Merge pull request #11189 from govargo/fix-ingress-addon
[Ingress Addon] Fix bug which the networking.k8s.io/v1 ingress is always rejectedpull/11203/head
commit
b31da8d335
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue