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?
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: