<p>I am trying to implement my first Kubernetes operator. I want the operator controller to be able to compare the config in a running pod vs the expected config defined in a custom resource definition.</p>

<p>Eg: Custom Resource</p>

<pre><code>apiVersion: test.com/v1alpha1
kind: TEST
metadata::
  name: example-test
spec:
  replicas: 3
  version: 20:03
  config:
    valueA: true
    valueB: 123
</code></pre>

<p>The above custom resource is deployed and 3 pods are running. A change is made such that the config "valueA" is changed to false.</p>

<p>In the GO controller reconcile function I can get the TEST instance and see the "new" version of the config:</p>

<pre><code>instance := &amp;testv1alpha1.TEST{}
log.Info("New value : " + instance.Spec.Config.valueA)
</code></pre>

<p>I am wondering how I can access what the value of "valueA" is in my running pods so that I can compare and recreate the pods if it has changed?</p>

<p>Also a secondary question, do I need to loop through all running pods in the reconcile function to check each or can I do this as a single operation?</p>

Kerry Gunn
<p>What is this config exactly? If it's Pod's spec config, i would suggest to you to update not individual Pods, but spec in Deployment, it will restart it's pods automatically. If it's environment variables for apps in this pod, i would recommend to use <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/" rel="nofollow noreferrer">ConfigMap</a> 
 for storing them, and update it. Answering your second question, in both cases -- it will be a single operation.</p>

<p>To get Deployment, or ConfigMap you need to have it's name and namespace, usually, with custom resource, it should be derived from it's name. <a href="https://github.com/GrigoriyMikhalkin/config-monitor/blob/master/pkg/controller/upgrade/upgrade_controller.go#L97" rel="nofollow noreferrer">Here is example</a> how you can get deployment instance and update it.</p>
