From a4c761515d9e856ac29f26129f99255a156bebe7 Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Wed, 22 Dec 2021 19:20:15 +1100 Subject: [PATCH] feat: add cluster to log meta --- api/v1alpha1/lagoonmessaging_types.go | 1 + controllers/lagoonbuild_controller.go | 1 + controllers/lagoonbuild_deletionhandlers.go | 3 +++ controllers/lagoonmonitor_buildhandlers.go | 3 +++ controllers/lagoonmonitor_controller.go | 1 + controllers/lagoonmonitor_taskhandlers.go | 3 +++ controllers/lagoontask_controller.go | 1 + main.go | 5 ++++- 8 files changed, 17 insertions(+), 1 deletion(-) diff --git a/api/v1alpha1/lagoonmessaging_types.go b/api/v1alpha1/lagoonmessaging_types.go index 2bec26ed..ae8e1aed 100644 --- a/api/v1alpha1/lagoonmessaging_types.go +++ b/api/v1alpha1/lagoonmessaging_types.go @@ -36,6 +36,7 @@ type LagoonLogMeta struct { Task *LagoonTaskInfo `json:"task,omitempty"` Key string `json:"key,omitempty"` AdvancedData string `json:"advancedData,omitempty"` + Cluster string `json:"clusterName,omitempty"` } // LagoonMessage is used for sending build info back to Lagoon diff --git a/controllers/lagoonbuild_controller.go b/controllers/lagoonbuild_controller.go index 6918ae1c..a8e0432f 100644 --- a/controllers/lagoonbuild_controller.go +++ b/controllers/lagoonbuild_controller.go @@ -71,6 +71,7 @@ type LagoonBuildReconciler struct { LFFQoSEnabled bool BuildQoS BuildQoS NativeCronPodMinFrequency int + LagoonTargetName string } // +kubebuilder:rbac:groups=lagoon.amazee.io,resources=lagoonbuilds,verbs=get;list;watch;create;update;patch;delete diff --git a/controllers/lagoonbuild_deletionhandlers.go b/controllers/lagoonbuild_deletionhandlers.go index 99b63024..f372bef0 100644 --- a/controllers/lagoonbuild_deletionhandlers.go +++ b/controllers/lagoonbuild_deletionhandlers.go @@ -239,6 +239,7 @@ func (r *LagoonBuildReconciler) cancelledBuildLogsToLagoonLogs(ctx context.Conte BuildPhase: condition, RemoteID: string(lagoonBuild.ObjectMeta.UID), LogLink: lagoonBuild.Spec.Project.UILink, + Cluster: r.LagoonTargetName, }, } // add the actual build log message @@ -285,6 +286,7 @@ func (r *LagoonBuildReconciler) updateCancelledDeploymentAndEnvironmentTask(ctx BuildName: lagoonBuild.ObjectMeta.Name, LogLink: lagoonBuild.Spec.Project.UILink, RemoteID: string(lagoonBuild.ObjectMeta.UID), + Cluster: r.LagoonTargetName, }, } labelRequirements1, _ := labels.NewRequirement("lagoon.sh/service", selection.NotIn, []string{"faketest"}) @@ -366,6 +368,7 @@ func (r *LagoonBuildReconciler) cancelledBuildStatusLogsToLagoonLogs(ctx context BuildPhase: condition, BuildName: lagoonBuild.ObjectMeta.Name, LogLink: lagoonBuild.Spec.Project.UILink, + Cluster: r.LagoonTargetName, }, Message: fmt.Sprintf("*[%s]* %s Build `%s` %s", lagoonBuild.Spec.Project.Name, diff --git a/controllers/lagoonmonitor_buildhandlers.go b/controllers/lagoonmonitor_buildhandlers.go index 52856418..2dc0349f 100644 --- a/controllers/lagoonmonitor_buildhandlers.go +++ b/controllers/lagoonmonitor_buildhandlers.go @@ -174,6 +174,7 @@ func (r *LagoonMonitorReconciler) buildLogsToLagoonLogs(ctx context.Context, BuildPhase: condition, RemoteID: string(jobPod.ObjectMeta.UID), LogLink: lagoonBuild.Spec.Project.UILink, + Cluster: r.LagoonTargetName, }, } // add the actual build log message @@ -233,6 +234,7 @@ func (r *LagoonMonitorReconciler) updateDeploymentAndEnvironmentTask(ctx context BuildName: lagoonBuild.ObjectMeta.Name, LogLink: lagoonBuild.Spec.Project.UILink, RemoteID: string(jobPod.ObjectMeta.UID), + Cluster: r.LagoonTargetName, }, } labelRequirements1, _ := labels.NewRequirement("lagoon.sh/service", selection.NotIn, []string{"faketest"}) @@ -340,6 +342,7 @@ func (r *LagoonMonitorReconciler) buildStatusLogsToLagoonLogs(ctx context.Contex BuildPhase: condition, BuildName: lagoonBuild.ObjectMeta.Name, LogLink: lagoonBuild.Spec.Project.UILink, + Cluster: r.LagoonTargetName, }, } // if we aren't being provided the lagoon config, we can skip adding the routes etc diff --git a/controllers/lagoonmonitor_controller.go b/controllers/lagoonmonitor_controller.go index 9f24f88d..3872fd30 100644 --- a/controllers/lagoonmonitor_controller.go +++ b/controllers/lagoonmonitor_controller.go @@ -42,6 +42,7 @@ type LagoonMonitorReconciler struct { Messaging *handlers.Messaging ControllerNamespace string EnableDebug bool + LagoonTargetName string } // slice of the different failure states of pods that we care about diff --git a/controllers/lagoonmonitor_taskhandlers.go b/controllers/lagoonmonitor_taskhandlers.go index 953b8859..1002142e 100644 --- a/controllers/lagoonmonitor_taskhandlers.go +++ b/controllers/lagoonmonitor_taskhandlers.go @@ -156,6 +156,7 @@ func (r *LagoonMonitorReconciler) taskLogsToLagoonLogs(opLog logr.Logger, JobStatus: condition, RemoteID: string(jobPod.ObjectMeta.UID), Key: lagoonTask.Spec.Key, + Cluster: r.LagoonTargetName, }, Message: fmt.Sprintf(`======================================== Logs on pod %s @@ -208,6 +209,7 @@ func (r *LagoonMonitorReconciler) updateLagoonTask(opLog logr.Logger, JobStatus: condition, RemoteID: string(jobPod.ObjectMeta.UID), Key: lagoonTask.Spec.Key, + Cluster: r.LagoonTargetName, }, } if _, ok := jobPod.ObjectMeta.Annotations["lagoon.sh/taskData"]; ok { @@ -272,6 +274,7 @@ func (r *LagoonMonitorReconciler) taskStatusLogsToLagoonLogs(opLog logr.Logger, JobStatus: condition, RemoteID: string(jobPod.ObjectMeta.UID), Key: lagoonTask.Spec.Key, + Cluster: r.LagoonTargetName, }, Message: fmt.Sprintf("*[%s]* Task `%s` *%s* %s", lagoonTask.Spec.Project.Name, diff --git a/controllers/lagoontask_controller.go b/controllers/lagoontask_controller.go index 2144b917..05433d67 100644 --- a/controllers/lagoontask_controller.go +++ b/controllers/lagoontask_controller.go @@ -45,6 +45,7 @@ type LagoonTaskReconciler struct { ControllerNamespace string TaskSettings LagoonTaskSettings EnableDebug bool + LagoonTargetName string } // LagoonTaskSettings is for the settings for task API/SSH host/ports diff --git a/main.go b/main.go index a67365dc..d3c7df38 100644 --- a/main.go +++ b/main.go @@ -621,6 +621,7 @@ func main() { LFFQoSEnabled: lffQoSEnabled, BuildQoS: buildQoSConfig, NativeCronPodMinFrequency: nativeCronPodMinFrequency, + LagoonTargetName: lagoonTargetName, }).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "LagoonBuild") os.Exit(1) @@ -633,6 +634,7 @@ func main() { Messaging: messaging, ControllerNamespace: controllerNamespace, EnableDebug: enableDebug, + LagoonTargetName: lagoonTargetName, }).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "LagoonMonitor") os.Exit(1) @@ -648,7 +650,8 @@ func main() { SSHHost: lagoonSSHHost, SSHPort: lagoonSSHPort, }, - EnableDebug: enableDebug, + EnableDebug: enableDebug, + LagoonTargetName: lagoonTargetName, }).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "LagoonTask") os.Exit(1)