diff --git a/bundle/manifests/k8s-overcommit.clusterserviceversion.yaml b/bundle/manifests/k8s-overcommit.clusterserviceversion.yaml index eaf608c..10c1cb2 100644 --- a/bundle/manifests/k8s-overcommit.clusterserviceversion.yaml +++ b/bundle/manifests/k8s-overcommit.clusterserviceversion.yaml @@ -30,7 +30,7 @@ metadata: } ] capabilities: Basic Install - createdAt: "2025-07-03T11:39:06Z" + createdAt: "2025-07-03T14:50:58Z" operators.operatorframework.io/builder: operator-sdk-v1.40.0 operators.operatorframework.io/project_layout: go.kubebuilder.io/v4 name: k8s-overcommit.v1.0.2 diff --git a/deploy/olm/1.0.2/k8s-overcommit.clusterserviceversion.yaml b/deploy/olm/1.0.2/k8s-overcommit.clusterserviceversion.yaml index eaf608c..10c1cb2 100644 --- a/deploy/olm/1.0.2/k8s-overcommit.clusterserviceversion.yaml +++ b/deploy/olm/1.0.2/k8s-overcommit.clusterserviceversion.yaml @@ -30,7 +30,7 @@ metadata: } ] capabilities: Basic Install - createdAt: "2025-07-03T11:39:06Z" + createdAt: "2025-07-03T14:50:58Z" operators.operatorframework.io/builder: operator-sdk-v1.40.0 operators.operatorframework.io/project_layout: go.kubebuilder.io/v4 name: k8s-overcommit.v1.0.2 diff --git a/internal/controller/overcommit/overcommit_controller.go b/internal/controller/overcommit/overcommit_controller.go index 98feea4..a4115b7 100644 --- a/internal/controller/overcommit/overcommit_controller.go +++ b/internal/controller/overcommit/overcommit_controller.go @@ -164,6 +164,16 @@ func (r *OvercommitReconciler) Reconcile(ctx context.Context, req ctrl.Request) overcommitClassDeployment.Spec.Template.Spec.Containers[0].Env = updatedDeployment.Spec.Template.Spec.Containers[0].Env updated = true } + // Update template annotations if they changed + if !mapsEqual(updatedDeployment.Spec.Template.Annotations, overcommitClassDeployment.Spec.Template.Annotations) { + overcommitClassDeployment.Spec.Template.Annotations = updatedDeployment.Spec.Template.Annotations + updated = true + } + // Update template labels if they changed + if !mapsEqual(updatedDeployment.Spec.Template.Labels, overcommitClassDeployment.Spec.Template.Labels) { + overcommitClassDeployment.Spec.Template.Labels = updatedDeployment.Spec.Template.Labels + updated = true + } // Only set controller reference if we actually updated something if updated { return ctrl.SetControllerReference(overcommit, overcommitClassDeployment, r.Scheme) @@ -250,6 +260,16 @@ func (r *OvercommitReconciler) Reconcile(ctx context.Context, req ctrl.Request) validatingPodDeployment.Spec.Template.Spec.Containers[0].Env = updatedDeployment.Spec.Template.Spec.Containers[0].Env updated = true } + // Update template annotations if they changed + if !mapsEqual(updatedDeployment.Spec.Template.Annotations, validatingPodDeployment.Spec.Template.Annotations) { + validatingPodDeployment.Spec.Template.Annotations = updatedDeployment.Spec.Template.Annotations + updated = true + } + // Update template labels if they changed + if !mapsEqual(updatedDeployment.Spec.Template.Labels, validatingPodDeployment.Spec.Template.Labels) { + validatingPodDeployment.Spec.Template.Labels = updatedDeployment.Spec.Template.Labels + updated = true + } // Only set controller reference if we actually updated something if updated { return ctrl.SetControllerReference(overcommit, validatingPodDeployment, r.Scheme) @@ -309,6 +329,7 @@ func (r *OvercommitReconciler) Reconcile(ctx context.Context, req ctrl.Request) occontroller.Spec = updatedDeployment.Spec occontroller.ObjectMeta.Labels = updatedDeployment.ObjectMeta.Labels occontroller.ObjectMeta.Annotations = updatedDeployment.ObjectMeta.Annotations + logger.Info("Creating new OvercommitClass Controller deployment") return ctrl.SetControllerReference(overcommit, occontroller, r.Scheme) } else { // Existing deployment, only update specific fields if needed @@ -322,6 +343,16 @@ func (r *OvercommitReconciler) Reconcile(ctx context.Context, req ctrl.Request) occontroller.Spec.Template.Spec.Containers[0].Env = updatedDeployment.Spec.Template.Spec.Containers[0].Env updated = true } + // Update template annotations if they changed + if !mapsEqual(updatedDeployment.Spec.Template.Annotations, occontroller.Spec.Template.Annotations) { + occontroller.Spec.Template.Annotations = updatedDeployment.Spec.Template.Annotations + updated = true + } + // Update template labels if they changed + if !mapsEqual(updatedDeployment.Spec.Template.Labels, occontroller.Spec.Template.Labels) { + occontroller.Spec.Template.Labels = updatedDeployment.Spec.Template.Labels + updated = true + } // Only set controller reference if we actually updated something if updated { return ctrl.SetControllerReference(overcommit, occontroller, r.Scheme) diff --git a/internal/controller/overcommit/utils.go b/internal/controller/overcommit/utils.go index 8477ae2..16fd5e4 100644 --- a/internal/controller/overcommit/utils.go +++ b/internal/controller/overcommit/utils.go @@ -290,3 +290,26 @@ func envVarsEqual(a, b []corev1.EnvVar) bool { return true } + +// annotationsEqual compares two annotation maps to see if they're equal +func mapsEqual(a, b map[string]string) bool { + // Handle nil cases + if a == nil && b == nil { + return true + } + if a == nil || b == nil { + return false + } + + if len(a) != len(b) { + return false + } + + for key, valueA := range a { + if valueB, exists := b[key]; !exists || valueA != valueB { + return false + } + } + + return true +} diff --git a/internal/resources/generate_resources_overcommit_class_controller_controller.go b/internal/resources/generate_resources_overcommit_class_controller_controller.go index 8a8a674..8f80ca0 100644 --- a/internal/resources/generate_resources_overcommit_class_controller_controller.go +++ b/internal/resources/generate_resources_overcommit_class_controller_controller.go @@ -21,6 +21,13 @@ func GenerateOvercommitClassControllerDeployment(overcommitObject overcommit.Ove labels = make(map[string]string) } labels["app"] = "overcommit-controller" + + // Ensure annotations are properly handled + annotations := overcommitObject.Spec.Annotations + if annotations == nil { + annotations = make(map[string]string) + } + return &appsv1.Deployment{ ObjectMeta: metav1.ObjectMeta{ Name: "k8s-overcommit-overcommitclass-controller", @@ -36,7 +43,7 @@ func GenerateOvercommitClassControllerDeployment(overcommitObject overcommit.Ove Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: labels, - Annotations: overcommitObject.Annotations, + Annotations: annotations, }, Spec: corev1.PodSpec{ ServiceAccountName: os.Getenv("SERVICE_ACCOUNT_NAME"), diff --git a/internal/resources/generate_resources_validating_webhooks.go b/internal/resources/generate_resources_validating_webhooks.go index 9af06f8..c2739c9 100644 --- a/internal/resources/generate_resources_validating_webhooks.go +++ b/internal/resources/generate_resources_validating_webhooks.go @@ -66,7 +66,7 @@ func GeneratePodValidatingDeployment(overcommitObject overcommit.Overcommit) *ap Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: labels, - Annotations: overcommitObject.Annotations, + Annotations: overcommitObject.Spec.Annotations, }, Spec: corev1.PodSpec{ ServiceAccountName: os.Getenv("SERVICE_ACCOUNT_NAME"), @@ -241,7 +241,7 @@ func GenerateOvercommitClassValidatingDeployment(overcommitObject overcommit.Ove Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: labels, - Annotations: overcommitObject.Annotations, + Annotations: overcommitObject.Spec.Annotations, }, Spec: corev1.PodSpec{ ServiceAccountName: os.Getenv("SERVICE_ACCOUNT_NAME"),