@@ -45,6 +45,7 @@ import (
4545 "k8s.io/apimachinery/pkg/runtime"
4646 "k8s.io/apimachinery/pkg/types"
4747 "k8s.io/apimachinery/pkg/util/intstr"
48+ "k8s.io/client-go/util/retry"
4849 ctrl "sigs.k8s.io/controller-runtime"
4950 "sigs.k8s.io/controller-runtime/pkg/builder"
5051 "sigs.k8s.io/controller-runtime/pkg/client"
@@ -483,10 +484,10 @@ func (r *ReconcileGitopsService) reconcileDefaultArgoCDInstance(instance *pipeli
483484 if existingArgoCD .Spec .SSO .Dex != nil {
484485 if existingArgoCD .Spec .SSO .Dex .Resources == nil {
485486 existingArgoCD .Spec .SSO .Dex .Resources = defaultArgoCDInstance .Spec .SSO .Dex .Resources
487+ changed = true
486488 }
487489 }
488490 }
489- changed = true
490491 }
491492
492493 //lint:ignore SA1019 known to be deprecated
@@ -530,7 +531,67 @@ func (r *ReconcileGitopsService) reconcileDefaultArgoCDInstance(instance *pipeli
530531
531532 if changed {
532533 reqLogger .Info ("Reconciling ArgoCD" , "Namespace" , existingArgoCD .Namespace , "Name" , existingArgoCD .Name )
533- err = r .Client .Update (context .TODO (), existingArgoCD )
534+ err = retry .RetryOnConflict (retry .DefaultRetry , func () error {
535+ if err := r .Client .Get (context .TODO (), types.NamespacedName {Name : existingArgoCD .Name , Namespace : existingArgoCD .Namespace }, existingArgoCD ); err != nil {
536+ return err
537+ }
538+ changed := false
539+ if existingArgoCD .Spec .ApplicationSet != nil {
540+ if existingArgoCD .Spec .ApplicationSet .Resources == nil {
541+ existingArgoCD .Spec .ApplicationSet .Resources = defaultArgoCDInstance .Spec .ApplicationSet .Resources
542+ changed = true
543+ }
544+ }
545+ if existingArgoCD .Spec .Controller .Resources == nil {
546+ existingArgoCD .Spec .Controller .Resources = defaultArgoCDInstance .Spec .Controller .Resources
547+ changed = true
548+ }
549+ if argocdcontroller .UseDex (existingArgoCD ) {
550+ if existingArgoCD .Spec .SSO != nil && existingArgoCD .Spec .SSO .Provider == argoapp .SSOProviderTypeDex {
551+ if existingArgoCD .Spec .SSO .Dex != nil {
552+ if existingArgoCD .Spec .SSO .Dex .Resources == nil {
553+ existingArgoCD .Spec .SSO .Dex .Resources = defaultArgoCDInstance .Spec .SSO .Dex .Resources
554+ changed = true
555+ }
556+ }
557+ }
558+ }
559+ //lint:ignore SA1019 known to be deprecated
560+ if existingArgoCD .Spec .Grafana .Resources == nil { //nolint:staticcheck // SA1019: We must test deprecated fields.
561+ //lint:ignore SA1019 known to be deprecated
562+ existingArgoCD .Spec .Grafana .Resources = defaultArgoCDInstance .Spec .Grafana .Resources //nolint:staticcheck // SA1019: We must test deprecated fields.
563+ changed = true
564+ }
565+ if existingArgoCD .Spec .HA .Resources == nil {
566+ existingArgoCD .Spec .HA .Resources = defaultArgoCDInstance .Spec .HA .Resources
567+ changed = true
568+ }
569+ if existingArgoCD .Spec .Redis .Resources == nil {
570+ existingArgoCD .Spec .Redis .Resources = defaultArgoCDInstance .Spec .Redis .Resources
571+ changed = true
572+ }
573+ if existingArgoCD .Spec .Repo .Resources == nil {
574+ existingArgoCD .Spec .Repo .Resources = defaultArgoCDInstance .Spec .Repo .Resources
575+ changed = true
576+ }
577+ if existingArgoCD .Spec .Server .Resources == nil {
578+ existingArgoCD .Spec .Server .Resources = defaultArgoCDInstance .Spec .Server .Resources
579+ changed = true
580+ }
581+ if defaultArgoCDInstance .Spec .NodePlacement != nil {
582+ if ! equality .Semantic .DeepEqual (existingArgoCD .Spec .NodePlacement , defaultArgoCDInstance .Spec .NodePlacement ) {
583+ existingArgoCD .Spec .NodePlacement = defaultArgoCDInstance .Spec .NodePlacement
584+ changed = true
585+ }
586+ } else if existingArgoCD .Spec .NodePlacement != nil {
587+ existingArgoCD .Spec .NodePlacement = defaultArgoCDInstance .Spec .NodePlacement
588+ changed = true
589+ }
590+ if ! changed {
591+ return nil
592+ }
593+ return r .Client .Update (context .TODO (), existingArgoCD )
594+ })
534595 if err != nil {
535596 return reconcile.Result {}, err
536597 }
@@ -590,8 +651,13 @@ func (r *ReconcileGitopsService) reconcileBackend(gitopsserviceNamespacedName ty
590651 }
591652 } else if ! equality .Semantic .DeepEqual (existingClusterRole .Rules , clusterRoleObj .Rules ) {
592653 reqLogger .Info ("Reconciling existing Cluster Role" , "Name" , clusterRoleObj .Name )
593- existingClusterRole .Rules = clusterRoleObj .Rules
594- err = r .Client .Update (context .TODO (), existingClusterRole )
654+ err = retry .RetryOnConflict (retry .DefaultRetry , func () error {
655+ if err := r .Client .Get (context .TODO (), types.NamespacedName {Name : existingClusterRole .Name }, existingClusterRole ); err != nil {
656+ return err
657+ }
658+ existingClusterRole .Rules = clusterRoleObj .Rules
659+ return r .Client .Update (context .TODO (), existingClusterRole )
660+ })
595661 if err != nil {
596662 return reconcile.Result {}, err
597663 }
@@ -699,7 +765,49 @@ func (r *ReconcileGitopsService) reconcileBackend(gitopsserviceNamespacedName ty
699765
700766 if changed {
701767 reqLogger .Info ("Reconciling existing backend Deployment" , "Namespace" , deploymentObj .Namespace , "Name" , deploymentObj .Name )
702- err = r .Client .Update (context .TODO (), found )
768+ err = retry .RetryOnConflict (retry .DefaultRetry , func () error {
769+ if err := r .Client .Get (context .TODO (), types.NamespacedName {Name : found .Name , Namespace : found .Namespace }, found ); err != nil {
770+ return err
771+ }
772+ changed := false
773+ desiredImage := deploymentObj .Spec .Template .Spec .Containers [0 ].Image
774+ if found .Spec .Template .Spec .Containers [0 ].Image != desiredImage {
775+ found .Spec .Template .Spec .Containers [0 ].Image = desiredImage
776+ changed = true
777+ }
778+ if ! equality .Semantic .DeepEqual (found .Spec .Template .Spec .Containers [0 ].Env , deploymentObj .Spec .Template .Spec .Containers [0 ].Env ) {
779+ found .Spec .Template .Spec .Containers [0 ].Env = deploymentObj .Spec .Template .Spec .Containers [0 ].Env
780+ changed = true
781+ }
782+ if ! equality .Semantic .DeepEqual (found .Spec .Template .Spec .Containers [0 ].Args , deploymentObj .Spec .Template .Spec .Containers [0 ].Args ) {
783+ found .Spec .Template .Spec .Containers [0 ].Args = deploymentObj .Spec .Template .Spec .Containers [0 ].Args
784+ changed = true
785+ }
786+ if ! equality .Semantic .DeepEqual (found .Spec .Template .Spec .Containers [0 ].Resources , deploymentObj .Spec .Template .Spec .Containers [0 ].Resources ) {
787+ found .Spec .Template .Spec .Containers [0 ].Resources = deploymentObj .Spec .Template .Spec .Containers [0 ].Resources
788+ changed = true
789+ }
790+ if ! equality .Semantic .DeepEqual (found .Spec .Template .Spec .Containers [0 ].SecurityContext , deploymentObj .Spec .Template .Spec .Containers [0 ].SecurityContext ) {
791+ found .Spec .Template .Spec .Containers [0 ].SecurityContext = deploymentObj .Spec .Template .Spec .Containers [0 ].SecurityContext
792+ changed = true
793+ }
794+ if ! equality .Semantic .DeepEqual (found .Spec .Template .Spec .NodeSelector , deploymentObj .Spec .Template .Spec .NodeSelector ) {
795+ found .Spec .Template .Spec .NodeSelector = deploymentObj .Spec .Template .Spec .NodeSelector
796+ changed = true
797+ }
798+ if ! equality .Semantic .DeepEqual (found .Spec .Template .Spec .Tolerations , deploymentObj .Spec .Template .Spec .Tolerations ) {
799+ found .Spec .Template .Spec .Tolerations = deploymentObj .Spec .Template .Spec .Tolerations
800+ changed = true
801+ }
802+ if ! equality .Semantic .DeepEqual (found .Spec .Template .Spec .SecurityContext , deploymentObj .Spec .Template .Spec .SecurityContext ) {
803+ found .Spec .Template .Spec .SecurityContext = deploymentObj .Spec .Template .Spec .SecurityContext
804+ changed = true
805+ }
806+ if ! changed {
807+ return nil
808+ }
809+ return r .Client .Update (context .TODO (), found )
810+ })
703811 if err != nil {
704812 return reconcile.Result {}, err
705813 }
0 commit comments