Metacontroller: how to stop calls to sync hooks and resource generation

6/3/2019

I'm using Metacontroller to implement a Kubernetes operator.

My problem is the following:

  1. Metacontroller never stops calling my sync hook for my controller ( composite controllers in that case), and
  2. the parent resources status.observedGeneration field is getting updated continuously (from what I understand that means the resource was recreated).

The composite controller documentation (specifically the response documentation) suggests that if there are no changes in the returned parent status or in the children collection, Metacontroller should stop calling the sync hook.

I additionally removed spec.resyncPeriodSeconds and spec.parentResource.revisionHistory from the composite controller manifest (to not trigger any calls to the sync hook due to timer events or changes to the parent's status field) .

Sadly, none of this worked. How can I tell Metacontroller to stop calling the sync hook and stop to create the resource?

-- FK82
kubernetes
kubernetes-operator

1 Answer

7/3/2019

You probably need to enable the "status" subresource for your CRD: https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions/#status-subresource

apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
  name: myresource
spec:
...
  subresources:
    status: {}

Without that, Metacontroller will treat status updates as normal resource updates which in turn creates a new .metadata.resourceVersion / .metadata.generation because Metacontroller always adds an updated .status.observedGeneration field.

See here: https://github.com/GoogleCloudPlatform/metacontroller/blob/985572b9052a306f7e4d4fb84f2ced6f74247dd5/dynamic/clientset/clientset.go#L200

I have created an issue for this: https://github.com/GoogleCloudPlatform/metacontroller/issues/176

Hopefully this will make this situation more obvious in the future.

-- Michael GrĂ¼ner
Source: StackOverflow