IsController: true

if err := c.Watch(&source.Kind{Type: &clusterapiv1alpha1.Cluster{}}, &handler.EnqueueRequestForOwner{
	IsController: true,
	OwnerType:    &gcmv1alpha1.ManagedCluster{},
}); err != nil {
	return err
}

From above, you could see there is IsController: true set. The documentation says: IsController if set will only look at the first OwnerReference with Controller: true.

Now, Let's take a look at what we have under cluster object:

apiVersion: cluster.k8s.io/v1alpha1
kind: Cluster
metadata:
  creationTimestamp: "2019-09-16T23:53:20Z"
  finalizers:
  - foregroundDeletion
  - cluster.cluster.k8s.io
  generation: 2
  name: test-guest-cluster-2
  namespace: default
  ownerReferences:
  - apiVersion: gcm.vmware.com/v1alpha1
    blockOwnerDeletion: true
    controller: true
    kind: ManagedCluster
    name: test-guest-cluster-2
    uid: a143951c-2ebf-4846-b9d3-adb598da2995
  ...

If we have IsController: true set in our &handler.EnqueueRequestForOwner . That means we are going to enqueue the name and namespace of ManagedCluster test-guest-cluster-2 that is becuase it is the first ownerRefernce which has controller: true . [To be verified: If no ownerReferences have controller:true, or only the last one has it. What will happen ?]

Last updated