Skip to content

Commit ea3aa4f

Browse files
committedOct 28, 2021
support ingress-dns addon, add tests
1 parent 76c1e79 commit ea3aa4f

7 files changed

+226
-13
lines changed
 

‎pkg/addons/addons.go

+23-8
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func EnableOrDisableAddon(cc *config.ClusterConfig, name string, val string) err
179179
exit.Error(reason.GuestCpConfig, "Error getting primary control plane", err)
180180
}
181181

182-
// maintain backwards compatibility for ingress with k8s < v1.19
182+
// maintain backwards compatibility for ingress and ingress-dns addons with k8s < v1.19
183183
if strings.HasPrefix(name, "ingress") && enable {
184184
if err := supportLegacyIngress(addon, *cc); err != nil {
185185
return err
@@ -294,21 +294,36 @@ func isAddonAlreadySet(cc *config.ClusterConfig, addon *assets.Addon, enable boo
294294
return false
295295
}
296296

297-
// maintain backwards compatibility for ingress with k8s < v1.19 by replacing default addon images with older versions
297+
// maintain backwards compatibility for ingress and ingress-dns addons with k8s < v1.19 by replacing default addons' images with compatible versions
298298
func supportLegacyIngress(addon *assets.Addon, cc config.ClusterConfig) error {
299299
v, err := util.ParseKubernetesVersion(cc.KubernetesConfig.KubernetesVersion)
300300
if err != nil {
301301
return errors.Wrap(err, "parsing Kubernetes version")
302302
}
303303
if semver.MustParseRange("<1.19.0")(v) {
304-
addon.Images = map[string]string{
305-
// https://github.com/kubernetes/ingress-nginx/blob/0a2ec01eb4ec0e1b29c4b96eb838a2e7bfe0e9f6/deploy/static/provider/kind/deploy.yaml#L328
306-
"IngressController": "ingress-nginx/controller:v0.49.3@sha256:35fe394c82164efa8f47f3ed0be981b3f23da77175bbb8268a9ae438851c8324",
307-
// issues: https://github.com/kubernetes/ingress-nginx/issues/7418 and https://github.com/jet/kube-webhook-certgen/issues/30
308-
"KubeWebhookCertgenCreate": "docker.io/jettech/kube-webhook-certgen:v1.5.1@sha256:950833e19ade18cd389d647efb88992a7cc077abedef343fa59e012d376d79b7",
309-
"KubeWebhookCertgenPatch": "docker.io/jettech/kube-webhook-certgen:v1.5.1@sha256:950833e19ade18cd389d647efb88992a7cc077abedef343fa59e012d376d79b7",
304+
if addon.Name() == "ingress" {
305+
addon.Images = map[string]string{
306+
// https://github.com/kubernetes/ingress-nginx/blob/0a2ec01eb4ec0e1b29c4b96eb838a2e7bfe0e9f6/deploy/static/provider/kind/deploy.yaml#L328
307+
"IngressController": "ingress-nginx/controller:v0.49.3@sha256:35fe394c82164efa8f47f3ed0be981b3f23da77175bbb8268a9ae438851c8324",
308+
// issues: https://github.com/kubernetes/ingress-nginx/issues/7418 and https://github.com/jet/kube-webhook-certgen/issues/30
309+
"KubeWebhookCertgenCreate": "docker.io/jettech/kube-webhook-certgen:v1.5.1@sha256:950833e19ade18cd389d647efb88992a7cc077abedef343fa59e012d376d79b7",
310+
"KubeWebhookCertgenPatch": "docker.io/jettech/kube-webhook-certgen:v1.5.1@sha256:950833e19ade18cd389d647efb88992a7cc077abedef343fa59e012d376d79b7",
311+
}
312+
addon.Registries = map[string]string{
313+
"IngressController": "k8s.gcr.io",
314+
}
315+
return nil
310316
}
317+
if addon.Name() == "ingress-dns" {
318+
addon.Images = map[string]string{
319+
"IngressDNS": "cryptexlabs/minikube-ingress-dns:0.3.0@sha256:e252d2a4c704027342b303cc563e95d2e71d2a0f1404f55d676390e28d5093ab",
320+
}
321+
addon.Registries = nil
322+
return nil
323+
}
324+
return fmt.Errorf("supportLegacyIngress called for unexpected addon %q - nothing to do here", addon.Name())
311325
}
326+
312327
return nil
313328
}
314329

‎test/integration/addons_test.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"testing"
3535
"time"
3636

37+
"github.com/blang/semver/v4"
3738
retryablehttp "github.com/hashicorp/go-retryablehttp"
3839
"k8s.io/minikube/pkg/kapi"
3940
"k8s.io/minikube/pkg/minikube/detect"
@@ -163,10 +164,23 @@ func validateIngressAddon(ctx context.Context, t *testing.T, profile string) {
163164
t.Fatalf("failed waiting for ingress-nginx-controller : %v", err)
164165
}
165166

167+
// use nginx ingress yaml that corresponds to k8s version
168+
// default: k8s >= v1.19, ingress api v1
169+
ingressYaml := "nginx-ingress-v1.yaml"
170+
ingressDNSYaml := "ingress-dns-example-v1.yaml"
171+
v, err := client.ServerVersion()
172+
if err != nil {
173+
t.Log("failed to get k8s version, assuming v1.19+ => ingress api v1")
174+
} else if semver.MustParseRange("<1.19.0")(semver.MustParse(fmt.Sprintf("%s.%s.0", v.Major, v.Minor))) {
175+
// legacy: k8s < v1.19 & ingress api v1beta1
176+
ingressYaml = "nginx-ingress-v1beta1.yaml"
177+
ingressDNSYaml = "ingress-dns-example-v1beta1.yaml"
178+
}
179+
166180
// create networking.k8s.io/v1 ingress
167181
createv1Ingress := func() error {
168182
// apply networking.k8s.io/v1 ingress
169-
rr, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "replace", "--force", "-f", filepath.Join(*testdataDir, "nginx-ingv1.yaml")))
183+
rr, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "replace", "--force", "-f", filepath.Join(*testdataDir, ingressYaml)))
170184
if err != nil {
171185
return err
172186
}
@@ -220,7 +234,7 @@ func validateIngressAddon(ctx context.Context, t *testing.T, profile string) {
220234
}
221235

