fix ingress-dns addon and add test

pull/12476/head
Sharif Elgamal 2021-09-14 17:41:26 -07:00
parent 28770a3848
commit 803fc43e26
5 changed files with 137 additions and 21 deletions

View File

@ -38,10 +38,8 @@ kind: Ingress
metadata:
name: example-ingress
namespace: kube-system
annotations:
# use the shared ingress-nginx
kubernetes.io/ingress.class: nginx
spec:
ingressClassName: nginx
rules:
- host: hello-john.test
http:

View File

@ -253,6 +253,17 @@ subjects:
name: ingress-nginx
namespace: ingress-nginx
---
apiVersion: networking.k8s.io/v1
kind: IngressClass
metadata:
labels:
app.kubernetes.io/component: controller
name: nginx
annotations:
ingressclass.kubernetes.io/is-default-class: "true"
spec:
controller: k8s.io/ingress-nginx
---
# Source: ingress-nginx/templates/controller-service-webhook.yaml
apiVersion: v1
kind: Service

View File

@ -480,8 +480,10 @@ var Addons = map[string]*Addon{
"ingress-dns-pod.yaml",
"0640"),
}, false, "ingress-dns", "", map[string]string{
"IngressDNS": "cryptexlabs/minikube-ingress-dns:0.3.0@sha256:e252d2a4c704027342b303cc563e95d2e71d2a0f1404f55d676390e28d5093ab",
}, nil),
"IngressDNS": "k8s-minikube/minikube-ingress-dns:0.0.1@sha256:69dc3c878c2e49ad85b70fdf9e8e6e87a1f961f42c8029e0912bebfa828ade46",
}, map[string]string{
"IngressDNS": "gcr.io",
}),
"metallb": NewAddon([]*BinAsset{
MustBinAsset(addons.MetallbAssets,
"metallb/metallb.yaml.tmpl",

View File

@ -69,7 +69,7 @@ func TestAddons(t *testing.T) {
args := append([]string{"start", "-p", profile, "--wait=true", "--memory=4000", "--alsologtostderr", "--addons=registry", "--addons=metrics-server", "--addons=olm", "--addons=volumesnapshots", "--addons=csi-hostpath-driver"}, StartArgs()...)
if !NoneDriver() { // none driver does not support ingress
args = append(args, "--addons=ingress")
args = append(args, "--addons=ingress", "--addons=ingress-dns")
}
if !arm64Platform() {
args = append(args, "--addons=helm-tiller")
@ -156,7 +156,7 @@ func TestAddons(t *testing.T) {
func validateIngressAddon(ctx context.Context, t *testing.T, profile string) {
defer PostMortemLogs(t, profile)
if NoneDriver() {
t.Skipf("skipping: ingress not supported ")
t.Skipf("skipping: ingress not supported")
}
client, err := kapi.Client(profile)
@ -168,7 +168,7 @@ func validateIngressAddon(ctx context.Context, t *testing.T, profile string) {
// Error from server (InternalError): Internal error occurred: failed calling webhook "validate.nginx.ingress.kubernetes.io": Post "https://ingress-nginx-controller-admission.ingress-nginx.svc:443/networking/v1/ingresses?timeout=10s": dial tcp 10.107.218.58:443: i/o timeout
// Error from server (InternalError): Internal error occurred: failed calling webhook "validate.nginx.ingress.kubernetes.io": Post "https://ingress-nginx-controller-admission.ingress-nginx.svc:443/networking/v1/ingresses?timeout=10s": context deadline exceeded
if _, err = Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "wait", "--for=condition=ready", "--namespace=ingress-nginx", "pod", "--selector=app.kubernetes.io/component=controller", "--timeout=90s")); err != nil {
t.Fatalf("failed waititing for ingress-nginx-controller : %v", err)
t.Fatalf("failed waiting for ingress-nginx-controller : %v", err)
}
// create networking.k8s.io/v1 ingress
@ -192,7 +192,7 @@ func validateIngressAddon(ctx context.Context, t *testing.T, profile string) {
t.Errorf("failed to kubectl replace nginx-pod-svc. args %q. %v", rr.Command(), err)
}
if _, err := PodWait(ctx, t, profile, "default", "run=nginx", Minutes(4)); err != nil {
if _, err := PodWait(ctx, t, profile, "default", "run=nginx", Minutes(8)); err != nil {
t.Fatalf("failed waiting for ngnix pod: %v", err)
}
if err := kapi.WaitForService(client, "default", "nginx", true, time.Millisecond*500, Minutes(10)); err != nil {
@ -204,19 +204,11 @@ func validateIngressAddon(ctx context.Context, t *testing.T, profile string) {
// 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
}
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)
@ -231,6 +223,32 @@ func validateIngressAddon(ctx context.Context, t *testing.T, profile string) {
t.Errorf("failed to get expected response from %s within minikube: %v", addr, err)
}
// check the ingress-dns addon here as well
rr, err = Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "replace", "--force", "-f", filepath.Join(*testdataDir, "ingress-dns-example.yaml")))
if err != nil {
t.Errorf("failed to kubectl replace ingress-dns-example. args %q. %v", rr.Command(), err)
}
rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "ip"))
if err != nil {
t.Errorf("failed to retrieve minikube ip. args %q : %v", rr.Command(), err)
}
ip := strings.TrimSuffix(rr.Stdout.String(), "\n")
rr, err = Run(t, exec.CommandContext(ctx, "nslookup", "hello-john.test", ip))
if err != nil {
t.Errorf("failed to nslookup hello-john.test host. args %q : %v", rr.Command(), err)
}
// nslookup should include info about the hello-john.test host, including minikube's ip
if !strings.Contains(rr.Stdout.String(), ip) {
t.Errorf("unexpected output from nslookup. stdout: %v\nstderr: %v", rr.Stdout.String(), rr.Stderr.String())
}
rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "addons", "disable", "ingress-dns", "--alsologtostderr", "-v=1"))
if err != nil {
t.Errorf("failed to disable ingress-dns addon. args %q : %v", rr.Command(), err)
}
rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "addons", "disable", "ingress", "--alsologtostderr", "-v=1"))
if err != nil {
t.Errorf("failed to disable ingress addon. args %q : %v", rr.Command(), err)

View File

@ -0,0 +1,87 @@
# Copyright 2016 The Kubernetes Authors All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-world-app
namespace: default
spec:
selector:
matchLabels:
app: hello-world-app
template:
metadata:
labels:
app: hello-world-app
spec:
containers:
- name: hello-world-app
image: gcr.io/google-samples/hello-app:1.0
ports:
- containerPort: 8080
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
namespace: kube-system
spec:
ingressClassName: nginx
rules:
- host: hello-john.test
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: hello-world-app
port:
number: 80
- host: hello-jane.test
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: hello-world-app
port:
number: 80
---
apiVersion: v1
kind: Service
metadata:
name: hello-world-app
namespace: kube-system
spec:
type: ExternalName
externalName: hello-world-app.default.svc.cluster.local
---
apiVersion: v1
kind: Service
metadata:
name: hello-world-app
namespace: default
spec:
ports:
- name: http
port: 80
targetPort: 8080
protocol: TCP
type: NodePort
selector:
app: hello-world-app