<p>I've a custom operator that listens to changes in a CRD I've defined in a Kubernetes cluster.</p>
<p>Whenever something changed in the defined custom resource, the custom operator would reconcile and idempotently create a secret (that would be owned by the custom resource).</p>
<hr />
<p><strong>What I expect is for the operator to Reconcile only when something changed in the custom resource or in the secret owned by it</strong>.</p>
<p><strong>What I observe is that for some reason the <code>Reconcile</code> function triggers for every CR on the cluster in <em>strange intervals</em> without observable changes to related entities</strong>. I've tried focusing on a specific instance of the CR and follow the times in which <code>Reconcile</code> was called for it. The intervals of these calls are very strange. It seems that the calls are alternating between two series - one starts at 10 hours and diminishes seven minutes at a time. The other starts at 7 minutes and grows by 7 minutes a time.</p>
<p>To demonstrate, Reconcile <code>triggered</code> at these times (give or take a few seconds):</p>
<pre><code>00:00
09:53 (10 hours - 1*7 minute interval)
10:00 (0 hours  + 1*7 minute interval)
19:46 (10 hours - 2*7 minute interval)
20:00 (0 hours  + 2*7 minute interval)
29:39 (10 hours - 3*7 minute interval)
30:00 (0 hours  + 3*7 minute interval)
</code></pre>
<p>Whenever the diminishing intervals become less than 7 hours, it resets back to 10 hour intervals. The same with the growing series - as soon as the intervals are higher than 3 hours it resets back to 7 minutes.</p>
<hr />
<p><strong>My main question is how can I investigating why Reconcile is being triggered?</strong></p>
<p>I'm attaching here the manifests for the CRD, the operator and a sample manifest for a CR:</p>
<pre><code>apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  annotations:
    controller-gen.kubebuilder.io/version: v0.4.1
  creationTimestamp: &quot;2021-10-13T11:04:42Z&quot;
  generation: 1
  name: databaseservices.operators.talon.one
  resourceVersion: &quot;245688703&quot;
  uid: 477f8d3e-c19b-43d7-ab59-65198b3c0108
spec:
  conversion:
    strategy: None
  group: operators.talon.one
  names:
    kind: DatabaseService
    listKind: DatabaseServiceList
    plural: databaseservices
    singular: databaseservice
  scope: Namespaced
  versions:
  - name: v1alpha1
    schema:
      openAPIV3Schema:
        description: DatabaseService is the Schema for the databaseservices API
        properties:
          apiVersion:
            description: 'APIVersion defines the versioned schema of this representation
              of an object. Servers should convert recognized schemas to the latest
              internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
            type: string
          kind:
            description: 'Kind is a string value representing the REST resource this
              object represents. Servers may infer this from the endpoint the client
              submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
            type: string
          metadata:
            type: object
          spec:
            description: DatabaseServiceSpec defines the desired state of DatabaseService
            properties:
              cloud:
                type: string
              databaseName:
                description: Foo is an example field of DatabaseService. Edit databaseservice_types.go
                  to remove/update
                type: string
              serviceName:
                type: string
              servicePlan:
                type: string
            required:
            - cloud
            - databaseName
            - serviceName
            - servicePlan
            type: object
          status:
            description: DatabaseServiceStatus defines the observed state of DatabaseService
            type: object
        type: object
    served: true
    storage: true
    subresources:
      status: {}
status:
  acceptedNames:
    kind: DatabaseService
    listKind: DatabaseServiceList
    plural: databaseservices
    singular: databaseservice
  conditions:
  - lastTransitionTime: &quot;2021-10-13T11:04:42Z&quot;
    message: no conflicts found
    reason: NoConflicts
    status: &quot;True&quot;
    type: NamesAccepted
  - lastTransitionTime: &quot;2021-10-13T11:04:42Z&quot;
    message: the initial names have been accepted
    reason: InitialNamesAccepted
    status: &quot;True&quot;
    type: Established
  storedVersions:
  - v1alpha1


----

