-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
fix: check default ingclass when ingclass is nill #2963
Changes from all commits
b8641e1
f0b82e3
cd7bf2c
eb9f773
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ package ingress | |
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/golang/mock/gomock" | ||
"github.com/google/go-cmp/cmp" | ||
|
@@ -18,7 +20,6 @@ import ( | |
"sigs.k8s.io/aws-load-balancer-controller/pkg/webhook" | ||
testclient "sigs.k8s.io/controller-runtime/pkg/client/fake" | ||
"sigs.k8s.io/controller-runtime/pkg/webhook/admission" | ||
"testing" | ||
) | ||
|
||
func Test_defaultClassLoader_Load(t *testing.T) { | ||
|
@@ -38,7 +39,57 @@ func Test_defaultClassLoader_Load(t *testing.T) { | |
wantErr error | ||
}{ | ||
{ | ||
name: "when IngressClassName unspecified", | ||
name: "when IngressClassName unspecified - Default class specified", | ||
env: env{ | ||
nsList: []*corev1.Namespace{ | ||
{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "awesome-ns", | ||
}, | ||
}, | ||
}, | ||
ingClassList: []*networking.IngressClass{ | ||
{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "awesome-ingress-class", | ||
Annotations: map[string]string{ | ||
"ingressclass.kubernetes.io/is-default-class": "true", | ||
}, | ||
}, | ||
Spec: networking.IngressClassSpec{ | ||
Controller: "awesome-ingress-controller", | ||
}, | ||
}, | ||
}, | ||
}, | ||
args: args{ | ||
ing: &networking.Ingress{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Namespace: "awesome-ns", | ||
Name: "awesome-ing", | ||
}, | ||
Spec: networking.IngressSpec{ | ||
IngressClassName: nil, | ||
}, | ||
}, | ||
}, | ||
want: ClassConfiguration{ | ||
IngClass: &networking.IngressClass{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "awesome-ingress-class", | ||
Annotations: map[string]string{ | ||
"ingressclass.kubernetes.io/is-default-class": "true", | ||
}, | ||
}, | ||
Spec: networking.IngressClassSpec{ | ||
Controller: "awesome-ingress-controller", | ||
}, | ||
}, | ||
}, | ||
wantErr: nil, | ||
}, | ||
{ | ||
name: "when IngressClassName unspecified - Default class unspecified", | ||
env: env{ | ||
nsList: []*corev1.Namespace{ | ||
{ | ||
|
@@ -59,7 +110,116 @@ func Test_defaultClassLoader_Load(t *testing.T) { | |
}, | ||
}, | ||
}, | ||
wantErr: errors.New("invalid ingress class: spec.ingressClassName is nil"), | ||
want: ClassConfiguration{}, | ||
}, | ||
{ | ||
name: "when IngressClassName unspecified - Multiple default classes specified", | ||
env: env{ | ||
nsList: []*corev1.Namespace{ | ||
{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "awesome-ns", | ||
}, | ||
}, | ||
}, | ||
ingClassList: []*networking.IngressClass{ | ||
{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "awesome-ingress-class-1", | ||
Annotations: map[string]string{ | ||
"ingressclass.kubernetes.io/is-default-class": "true", | ||
}, | ||
}, | ||
Spec: networking.IngressClassSpec{ | ||
Controller: "awesome-ingress-controller-1", | ||
}, | ||
}, | ||
{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "awesome-ingress-class-2", | ||
Annotations: map[string]string{ | ||
"ingressclass.kubernetes.io/is-default-class": "true", | ||
}, | ||
}, | ||
Spec: networking.IngressClassSpec{ | ||
Controller: "awesome-ingress-controller-2", | ||
}, | ||
}, | ||
}, | ||
}, | ||
args: args{ | ||
ing: &networking.Ingress{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Namespace: "awesome-ns", | ||
Name: "awesome-ing", | ||
}, | ||
Spec: networking.IngressSpec{ | ||
IngressClassName: nil, | ||
}, | ||
}, | ||
}, | ||
wantErr: errors.New("multiple default IngressClasses found"), | ||
}, | ||
{ | ||
name: "when IngressClass is ALB - Multiple default classes specified", | ||
env: env{ | ||
nsList: []*corev1.Namespace{ | ||
{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "awesome-ns", | ||
}, | ||
}, | ||
}, | ||
ingClassList: []*networking.IngressClass{ | ||
{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "awesome-ingress-class-1", | ||
Annotations: map[string]string{ | ||
"ingressclass.kubernetes.io/is-default-class": "true", | ||
}, | ||
}, | ||
Spec: networking.IngressClassSpec{ | ||
Controller: "ingress.k8s.aws/alb", | ||
}, | ||
}, | ||
{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "awesome-ingress-class-2", | ||
Annotations: map[string]string{ | ||
"ingressclass.kubernetes.io/is-default-class": "true", | ||
}, | ||
}, | ||
Spec: networking.IngressClassSpec{ | ||
Controller: "awesome-ingress-controller-2", | ||
}, | ||
}, | ||
}, | ||
}, | ||
args: args{ | ||
ing: &networking.Ingress{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Namespace: "awesome-ns", | ||
Name: "awesome-ing", | ||
}, | ||
Spec: networking.IngressSpec{ | ||
IngressClassName: aws.String("awesome-ingress-class-1"), | ||
}, | ||
}, | ||
}, | ||
want: ClassConfiguration{ | ||
IngClass: &networking.IngressClass{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "awesome-ingress-class-1", | ||
Annotations: map[string]string{ | ||
"ingressclass.kubernetes.io/is-default-class": "true", | ||
}, | ||
}, | ||
Spec: networking.IngressClassSpec{ | ||
Controller: "ingress.k8s.aws/alb", | ||
}, | ||
}, | ||
}, | ||
wantErr: nil, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should specify Need to add a test where there is a default IngressClass. It should assert that the default IngressClass was used. Need to add a test where there are two IngressClasses annotated as being the default. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added multiple test cases
|
||
}, | ||
{ | ||
name: "when IngressClass not found", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Document the behavior for when there is no default IngressClass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @johngmyers
Thank you for reviewing my code.
I added the document about it.