Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions internal/controller/overcommit/overcommit_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
23 changes: 23 additions & 0 deletions internal/controller/overcommit/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down