ericsysmin's DevOps Blog

Converting Python Google.Cloud Objects to JSON Parseable Dictionaries

Converting Python Google.Cloud Objects to JSON Parseable Dictionaries

Trying to write some python scripts to handle our infrastructure in GCP. I found that the Google Cloud Python SDK, does not easily convert into python using __dict__, and json.dumps() so I had to do some digging. It took a bit of time but found that we can use the Python proto library to handle conversion of the Google Cloud Objects to JSON. Here’s an example of listing GKE clusters.

As you can see using proto.Message.to_json(object) allowed me to provide json parseable data. Just figured someone else can use this and I wanted to keep a note of it as the solution wasn’t something easily able to be found. Someone also found it works for other GCP objects.

Other methods were also discussed here: https://github.com/googleapis/python-vision/issues/70

Continue reading...
Copying files from host to K8s pod via Ansible

Copying files from host to K8s pod via Ansible

There weren’t a lot of resources out there to share how to execute commands or copy files using Ansible and the kubectl  Connection plugin. To help, I decided to document how to use the plugin. At least an example.

Usage is fairly easy. Top copy a file from your Ansible machine to the K8s pod you’ll need to have your ~/.kube/config file setup. Follow kubectl instructions for that part (it can differ depending on your cloud).

In this example, I add the K8s pod to inventory, then copy a file to the K8s pod. I added a step that allows you to see what the file contains if you use -vvv in the Ansible command

There are additional parameters, which are listed here: https://docs.ansible.com/ansible/latest/plugins/connection/kubectl.html

Continue reading...