Cobra and Persistentflags gotchas

If you are using cobra cmd line library for golang applications and it鈥檚 PersistentFlags and if you have a use case where you are adding same kind of flag in multiple places. You might burn your fingers in that case, if you keep adding it in multiple sub-commands without giving it a second thought. To understand what is really happening and why it is happening follow along. All the code referenced here can be found here https://github.com/surajssd/cobrademo. ...

January 4, 2019 路 3 min 路 Suraj Deshmukh

Adding new worker to existing Kubernetes cluster

To setup a multi-node Kubernetes cluster just run this script and you will have a cluster with 3 masters and 3 workers. $ kubectl get nodes -o wide NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME worker-0 Ready <none> 1h v1.11.2 192.168.199.20 <none> Ubuntu 18.04.1 LTS 4.15.0-33-generic cri-o://1.11.2 worker-1 Ready <none> 1h v1.11.2 192.168.199.21 <none> Ubuntu 18.04.1 LTS 4.15.0-33-generic cri-o://1.11.2 worker-2 Ready <none> 1h v1.11.2 192.168.199.22 <none> Ubuntu 18.04.1 LTS 4.15.0-33-generic cri-o://1.11.2 Now to add a new node to this cluster you will need to bring up a VM, for this just use following Vagrantfile. ...

September 23, 2018 路 5 min 路 Suraj Deshmukh

Golang struct tags gotchas

In golang while using struct tag, the spaces make a lot of difference. For example look at the following code. type PodStatus struct { Status string `json: ",status"` } If you run go vet on this piece of code you will get following error: $ go vet types.go # command-line-arguments ./types.go:28: struct field tag `json: ",status"` not compatible with reflect.StructTag.Get: bad syntax for struct tag value Now this does not tell us what is wrong with the struct tag, json: ",status". The problem with this struct tag is that the extra space can be interpreted as delimiter so provide key-value pair without space. ...

August 12, 2018 路 1 min 路 Suraj Deshmukh

Access etcd in OpenShift origin

How do you access the etcd that is being used by the OpenShift started by oc cluster up or using minishift. If you are using minishift then get docker environment access of the minishift VM by running following commands. eval $(minishift docker-env) && eval $(minishift oc-env) Exec into the container named origin that runs OpenShift and all the needed services. $ docker exec -it origin bash First install the etcdctl needed to talk to etcd. [root@surajd origin]$ yum -y install etcd Get into the directory where all the certs and keys are available. ...

July 11, 2018 路 1 min 路 Suraj Deshmukh

Change namespaces in Kubernetes

There is no easy way to change namespace in Kubernetes using kubectl command line utility. But here are some commands that you can alias in your bashrc file so that it鈥檚 just a single command that you can use to change the namespace in the Kubernetes cluster. Change namespace Let鈥檚 see step by step what goes in to change the namespace. So the first step is to find the context. A context element in a kubeconfig file is used to group access parameters under a convenient name. Each context has three parameters: cluster, namespace, and user. By default, the kubectl command-line tool uses parameters from the current context to communicate with the cluster. Read more. ...

July 2, 2018 路 3 min 路 Suraj Deshmukh

Prometheus with existing application on OpenShift

This post is very specific to OpenShift and how you can have an application exposing prometheus metrics to be scraped by a prometheus running in the same cluster. Requirements Setting up cluster I have done it using the oc cluster up, read about how to do this here. You could also setup a local OpenShift cluster by running minishift, read about setting up minishift here. Downloading Kedge The configurations defined for setting up this cluster is written in a format that is understood by a tool called Kedge. This makes configuration easier to understand and edit. So for using this setup download Kedge and put it in your path as explained here. ...

April 4, 2018 路 2 min 路 Suraj Deshmukh

vscode Shortcuts

This post has shortcuts that are generic and golang specific as well. This post will edited from time to time. Shortcuts Toggle side bar Ctrl + B Project explorer in side bar Ctrl + Shift + E Project wide search in side bar Ctrl + Shift + F Source control in side bar Ctrl + Shift + G Copy entire line Ctrl + C (without any selection) Delete entire line Ctrl + Shift + K ...

February 22, 2018 路 3 min 路 Suraj Deshmukh