From c5bb6a4be3ea1ebdcc93a88d1125b1a87542eeec Mon Sep 17 00:00:00 2001 From: "jesus m. rodriguez" Date: Sun, 26 Jul 2020 22:20:20 -0400 Subject: [PATCH 1/2] Format source code in go doc. --- handler/enqueue_annotation.go | 31 +++++++++++++------------- handler/instrumented_enqueue_object.go | 10 +++++---- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/handler/enqueue_annotation.go b/handler/enqueue_annotation.go index bd77321..9727642 100644 --- a/handler/enqueue_annotation.go +++ b/handler/enqueue_annotation.go @@ -47,33 +47,32 @@ const ( // of the parent resource which is identified by annotations. `NamespacedNameAnnotation` and // `TypeAnnotation` together uniquely identify an owner resource to reconcile. // -// handler.EnqueueRequestForAnnotation can be used to trigger reconciliation of resources which are -// cross-referenced. This allows a namespace-scoped dependent to trigger reconciliation of an owner which -// is in a different namespace, and a cluster-scoped dependent can trigger the reconciliation of a -// namespace(scoped)-owner. +// handler.EnqueueRequestForAnnotation +// +// can be used to trigger reconciliation of resources which are cross-referenced. This allows a +// namespace-scoped dependent to trigger reconciliation of an owner which is in a different namespace, +// and a cluster-scoped dependent can trigger the reconciliation of a namespace(scoped)-owner. // // As an example, consider the case where we would like to watch clusterroles based on which we reconcile // namespace-scoped replicasets. With native owner references, this would not be possible since the // cluster-scoped dependent (clusterroles) is trying to specify a namespace-scoped owner (replicasets). // Whereas in case of annotations-based handlers, we could implement the following: // -// ... -// if err := c.Watch(&source.Kind{ -// // Watch clusterroles -// Type: &rbacv1.ClusterRole{}}, +// if err := c.Watch(&source.Kind{ +// // Watch clusterroles +// Type: &rbacv1.ClusterRole{}}, // -// // Enqueue ReplicaSet reconcile requests using the namespacedName annotation value in the request. -// &handler.EnqueueRequestForAnnotation{schema.GroupKind{Group:"apps", Kind:"ReplicaSet"}}); err != nil { -// entryLog.Error(err, "unable to watch ClusterRole") -// os.Exit(1) -// } -// } -// ... +// // Enqueue ReplicaSet reconcile requests using the namespacedName annotation value in the request. +// &handler.EnqueueRequestForAnnotation{schema.GroupKind{Group:"apps", Kind:"ReplicaSet"}}); err != nil { +// entryLog.Error(err, "unable to watch ClusterRole") +// os.Exit(1) +// } +// } // // With this watch, the ReplicaSet reconciler would receive a request to reconcile // "my-namespace/my-replicaset" based on a change to a ClusterRole that has the following annotations: // -// annotations: +// annotations: // operator-sdk/primary-resource:"my-namespace/my-replicaset" // operator-sdk/primary-resource-type:"ReplicaSet.apps" // diff --git a/handler/instrumented_enqueue_object.go b/handler/instrumented_enqueue_object.go index 9305a01..7bdd393 100644 --- a/handler/instrumented_enqueue_object.go +++ b/handler/instrumented_enqueue_object.go @@ -26,13 +26,15 @@ import ( // InstrumentedEnqueueRequestForObject wraps controller-runtime handler for // "EnqueueRequestForObject", and sets up primary resource metrics on event -// handlers. The main objective of this handler is to set prometheues metrics -// when create/update/delete events occur. These metrics contain below +// handlers. The main objective of this handler is to set prometheus metrics +// when create/update/delete events occur. These metrics contain the following // information on resource. // -// resource_created_at_seconds{"name", "namespace", "group", "version", "kind"} +// resource_created_at_seconds{"name", "namespace", "group", "version", "kind"} // -// '&handler.InstrumentedEnqueueRequestForObject{}' is used to call the handler. +// To call the handler use: +// +// &handler.InstrumentedEnqueueRequestForObject{} type InstrumentedEnqueueRequestForObject struct { handler.EnqueueRequestForObject } From 7fa990f7d32836b6b7e59781f6a09320797b9071 Mon Sep 17 00:00:00 2001 From: "jesus m. rodriguez" Date: Mon, 27 Jul 2020 11:01:57 -0400 Subject: [PATCH 2/2] handler.EnqueueRequestForAnnotation is a noun, do not indent --- handler/enqueue_annotation.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/handler/enqueue_annotation.go b/handler/enqueue_annotation.go index 9727642..d6b1fa4 100644 --- a/handler/enqueue_annotation.go +++ b/handler/enqueue_annotation.go @@ -47,11 +47,10 @@ const ( // of the parent resource which is identified by annotations. `NamespacedNameAnnotation` and // `TypeAnnotation` together uniquely identify an owner resource to reconcile. // -// handler.EnqueueRequestForAnnotation -// -// can be used to trigger reconciliation of resources which are cross-referenced. This allows a -// namespace-scoped dependent to trigger reconciliation of an owner which is in a different namespace, -// and a cluster-scoped dependent can trigger the reconciliation of a namespace(scoped)-owner. +// handler.EnqueueRequestForAnnotation can be used to trigger reconciliation of resources which are +// cross-referenced. This allows a namespace-scoped dependent to trigger reconciliation of an owner +// which is in a different namespace, and a cluster-scoped dependent can trigger the reconciliation +// of a namespace(scoped)-owner. // // As an example, consider the case where we would like to watch clusterroles based on which we reconcile // namespace-scoped replicasets. With native owner references, this would not be possible since the