222236
// check the ingress-dns addon here as well
223-
rr, err = Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "replace", "--force", "-f", filepath.Join(*testdataDir, "ingress-dns-example.yaml")))
237+
rr, err = Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "replace", "--force", "-f", filepath.Join(*testdataDir, ingressDNSYaml)))
224238
if err != nil {
225239
t.Errorf("failed to kubectl replace ingress-dns-example. args %q. %v", rr.Command(), err)
226240
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
//go:build integration
2+
// +build integration
3+
4+
/*
5+
Copyright 2021 The Kubernetes Authors All rights reserved.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
*/
19+
20+
package integration
21+
22+
import (
23+
"context"
24+
"os/exec"
25+
"testing"
26+
)
27+
28+
// TestIngressAddonLegacy tests ingress and ingress-dns addons with legacy k8s version <1.19
29+
func TestIngressAddonLegacy(t *testing.T) {
30+
if NoneDriver() {
31+
t.Skipf("skipping: none driver does not support ingress")
32+
}
33+
34+
profile := UniqueProfileName("ingress-addon-legacy")
35+
ctx, cancel := context.WithTimeout(context.Background(), Minutes(10))
36+
defer Cleanup(t, profile, cancel)
37+
38+
t.Run("StartLegacyK8sCluster", func(t *testing.T) {
39+
args := append([]string{"start", "-p", profile, "--kubernetes-version=v1.18.20", "--memory=4096", "--wait=true", "--alsologtostderr", "-v=5"}, StartArgs()...)
40+
rr, err := Run(t, exec.CommandContext(ctx, Target(), args...))
41+
if err != nil {
42+
t.Errorf("failed to start minikube with args: %q : %v", rr.Command(), err)
43+
}
44+
})
45+
46+
t.Run("serial", func(t *testing.T) {
47+
tests := []struct {
48+
name string
49+
validator validateFunc
50+
}{
51+
{"ValidateIngressAddonActivation", validateIngressAddonActivation},
52+
{"ValidateIngressDNSAddonActivation", validateIngressDNSAddonActivation},
53+
{"ValidateIngressAddons", validateIngressAddon},
54+
}
55+
for _, tc := range tests {
56+
tc := tc
57+
if ctx.Err() == context.DeadlineExceeded {
58+
t.Fatalf("Unable to run more tests (deadline exceeded)")
59+
}
60+
t.Run(tc.name, func(t *testing.T) {
61+
tc.validator(ctx, t, profile)
62+
})
63+
}
64+
})
65+
}
66+
67+
// validateIngressAddonActivation tests ingress addon activation
68+
func validateIngressAddonActivation(ctx context.Context, t *testing.T, profile string) {
69+
defer PostMortemLogs(t, profile)
70+
71+
if _, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "addons", "enable", "ingress", "--alsologtostderr", "-v=5")); err != nil {
72+
t.Errorf("failed to enable ingress addon: %v", err)
73+
}
74+
}
75+
76+
// validateIngressDNSAddonActivation tests ingress-dns addon activation
77+
func validateIngressDNSAddonActivation(ctx context.Context, t *testing.T, profile string) {
78+
defer PostMortemLogs(t, profile)
79+
80+
if _, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "addons", "enable", "ingress-dns", "--alsologtostderr", "-v=5")); err != nil {
81+
t.Errorf("failed to enable ingress-dns addon: %v", err)
82+
}
83+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Copyright 2021 The Kubernetes Authors All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
---
16+
apiVersion: apps/v1
17+
kind: Deployment
18+
metadata:
19+
name: hello-world-app
20+
namespace: default
21+
spec:
22+
selector:
23+
matchLabels:
24+
app: hello-world-app
25+
template:
26+
metadata:
27+
labels:
28+
app: hello-world-app
29+
spec:
30+
containers:
31+
- name: hello-world-app
32+
image: gcr.io/google-samples/hello-app:1.0
33+
ports:
34+
- containerPort: 8080
35+
---
36+
apiVersion: networking.k8s.io/v1beta1
37+
kind: Ingress
38+
metadata:
39+
name: example-ingress
40+
namespace: kube-system
41+
annotations:
42+
# needed for k8s < v1.18: https://kubernetes.io/blog/2020/04/02/improvements-to-the-ingress-api-in-kubernetes-1.18/#deprecating-the-ingress-class-annotation
43+
kubernetes.io/ingress.class: nginx
44+
spec:
45+
rules:
46+
- host: hello-john.test
47+
http:
48+
paths:
49+
- path: /
50+
pathType: Prefix
51+
backend:
52+
serviceName: hello-world-app
53+
servicePort: 80
54+
- host: hello-jane.test
55+
http:
56+
paths:
57+
- path: /
58+
pathType: Prefix
59+
backend:
60+
serviceName: hello-world-app
61+
servicePort: 80
62+
---
63+
apiVersion: v1
64+
kind: Service
65+
metadata:
66+
name: hello-world-app
67+
namespace: kube-system
68+
spec:
69+
type: ExternalName
70+
externalName: hello-world-app.default.svc.cluster.local
71+
---
72+
apiVersion: v1
73+
kind: Service
74+
metadata:
75+
name: hello-world-app
76+
namespace: default
77+
spec:
78+
ports:
79+
- name: http
80+
port: 80
81+
targetPort: 8080
82+
protocol: TCP
83+
type: NodePort
84+
selector:
85+
app: hello-world-app

‎test/integration/testdata/nginx-ingv1.yaml renamed to ‎test/integration/testdata/nginx-ingress-v1.yaml

-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ apiVersion: networking.k8s.io/v1
22
kind: Ingress
33
metadata:
44
name: nginx-ingress
5-
annotations:
6-
# use the shared ingress-nginx
7-
kubernetes.io/ingress.class: nginx
85
labels:
96
integration-test: ingress
107
spec:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: networking.k8s.io/v1beta1
2+
kind: Ingress
3+
metadata:
4+
name: nginx-ingress
5+
annotations:
6+
# needed for k8s < v1.18: https://kubernetes.io/blog/2020/04/02/improvements-to-the-ingress-api-in-kubernetes-1.18/#deprecating-the-ingress-class-annotation
7+
kubernetes.io/ingress.class: nginx
8+
labels:
9+
integration-test: ingress
10+
spec:
11+
rules:
12+
- host: nginx.example.com
13+
http:
14+
paths:
15+
- path: /
16+
pathType: Prefix
17+
backend:
18+
serviceName: nginx
19+
servicePort: 80

0 commit comments

Comments
 (0)
Please sign in to comment.