Kubernetes controller update CR status field with values from pod output in GO

7/13/2020

Using the Operator-sdk I deploy a CR that has a Job with a pod. CR has a Status struct something like below

type CRStatus struct {
    TestStatus string `json:"testStatus"`
    TestCount int `json:"testCount"`
}

The Pod does some processing and prints output TestStatus and TestCount values. How can operator-sdk controller update CR's TestStatus and TestCount fields with values from Pod output of the job?

-- user2596613
kubernetes
operator-sdk

1 Answer

7/13/2020

You can start by creating a controller (you might have already):

operator-sdk add controller --api-version=example.com/v1alpha1 --kind=YourCRApp

Then in the implementation, you will want to make use of the Kubernetes Informers/SharedInformers by adding an AddEventHandler call to see if any value has changed on any Kubernetes resource. You can find a sample controller in Kubernetes source code. Also, there are many resources available online that can guide you on how to create the controller and make use of Informers, here are some examples:

-- Rico
Source: StackOverflow