|
| 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 | +} |
0 commit comments