apiVersion: operators.talon.one/v1alpha1
kind: DatabaseService
metadata:
  creationTimestamp: &quot;2021-10-13T11:14:08Z&quot;
  generation: 1
  labels:
    app: talon
    company: amber
    repo: talon-service
  name: db-service-secret
  namespace: amber
  resourceVersion: &quot;245692590&quot;
  uid: cc369297-6825-4fbf-aa0b-58c24be427b0
spec:
  cloud: google-australia-southeast1
  databaseName: amber
  serviceName: pg-amber
  servicePlan: business-4

----

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: &quot;75&quot;
    secret.reloader.stakater.com/reload: db-credentials
    simpledeployer.talon.one/image: &lt;path_to_image&gt;/production:latest
  creationTimestamp: &quot;2020-06-22T09:20:06Z&quot;
  generation: 77
  labels:
    simpledeployer.talon.one/enabled: &quot;true&quot;
  name: db-operator
  namespace: db-operator
  resourceVersion: &quot;245688814&quot;
  uid: 900424cd-b469-11ea-b661-4201ac100014
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      name: db-operator
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        name: db-operator
    spec:
      containers:
      - command:
        - app/db-operator
        env:
        - name: POD_NAME
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: metadata.name
        - name: OPERATOR_NAME
          value: db-operator
        - name: AIVEN_PASSWORD
          valueFrom:
            secretKeyRef:
              key: password
              name: db-credentials
        - name: AIVEN_PROJECT
          valueFrom:
            secretKeyRef:
              key: projectname
              name: db-credentials
        - name: AIVEN_USERNAME
          valueFrom:
            secretKeyRef:
              key: username
              name: db-credentials
        - name: SENTRY_URL
          valueFrom:
            secretKeyRef:
              key: sentry_url
              name: db-credentials
        - name: ROTATION_INTERVAL
          value: monthly
        image: &lt;path_to_image&gt;/production@sha256:&lt;some_sha&gt;
        imagePullPolicy: Always
        name: db-operator
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      serviceAccount: db-operator
      serviceAccountName: db-operator
      terminationGracePeriodSeconds: 30
status:
  availableReplicas: 1
  conditions:
  - lastTransitionTime: &quot;2020-06-22T09:20:06Z&quot;
    lastUpdateTime: &quot;2021-09-07T11:56:07Z&quot;
    message: ReplicaSet &quot;db-operator-cb6556b76&quot; has successfully progressed.
    reason: NewReplicaSetAvailable
    status: &quot;True&quot;
    type: Progressing
  - lastTransitionTime: &quot;2021-09-12T03:56:19Z&quot;
    lastUpdateTime: &quot;2021-09-12T03:56:19Z&quot;
    message: Deployment has minimum availability.
    reason: MinimumReplicasAvailable
    status: &quot;True&quot;
    type: Available
  observedGeneration: 77
  readyReplicas: 1
  replicas: 1
  updatedReplicas: 1
</code></pre>
<hr />
<p>Note:</p>
<ul>
<li>When Reconcile finishes, I return:</li>
</ul>
<pre><code>return ctrl.Result{Requeue: false, RequeueAfter: 0}
</code></pre>
<p>So that shouldn't be the reason for the repeated triggers.</p>
<ul>
<li>I will add that I have recently updated the Kubernetes cluster version to v1.20.8-gke.2101.</li>
</ul>

Alechko
<p>This would require more info on how your controller is set up. For example what is the sync period you have set. This could be due to default sync period set which reconciles all the objects at given interval of time.</p>
<blockquote>
<p>SyncPeriod determines the minimum frequency at which watched resources are
reconciled. A lower period will correct entropy more quickly, but reduce
responsiveness to change if there are many watched resources. Change this
value only if you know what you are doing. Defaults to 10 hours if unset.
there will a 10 percent jitter between the SyncPeriod of all controllers
so that all controllers will not send list requests simultaneously.</p>
</blockquote>
<p>For more information check this: <a href="https://github.com/kubernetes-sigs/controller-runtime/blob/v0.11.2/pkg/manager/manager.go#L134" rel="nofollow noreferrer">https://github.com/kubernetes-sigs/controller-runtime/blob/v0.11.2/pkg/manager/manager.go#L134</a></p>
