@@ -32,9 +32,9 @@ import (
32
32
var log = logf .Log .WithName ("event_handler" )
33
33
34
34
const (
35
- // NamespacedNameAnnotation is an annotation whose value encodes the name and namespace of a resource to reconcile
36
- // when a resource containing this annotation changes. Valid values are of the form `<namespace>/<name>` for
37
- // namespace-scoped owners and `<name>` for cluster-scoped owners.
35
+ // NamespacedNameAnnotation is an annotation whose value encodes the name and namespace of a resource to
36
+ // reconcile when a resource containing this annotation changes. Valid values are of the form
37
+ // `<namespace>/<name>` for namespace-scoped owners and `<name>` for cluster-scoped owners.
38
38
NamespacedNameAnnotation = "operator-sdk/primary-resource"
39
39
// TypeAnnotation is an annotation whose value encodes the group and kind of a resource to reconcil when a
40
40
// resource containing this annotation changes. Valid values are of the form `<Kind>` for resource in the
@@ -44,16 +44,19 @@ const (
44
44
45
45
// EnqueueRequestForAnnotation enqueues Request containing the Name and Namespace specified in the
46
46
// annotations of the object that is the source of the Event. The source of the event triggers reconciliation
47
- // of the parent resource which is identified by annotations. `NamespacedNameAnnotation` and `TypeAnnotation` together uniquely
48
- // identify an owner resource to reconcile.
49
- // handler.EnqueueRequestForAnnotation can be used to trigger reconciliation of resources which are cross-referenced.
50
- // This allows a namespace-scoped dependent to trigger reconciliation of an owner which is in a different namespace, and
51
- // a cluster-scoped dependent can trigger the reconciliation of a namespace(scoped)-owner.
52
-
53
- // As an example, consider the case where we would like to watch clusterroles based on which we reconcile namespace-scoped replicasets.
54
- // With native owner references, this would not be possible since the cluster-scoped dependent (clusterroles) is trying to
55
- // specify a namespace-scoped owner (replicasets). Whereas in case of annotations-based handlers, we could implement the following:
56
-
47
+ // of the parent resource which is identified by annotations. `NamespacedNameAnnotation` and
48
+ // `TypeAnnotation` together uniquely identify an owner resource to reconcile.
49
+ //
50
+ // handler.EnqueueRequestForAnnotation can be used to trigger reconciliation of resources which are
51
+ // cross-referenced. This allows a namespace-scoped dependent to trigger reconciliation of an owner which
52
+ // is in a different namespace, and a cluster-scoped dependent can trigger the reconciliation of a
53
+ // namespace(scoped)-owner.
54
+ //
55
+ // As an example, consider the case where we would like to watch clusterroles based on which we reconcile
56
+ // namespace-scoped replicasets. With native owner references, this would not be possible since the
57
+ // cluster-scoped dependent (clusterroles) is trying to specify a namespace-scoped owner (replicasets).
58
+ // Whereas in case of annotations-based handlers, we could implement the following:
59
+ //
57
60
// ...
58
61
// if err := c.Watch(&source.Kind{
59
62
// // Watch clusterroles
@@ -66,13 +69,13 @@ const (
66
69
// }
67
70
// }
68
71
// ...
69
-
70
- // With this watch, the ReplicaSet reconciler would receive a request to reconcile "my-namespace/my-replicaset" based
71
- // on a change to a ClusterRole that has the following annotations:
72
+ //
73
+ // With this watch, the ReplicaSet reconciler would receive a request to reconcile
74
+ // "my-namespace/my-replicaset" based on a change to a ClusterRole that has the following annotations:
72
75
//
73
76
// annotations:
74
- // operator-sdk/primary-resource:"my-namespace/my-replicaset"
75
- // operator-sdk/primary-resource-type:"ReplicaSet.apps"
77
+ // operator-sdk/primary-resource:"my-namespace/my-replicaset"
78
+ // operator-sdk/primary-resource-type:"ReplicaSet.apps"
76
79
//
77
80
// Though an annotation-based watch handler removes the boundaries set by native owner reference implementation,
78
81
// the garbage collector still respects the scope restrictions. For example,
@@ -149,10 +152,10 @@ func parseNamespacedName(namespacedNameString string) types.NamespacedName {
149
152
}
150
153
}
151
154
152
- // SetOwnerAnnotations helps in adding 'NamespacedNameAnnotation' and 'TypeAnnotation' to object based on the values
153
- // obtained from owner. The object gets the annotations from owner's namespace, name, group and kind. In other terms,
154
- // object can be said to be the dependent having annotations from the owner. When a watch is set on the object, the
155
- // annotations help to identify the owner and trigger reconciliation.
155
+ // SetOwnerAnnotations helps in adding 'NamespacedNameAnnotation' and 'TypeAnnotation' to object based on
156
+ // the values obtained from owner. The object gets the annotations from owner's namespace, name, group
157
+ // and kind. In other terms, object can be said to be the dependent having annotations from the owner.
158
+ // When a watch is set on the object, the annotations help to identify the owner and trigger reconciliation.
156
159
// Annotations are ALWAYS overwritten.
157
160
func SetOwnerAnnotations (owner , object controllerutil.Object ) error {
158
161
if owner .GetName () == "" {
0 commit comments