Skip to content

Commit

Permalink
Update ingressClassName of ingress based on ArgoCD ingressClassName
Browse files Browse the repository at this point in the history
Signed-off-by: Rizwana777 <[email protected]>
  • Loading branch information
Rizwana777 committed Jun 5, 2024
1 parent cdf3832 commit e1bcc65
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
6 changes: 6 additions & 0 deletions controllers/argocd/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ func (r *ReconcileArgoCD) reconcileArgoServerIngress(cr *argoproj.ArgoCD) error
// Ingress exists but enabled flag has been set to false, delete the Ingress
return r.Client.Delete(context.TODO(), ingress)
}

// If Ingress found and enabled, make sure the ingressClassName is up-to-date
if ingress.Spec.IngressClassName != cr.Spec.Server.Ingress.IngressClassName {
ingress.Spec.IngressClassName = cr.Spec.Server.Ingress.IngressClassName
return r.Client.Update(context.TODO(), ingress)
}
return nil // Ingress found and enabled, do nothing
}

Expand Down
43 changes: 43 additions & 0 deletions controllers/argocd/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/stretchr/testify/assert"
networkingv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -63,6 +64,48 @@ func TestReconcileArgoCD_reconcile_ServerIngress_ingressClassName(t *testing.T)
}
}

func TestReconcileArgoCD_reconcile_ServerIngress_ingressClassName_update(t *testing.T) {
logf.SetLogger(ZapLogger(true))

nginx := "nginx"
existingIngressClassName := "test-name"

a := makeTestArgoCD(func(a *argoproj.ArgoCD) {
a.Spec.Server.Ingress.Enabled = true
a.Spec.Server.Ingress.IngressClassName = &nginx
})

// Existing ingress with different ingressClassName
ingress := &networkingv1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: "argocd-server",
Namespace: a.Namespace,
},
Spec: networkingv1.IngressSpec{
IngressClassName: &existingIngressClassName,
},
}

resObjs := []client.Object{a, ingress}
subresObjs := []client.Object{a}
runtimeObjs := []runtime.Object{}
sch := makeTestReconcilerScheme(argoproj.AddToScheme)
cl := makeTestReconcilerClient(sch, resObjs, subresObjs, runtimeObjs)
r := makeTestReconciler(cl, sch)

err := r.reconcileArgoServerIngress(a)
assert.NoError(t, err)

updatedIngress := &networkingv1.Ingress{}
err = r.Client.Get(context.TODO(), types.NamespacedName{
Name: "argocd-server",
Namespace: testNamespace,
}, updatedIngress)
assert.NoError(t, err)
assert.Equal(t, a.Spec.Server.Ingress.IngressClassName, updatedIngress.Spec.IngressClassName)

}

func TestReconcileArgoCD_reconcile_ServerGRPCIngress_ingressClassName(t *testing.T) {
logf.SetLogger(ZapLogger(true))

Expand Down

0 comments on commit e1bcc65

Please sign in to comment.