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

[Ingress Addon] Fix bug which the networking.k8s.io/v1 ingress is always rejected #11189

Merged
merged 1 commit into from
Apr 25, 2021
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
4 changes: 3 additions & 1 deletion deploy/addons/ingress/ingress-dp.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ spec:
secret:
secretName: ingress-nginx-admission
---
# Currently(v0.44.0), ValidatingWebhookConfiguration of this validates v1beta1 request
# TODO(govargo): check this after upstream ingress-nginx can validate v1 version
# https://github.com/kubernetes/ingress-nginx/blob/controller-v0.44.0/internal/admission/controller/main.go#L46-L52
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
Expand All @@ -197,7 +200,6 @@ webhooks:
- networking.k8s.io
apiVersions:
- v1beta1
- v1
operations:
- CREATE
- UPDATE
Expand Down
66 changes: 61 additions & 5 deletions test/integration/addons_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,10 @@ func validateIngressAddon(ctx context.Context, t *testing.T, profile string) {
t.Fatalf("failed waititing for ingress-nginx-controller : %v", err)
}

createIngress := func() error {
rr, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "replace", "--force", "-f", filepath.Join(*testdataDir, "nginx-ing.yaml")))
// create networking.k8s.io/v1beta1 ingress
createv1betaIngress := func() error {
// apply networking.k8s.io/v1beta1 ingress
rr, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "replace", "--force", "-f", filepath.Join(*testdataDir, "nginx-ingv1beta.yaml")))
if err != nil {
return err
}
Expand All @@ -170,7 +172,8 @@ func validateIngressAddon(ctx context.Context, t *testing.T, profile string) {
return nil
}

if err := retry.Expo(createIngress, 1*time.Second, Seconds(90)); err != nil {
// create networking.k8s.io/v1beta1 ingress
if err := retry.Expo(createv1betaIngress, 1*time.Second, Seconds(90)); err != nil {
t.Errorf("failed to create ingress: %v", err)
}

Expand All @@ -188,7 +191,8 @@ func validateIngressAddon(ctx context.Context, t *testing.T, profile string) {

want := "Welcome to nginx!"
addr := "http://127.0.0.1/"
checkIngress := func() error {
// check if the ingress can route nginx app with networking.k8s.io/v1beta1 ingress
checkv1betaIngress := func() error {
var rr *RunResult
var err error
if NoneDriver() { // just run curl directly on the none driver
Expand All @@ -215,7 +219,59 @@ func validateIngressAddon(ctx context.Context, t *testing.T, profile string) {
return nil
}

if err := retry.Expo(checkIngress, 500*time.Millisecond, Seconds(90)); err != nil {
// check if the ingress can route nginx app with networking.k8s.io/v1beta1 ingress
if err := retry.Expo(checkv1betaIngress, 500*time.Millisecond, Seconds(90)); err != nil {
t.Errorf("failed to get expected response from %s within minikube: %v", addr, err)
}

// create networking.k8s.io/v1 ingress
createv1Ingress := func() error {
// apply networking.k8s.io/v1beta1 ingress
rr, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "replace", "--force", "-f", filepath.Join(*testdataDir, "nginx-ingv1.yaml")))
if err != nil {
return err
}
if rr.Stderr.String() != "" {
t.Logf("%v: unexpected stderr: %s (may be temporary)", rr.Command(), rr.Stderr)
}
return nil
}

// create networking.k8s.io/v1 ingress
if err := retry.Expo(createv1Ingress, 1*time.Second, Seconds(90)); err != nil {
t.Errorf("failed to create ingress: %v", err)
}

// check if the ingress can route nginx app with networking.k8s.io/v1 ingress
checkv1Ingress := func() error {
var rr *RunResult
var err error
if NoneDriver() { // just run curl directly on the none driver
rr, err = Run(t, exec.CommandContext(ctx, "curl", "-s", addr, "-H", "'Host: nginx.example.com'"))
if err != nil {
return err
}
} else {
rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "ssh", fmt.Sprintf("curl -s %s -H 'Host: nginx.example.com'", addr)))
if err != nil {
return err
}
}

stderr := rr.Stderr.String()
if rr.Stderr.String() != "" {
t.Logf("debug: unexpected stderr for %v:\n%s", rr.Command(), stderr)
}

stdout := rr.Stdout.String()
if !strings.Contains(stdout, want) {
return fmt.Errorf("%v stdout = %q, want %q", rr.Command(), stdout, want)
}
return nil
}

// check if the ingress can route nginx app with networking.k8s.io/v1 ingress
if err := retry.Expo(checkv1Ingress, 500*time.Millisecond, Seconds(90)); err != nil {
t.Errorf("failed to get expected response from %s within minikube: %v", addr, err)
}

Expand Down
20 changes: 20 additions & 0 deletions test/integration/testdata/nginx-ingv1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nginx-ingress
annotations:
kubernetes.io/ingress.class: "nginx"
labels:
integration-test: ingress
spec:
rules:
- host: nginx.example.com
http:
paths:
- path: "/"
pathType: Prefix
backend:
service:
name: nginx
port:
number: 80
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ spec:
- path: "/"
backend:
serviceName: nginx
servicePort: 80
servicePort: 80