Skip to content

Commit 0c1786b

Browse files
authored
Update ingressClassName of ingress based on ArgoCD ingressClassName (#1395)
Signed-off-by: Rizwana777 <[email protected]>
1 parent 9aa0676 commit 0c1786b

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

controllers/argocd/ingress.go

+6
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ func (r *ReconcileArgoCD) reconcileArgoServerIngress(cr *argoproj.ArgoCD) error
9797
// Ingress exists but enabled flag has been set to false, delete the Ingress
9898
return r.Client.Delete(context.TODO(), ingress)
9999
}
100+
101+
// If Ingress found and enabled, make sure the ingressClassName is up-to-date
102+
if ingress.Spec.IngressClassName != cr.Spec.Server.Ingress.IngressClassName {
103+
ingress.Spec.IngressClassName = cr.Spec.Server.Ingress.IngressClassName
104+
return r.Client.Update(context.TODO(), ingress)
105+
}
100106
return nil // Ingress found and enabled, do nothing
101107
}
102108

controllers/argocd/ingress_test.go

+43
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/stretchr/testify/assert"
88
networkingv1 "k8s.io/api/networking/v1"
9+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
910
"k8s.io/apimachinery/pkg/runtime"
1011
"k8s.io/apimachinery/pkg/types"
1112
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -63,6 +64,48 @@ func TestReconcileArgoCD_reconcile_ServerIngress_ingressClassName(t *testing.T)
6364
}
6465
}
6566

67+
func TestReconcileArgoCD_reconcile_ServerIngress_ingressClassName_update(t *testing.T) {
68+
logf.SetLogger(ZapLogger(true))
69+
70+
nginx := "nginx"
71+
existingIngressClassName := "test-name"
72+
73+
a := makeTestArgoCD(func(a *argoproj.ArgoCD) {
74+
a.Spec.Server.Ingress.Enabled = true
75+
a.Spec.Server.Ingress.IngressClassName = &nginx
76+
})
77+
78+
// Existing ingress with different ingressClassName
79+
ingress := &networkingv1.Ingress{
80+
ObjectMeta: metav1.ObjectMeta{
81+
Name: "argocd-server",
82+
Namespace: a.Namespace,
83+
},
84+
Spec: networkingv1.IngressSpec{
85+
IngressClassName: &existingIngressClassName,
86+
},
87+
}
88+
89+
resObjs := []client.Object{a, ingress}
90+
subresObjs := []client.Object{a}
91+
runtimeObjs := []runtime.Object{}
92+
sch := makeTestReconcilerScheme(argoproj.AddToScheme)
93+
cl := makeTestReconcilerClient(sch, resObjs, subresObjs, runtimeObjs)
94+
r := makeTestReconciler(cl, sch)
95+
96+
err := r.reconcileArgoServerIngress(a)
97+
assert.NoError(t, err)
98+
99+
updatedIngress := &networkingv1.Ingress{}
100+
err = r.Client.Get(context.TODO(), types.NamespacedName{
101+
Name: "argocd-server",
102+
Namespace: testNamespace,
103+
}, updatedIngress)
104+
assert.NoError(t, err)
105+
assert.Equal(t, a.Spec.Server.Ingress.IngressClassName, updatedIngress.Spec.IngressClassName)
106+
107+
}
108+
66109
func TestReconcileArgoCD_reconcile_ServerGRPCIngress_ingressClassName(t *testing.T) {
67110
logf.SetLogger(ZapLogger(true))
68111

0 commit comments

Comments
 (0)