diff --git a/deploy/addons/ingress/ingress-dp.yaml.tmpl b/deploy/addons/ingress/ingress-dp.yaml.tmpl index 4b43a06580..694534c936 100644 --- a/deploy/addons/ingress/ingress-dp.yaml.tmpl +++ b/deploy/addons/ingress/ingress-dp.yaml.tmpl @@ -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: @@ -197,7 +200,6 @@ webhooks: - networking.k8s.io apiVersions: - v1beta1 - - v1 operations: - CREATE - UPDATE diff --git a/test/integration/addons_test.go b/test/integration/addons_test.go index aa936e5379..8475f78489 100644 --- a/test/integration/addons_test.go +++ b/test/integration/addons_test.go @@ -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 } @@ -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) } @@ -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 @@ -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) } diff --git a/test/integration/testdata/nginx-ingv1.yaml b/test/integration/testdata/nginx-ingv1.yaml new file mode 100644 index 0000000000..03663248ea --- /dev/null +++ b/test/integration/testdata/nginx-ingv1.yaml @@ -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 \ No newline at end of file diff --git a/test/integration/testdata/nginx-ing.yaml b/test/integration/testdata/nginx-ingv1beta.yaml similarity index 92% rename from test/integration/testdata/nginx-ing.yaml rename to test/integration/testdata/nginx-ingv1beta.yaml index fe84aa5223..a714737080 100644 --- a/test/integration/testdata/nginx-ing.yaml +++ b/test/integration/testdata/nginx-ingv1beta.yaml @@ -14,4 +14,4 @@ spec: - path: "/" backend: serviceName: nginx - servicePort: 80 + servicePort: 80 \ No newline at end of file