Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ingressClassName of ingress based on ArgoCD ingressClassName #1395

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading