@@ -680,6 +680,149 @@ func TestReconcileArgoCD_reconcileDexDeployment_withUpdate(t *testing.T) {
680680 }
681681}
682682
683+ func TestReconcileArgoCD_reconcileDexDeployment_updatesInitContainerFields (t * testing.T ) {
684+ logf .SetLogger (ZapLogger (true ))
685+
686+ // staleDeployment simulates a Dex Deployment created by an old operator version (e.g., v1.13)
687+ // that only has the "static-files" volumeMount in the copyutil initContainer and no dexconfig volume.
688+ staleDeployment := func (namespace string ) * appsv1.Deployment {
689+ return & appsv1.Deployment {
690+ ObjectMeta : metav1.ObjectMeta {
691+ Name : "argocd-dex-server" ,
692+ Namespace : namespace ,
693+ },
694+ Spec : appsv1.DeploymentSpec {
695+ Selector : & metav1.LabelSelector {
696+ MatchLabels : map [string ]string {
697+ "app.kubernetes.io/name" : "argocd-dex-server" ,
698+ },
699+ },
700+ Template : corev1.PodTemplateSpec {
701+ ObjectMeta : metav1.ObjectMeta {
702+ Labels : map [string ]string {
703+ "app.kubernetes.io/name" : "argocd-dex-server" ,
704+ },
705+ },
706+ Spec : corev1.PodSpec {
707+ InitContainers : []corev1.Container {
708+ {
709+ Name : "copyutil" ,
710+ // Old state: only static-files, dexconfig mount is absent
711+ VolumeMounts : []corev1.VolumeMount {
712+ {Name : "static-files" , MountPath : "/shared" },
713+ },
714+ Resources : corev1.ResourceRequirements {
715+ Limits : corev1.ResourceList {
716+ corev1 .ResourceMemory : resourcev1 .MustParse ("128Mi" ),
717+ },
718+ Requests : corev1.ResourceList {
719+ corev1 .ResourceCPU : resourcev1 .MustParse ("15m" ),
720+ corev1 .ResourceMemory : resourcev1 .MustParse ("128Mi" ),
721+ },
722+ },
723+ },
724+ },
725+ Containers : []corev1.Container {
726+ {Name : "dex" },
727+ },
728+ Volumes : []corev1.Volume {
729+ {
730+ Name : "static-files" ,
731+ VolumeSource : corev1.VolumeSource {EmptyDir : & corev1.EmptyDirVolumeSource {}},
732+ },
733+ },
734+ },
735+ },
736+ },
737+ }
738+ }
739+
740+ tests := []struct {
741+ name string
742+ argoCD * argoproj.ArgoCD
743+ wantInitVolumeMounts []corev1.VolumeMount
744+ wantInitResources corev1.ResourceRequirements
745+ }{
746+ {
747+ name : "reconciler adds missing dexconfig volumeMount to copyutil initContainer on upgrade" ,
748+ argoCD : makeTestArgoCD (func (cr * argoproj.ArgoCD ) {
749+ cr .Spec .SSO = & argoproj.ArgoCDSSOSpec {
750+ Provider : argoproj .SSOProviderTypeDex ,
751+ }
752+ }),
753+ wantInitVolumeMounts : []corev1.VolumeMount {
754+ {Name : "static-files" , MountPath : "/shared" },
755+ {Name : "dexconfig" , MountPath : "/tmp" },
756+ },
757+ wantInitResources : corev1.ResourceRequirements {},
758+ },
759+ {
760+ name : "reconciler updates stale resources in copyutil initContainer on upgrade" ,
761+ argoCD : makeTestArgoCD (func (cr * argoproj.ArgoCD ) {
762+ cr .Spec .SSO = & argoproj.ArgoCDSSOSpec {
763+ Provider : argoproj .SSOProviderTypeDex ,
764+ Dex : & argoproj.ArgoCDDexSpec {
765+ Resources : & corev1.ResourceRequirements {
766+ Requests : corev1.ResourceList {
767+ corev1 .ResourceMemory : resourcev1 .MustParse ("128Mi" ),
768+ corev1 .ResourceCPU : resourcev1 .MustParse ("250m" ),
769+ },
770+ Limits : corev1.ResourceList {
771+ corev1 .ResourceMemory : resourcev1 .MustParse ("256Mi" ),
772+ corev1 .ResourceCPU : resourcev1 .MustParse ("500m" ),
773+ },
774+ },
775+ },
776+ }
777+ }),
778+ wantInitVolumeMounts : []corev1.VolumeMount {
779+ {Name : "static-files" , MountPath : "/shared" },
780+ {Name : "dexconfig" , MountPath : "/tmp" },
781+ },
782+ wantInitResources : corev1.ResourceRequirements {
783+ Requests : corev1.ResourceList {
784+ corev1 .ResourceMemory : resourcev1 .MustParse ("128Mi" ),
785+ corev1 .ResourceCPU : resourcev1 .MustParse ("250m" ),
786+ },
787+ Limits : corev1.ResourceList {
788+ corev1 .ResourceMemory : resourcev1 .MustParse ("256Mi" ),
789+ corev1 .ResourceCPU : resourcev1 .MustParse ("500m" ),
790+ },
791+ },
792+ },
793+ }
794+
795+ for _ , test := range tests {
796+ t .Run (test .name , func (t * testing.T ) {
797+ existingDeploy := staleDeployment (test .argoCD .Namespace )
798+ resObjs := []client.Object {test .argoCD , existingDeploy }
799+ subresObjs := []client.Object {test .argoCD }
800+ runtimeObjs := []runtime.Object {}
801+ sch := makeTestReconcilerScheme (argoproj .AddToScheme )
802+ cl := makeTestReconcilerClient (sch , resObjs , subresObjs , runtimeObjs )
803+ r := makeTestReconciler (cl , sch , testclient .NewSimpleClientset ())
804+
805+ assert .NoError (t , r .reconcileDexDeployment (test .argoCD ))
806+
807+ deployment := & appsv1.Deployment {}
808+ assert .NoError (t , r .Get (
809+ context .TODO (),
810+ types.NamespacedName {
811+ Name : "argocd-dex-server" ,
812+ Namespace : test .argoCD .Namespace ,
813+ },
814+ deployment ))
815+
816+ assert .Equal (t , test .wantInitVolumeMounts ,
817+ deployment .Spec .Template .Spec .InitContainers [0 ].VolumeMounts ,
818+ "copyutil initContainer VolumeMounts should be updated by reconciler" )
819+ assert .Equal (t , test .wantInitResources ,
820+ deployment .Spec .Template .Spec .InitContainers [0 ].Resources ,
821+ "copyutil initContainer Resources should be updated by reconciler" )
822+ })
823+ }
824+ }
825+
683826// When Dex is enabled dex service should be created, when disabled the Dex service should be removed
684827func TestReconcileArgoCD_reconcileDexService_removes_dex_when_disabled (t * testing.T ) {
685828 logf .SetLogger (ZapLogger (true ))
0 commit comments