@@ -21,7 +21,6 @@ import (
2121 "fmt"
2222 "log"
2323 "os"
24- "reflect"
2524 "strings"
2625
2726 argoapp "github.com/argoproj-labs/argocd-operator/api/v1beta1"
@@ -39,6 +38,7 @@ import (
3938 appsv1 "k8s.io/api/apps/v1"
4039 corev1 "k8s.io/api/core/v1"
4140 rbacv1 "k8s.io/api/rbac/v1"
41+ "k8s.io/apimachinery/pkg/api/equality"
4242 "k8s.io/apimachinery/pkg/api/errors"
4343 resourcev1 "k8s.io/apimachinery/pkg/api/resource"
4444 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -103,7 +103,8 @@ func (r *ReconcileGitopsService) SetupWithManager(mgr ctrl.Manager) error {
103103 Owns (& rbacv1.ClusterRole {}).
104104 Owns (& corev1.ServiceAccount {}).
105105 Owns (& corev1.ConfigMap {}).
106- Owns (& appsv1.Deployment {}, builder .WithPredicates (pred )).
106+ // Removed Owns(&appsv1.Deployment{}) watch to prevent hot loop from deployment updates
107+ // Deployments are still reconciled when GitopsService or ArgoCD changes
107108 Owns (& corev1.Service {}, builder .WithPredicates (pred )).
108109 Owns (& routev1.Route {}, builder .WithPredicates (pred )).
109110 Watches (
@@ -517,7 +518,7 @@ func (r *ReconcileGitopsService) reconcileDefaultArgoCDInstance(instance *pipeli
517518
518519 // if user is patching nodePlacement through GitopsService CR, then existingArgoCD NodePlacement is updated.
519520 if defaultArgoCDInstance .Spec .NodePlacement != nil {
520- if ! reflect .DeepEqual (existingArgoCD .Spec .NodePlacement , defaultArgoCDInstance .Spec .NodePlacement ) {
521+ if ! equality . Semantic .DeepEqual (existingArgoCD .Spec .NodePlacement , defaultArgoCDInstance .Spec .NodePlacement ) {
521522 existingArgoCD .Spec .NodePlacement = defaultArgoCDInstance .Spec .NodePlacement
522523 changed = true
523524 }
@@ -587,7 +588,7 @@ func (r *ReconcileGitopsService) reconcileBackend(gitopsserviceNamespacedName ty
587588 } else {
588589 return reconcile.Result {}, err
589590 }
590- } else if ! reflect .DeepEqual (existingClusterRole .Rules , clusterRoleObj .Rules ) {
591+ } else if ! equality . Semantic .DeepEqual (existingClusterRole .Rules , clusterRoleObj .Rules ) {
591592 reqLogger .Info ("Reconciling existing Cluster Role" , "Name" , clusterRoleObj .Name )
592593 existingClusterRole .Rules = clusterRoleObj .Rules
593594 err = r .Client .Update (context .TODO (), existingClusterRole )
@@ -666,39 +667,36 @@ func (r *ReconcileGitopsService) reconcileBackend(gitopsserviceNamespacedName ty
666667 found .Spec .Template .Spec .Containers [0 ].Image = desiredImage
667668 changed = true
668669 }
669- if ! reflect .DeepEqual (found .Spec .Template .Spec .Containers [0 ].Env , deploymentObj .Spec .Template .Spec .Containers [0 ].Env ) {
670+ if ! equality . Semantic .DeepEqual (found .Spec .Template .Spec .Containers [0 ].Env , deploymentObj .Spec .Template .Spec .Containers [0 ].Env ) {
670671 found .Spec .Template .Spec .Containers [0 ].Env = deploymentObj .Spec .Template .Spec .Containers [0 ].Env
671672 changed = true
672673 }
673- if ! reflect .DeepEqual (found .Spec .Template .Spec .Containers [0 ].ImagePullPolicy , deploymentObj .Spec .Template .Spec .Containers [0 ].ImagePullPolicy ) {
674+ if ! equality . Semantic .DeepEqual (found .Spec .Template .Spec .Containers [0 ].ImagePullPolicy , deploymentObj .Spec .Template .Spec .Containers [0 ].ImagePullPolicy ) {
674675 found .Spec .Template .Spec .Containers [0 ].ImagePullPolicy = deploymentObj .Spec .Template .Spec .Containers [0 ].ImagePullPolicy
675676 changed = true
676677 }
677- if ! reflect .DeepEqual (found .Spec .Template .Spec .Containers [0 ].Resources , deploymentObj .Spec .Template .Spec .Containers [0 ].Resources ) {
678- found .Spec .Template .Spec .Containers [0 ].Resources = deploymentObj .Spec .Template .Spec .Containers [0 ].Resources
679- changed = true
680- }
681- if ! reflect .DeepEqual (found .Spec .Template .Spec .Containers [0 ].Args , deploymentObj .Spec .Template .Spec .Containers [0 ].Args ) {
678+ if ! equality .Semantic .DeepEqual (found .Spec .Template .Spec .Containers [0 ].Args , deploymentObj .Spec .Template .Spec .Containers [0 ].Args ) {
682679 found .Spec .Template .Spec .Containers [0 ].Args = deploymentObj .Spec .Template .Spec .Containers [0 ].Args
683680 changed = true
684681 }
685- if ! reflect .DeepEqual (found .Spec .Template .Spec .Containers [0 ].Resources , deploymentObj .Spec .Template .Spec .Containers [0 ].Resources ) {
682+ // Use semantic equality to handle Kubernetes defaults properly
683+ if ! equality .Semantic .DeepEqual (found .Spec .Template .Spec .Containers [0 ].Resources , deploymentObj .Spec .Template .Spec .Containers [0 ].Resources ) {
686684 found .Spec .Template .Spec .Containers [0 ].Resources = deploymentObj .Spec .Template .Spec .Containers [0 ].Resources
687685 changed = true
688686 }
689- if ! reflect .DeepEqual (found .Spec .Template .Spec .Containers [0 ].SecurityContext , deploymentObj .Spec .Template .Spec .Containers [0 ].SecurityContext ) {
687+ if ! equality . Semantic .DeepEqual (found .Spec .Template .Spec .Containers [0 ].SecurityContext , deploymentObj .Spec .Template .Spec .Containers [0 ].SecurityContext ) {
690688 found .Spec .Template .Spec .Containers [0 ].SecurityContext = deploymentObj .Spec .Template .Spec .Containers [0 ].SecurityContext
691689 changed = true
692690 }
693- if ! reflect .DeepEqual (found .Spec .Template .Spec .NodeSelector , deploymentObj .Spec .Template .Spec .NodeSelector ) {
691+ if ! equality . Semantic .DeepEqual (found .Spec .Template .Spec .NodeSelector , deploymentObj .Spec .Template .Spec .NodeSelector ) {
694692 found .Spec .Template .Spec .NodeSelector = deploymentObj .Spec .Template .Spec .NodeSelector
695693 changed = true
696694 }
697- if ! reflect .DeepEqual (found .Spec .Template .Spec .Tolerations , deploymentObj .Spec .Template .Spec .Tolerations ) {
695+ if ! equality . Semantic .DeepEqual (found .Spec .Template .Spec .Tolerations , deploymentObj .Spec .Template .Spec .Tolerations ) {
698696 found .Spec .Template .Spec .Tolerations = deploymentObj .Spec .Template .Spec .Tolerations
699697 changed = true
700698 }
701- if ! reflect .DeepEqual (found .Spec .Template .Spec .SecurityContext , deploymentObj .Spec .Template .Spec .SecurityContext ) {
699+ if ! equality . Semantic .DeepEqual (found .Spec .Template .Spec .SecurityContext , deploymentObj .Spec .Template .Spec .SecurityContext ) {
702700 found .Spec .Template .Spec .SecurityContext = deploymentObj .Spec .Template .Spec .SecurityContext
703701 changed = true
704702 }
0 commit comments