Skip to content

Commit

Permalink
Merge pull request #11189 from govargo/fix-ingress-addon
Browse files Browse the repository at this point in the history
[Ingress Addon] Fix bug which the networking.k8s.io/v1 ingress is always rejected
  • Loading branch information
medyagh authored Apr 25, 2021
2 parents 222dbec + cc9afff commit b31da8d
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 7 deletions.
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

0 comments on commit b31da8d

Please sign in to comment.