From efdc206773d931d8ef4188b63edeae6a1644a8df Mon Sep 17 00:00:00 2001 From: Blaize Kaye Date: Wed, 2 Mar 2022 08:19:15 +1300 Subject: [PATCH] Adds build information to logs --- controllers/configmap_controller.go | 11 +++++------ main.go | 7 ++++++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/controllers/configmap_controller.go b/controllers/configmap_controller.go index 1195d5c..8f765c7 100644 --- a/controllers/configmap_controller.go +++ b/controllers/configmap_controller.go @@ -20,16 +20,15 @@ import ( "context" "fmt" "github.com/cheshir/go-mq" - "k8s.io/apimachinery/pkg/util/json" - "sigs.k8s.io/controller-runtime/pkg/event" - "sigs.k8s.io/controller-runtime/pkg/predicate" - "time" - corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/util/json" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/log" + "sigs.k8s.io/controller-runtime/pkg/predicate" + "time" ) const InsightsLabel = "lagoon.sh/insightsType" @@ -150,7 +149,7 @@ func insightsProcessedAnnotationExists(eventObject client.Object) bool { annotations := eventObject.GetAnnotations() annotationExists := false if _, ok := annotations[InsightsUpdatedAnnotationLabel]; ok { - fmt.Println("Insights update annotation exists for " + eventObject.GetName()) + log.Log.Info(fmt.Sprintf("Insights update annotation exists for '%v' in ns '%v'", eventObject.GetName(), eventObject.GetNamespace())) annotationExists = true } return annotationExists diff --git a/main.go b/main.go index a4fd208..6515400 100644 --- a/main.go +++ b/main.go @@ -209,10 +209,15 @@ func main() { for _, x := range configMapList.Items { //check the annotations if _, okay := x.Annotations[controllers.InsightsUpdatedAnnotationLabel]; okay { + //grab the build this is linked to + buildName := "" + if val, ok := x.Labels["lagoon.sh/buildName"]; ok { + buildName = fmt.Sprintf(" (build: '%v')", val) + } if err := client.Delete(context.Background(), &x); err != nil { log.Printf("Unable to delete configMap '%v' in ns '%v': %v\n\n", x.Name, x.Namespace, err) } else { - log.Printf("Deleted Insights configMap '%v' in ns '%v'", x.Name, x.Namespace) + log.Printf("Deleted Insights configMap '%v' in ns '%v' %v", x.Name, x.Namespace, buildName) } } }