Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: allow running functional tests for different k8s versions #18564

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pkg/minikube/tunnel/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ func (r *persistentRegistry) Register(tunnel *ID) (rerr error) {

alreadyExists := false
for i, t := range tunnels {
if t.Route.Equal(tunnel.Route) {
// It is allowed for multiple minikube clusters to have multiple
// tunnels simultaneously. It is possible that an old tunnel
// from an old profile has duplicated route information so we
// need to check both machine name and route information.
if tunnel.MachineName == t.MachineName && t.Route.Equal(tunnel.Route) {
ComradeProgrammer marked this conversation as resolved.
Show resolved Hide resolved
isRunning, err := checkIfRunning(t.Pid)
if err != nil {
return fmt.Errorf("error checking whether conflicting tunnel (%v) is running: %s", t, err)
Expand Down
4 changes: 4 additions & 0 deletions site/content/en/docs/contrib/tests.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ asserts that there are no unexpected errors displayed in minikube command output
## TestFunctional
are functionality tests which can safely share a profile in parallel

## TestFunctionalNewestKubernetes
are functionality run functional tests using
NewestKubernetesVersion

#### validateNodeLabels
checks if minikube cluster is created with correct kubernetes's node label

Expand Down
29 changes: 23 additions & 6 deletions test/integration/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (

"k8s.io/minikube/pkg/drivers/kic/oci"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/detect"
"k8s.io/minikube/pkg/minikube/localpath"
"k8s.io/minikube/pkg/minikube/reason"
Expand Down Expand Up @@ -72,9 +73,26 @@ var runCorpProxy = detect.GithubActionRunner() && runtime.GOOS == "linux" && !ar

// TestFunctional are functionality tests which can safely share a profile in parallel
func TestFunctional(t *testing.T) {
testFunctional(t, "")
}

// TestFunctionalNewestKubernetes are functionality run functional tests using
// NewestKubernetesVersion
func TestFunctionalNewestKubernetes(t *testing.T) {
ComradeProgrammer marked this conversation as resolved.
Show resolved Hide resolved
if strings.Contains(*startArgs, "--kubernetes-version") || constants.NewestKubernetesVersion == constants.DefaultKubernetesVersion {
t.Skip()
}
k8sVersionString := constants.NewestKubernetesVersion
t.Run("Version"+k8sVersionString, func(t *testing.T) {
testFunctional(t, k8sVersionString)
})

}

func testFunctional(t *testing.T, k8sVersion string) {
profile := UniqueProfileName("functional")
ctx, cancel := context.WithTimeout(context.Background(), Minutes(40))
ctx := context.WithValue(context.Background(), ContextKey("k8sVersion"), k8sVersion)
ctx, cancel := context.WithTimeout(ctx, Minutes(40))
defer func() {
if !*cleanup {
return
Expand All @@ -86,7 +104,6 @@ func TestFunctional(t *testing.T) {

Cleanup(t, profile, cancel)
}()

// Serial tests
t.Run("serial", func(t *testing.T) {
tests := []struct {
Expand Down Expand Up @@ -965,7 +982,7 @@ func validateDryRun(ctx context.Context, t *testing.T, profile string) {

// docs: Run `minikube start --dry-run --memory 250MB`
// Too little memory!
startArgs := append([]string{"start", "-p", profile, "--dry-run", "--memory", "250MB", "--alsologtostderr"}, StartArgs()...)
startArgs := append([]string{"start", "-p", profile, "--dry-run", "--memory", "250MB", "--alsologtostderr"}, StartArgsWithContext(ctx)...)
c := exec.CommandContext(mctx, Target(), startArgs...)
rr, err := Run(t, c)

Expand All @@ -982,7 +999,7 @@ func validateDryRun(ctx context.Context, t *testing.T, profile string) {
dctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
// docs: Run `minikube start --dry-run`
startArgs = append([]string{"start", "-p", profile, "--dry-run", "--alsologtostderr", "-v=1"}, StartArgs()...)
startArgs = append([]string{"start", "-p", profile, "--dry-run", "--alsologtostderr", "-v=1"}, StartArgsWithContext(ctx)...)
c = exec.CommandContext(dctx, Target(), startArgs...)
rr, err = Run(t, c)
// docs: Make sure the command doesn't raise any error
Expand All @@ -1007,7 +1024,7 @@ func validateInternationalLanguage(ctx context.Context, t *testing.T, profile st
defer cancel()

// Too little memory!
startArgs := append([]string{"start", "-p", profile, "--dry-run", "--memory", "250MB", "--alsologtostderr"}, StartArgs()...)
startArgs := append([]string{"start", "-p", profile, "--dry-run", "--memory", "250MB", "--alsologtostderr"}, StartArgsWithContext(ctx)...)
c := exec.CommandContext(mctx, Target(), startArgs...)
// docs: Set environment variable `LC_ALL=fr` to enable minikube translation to French
c.Env = append(os.Environ(), "LC_ALL=fr")
Expand Down Expand Up @@ -2221,7 +2238,7 @@ func startMinikubeWithProxy(ctx context.Context, t *testing.T, profile string, p
memoryFlag = "--memory=6000"
}
// passing --api-server-port so later verify it didn't change in soft start.
startArgs := append([]string{"start", "-p", profile, memoryFlag, fmt.Sprintf("--apiserver-port=%d", apiPortTest), "--wait=all"}, StartArgs()...)
startArgs := append([]string{"start", "-p", profile, memoryFlag, fmt.Sprintf("--apiserver-port=%d", apiPortTest), "--wait=all"}, StartArgsWithContext(ctx)...)
c := exec.CommandContext(ctx, Target(), startArgs...)
env := os.Environ()
env = append(env, fmt.Sprintf("%s=%s", proxyEnv, addr))
Expand Down
5 changes: 5 additions & 0 deletions test/integration/functional_test_tunnel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,4 +432,9 @@ func validateTunnelDelete(_ context.Context, t *testing.T, _ string) {
checkRoutePassword(t)
// Stop tunnel
tunnelSession.Stop(t)
// prevent the child process from becoming a defunct zombie process
if err := tunnelSession.cmd.Wait(); err != nil {
t.Logf("failed to stop process: %v", err)
return
}
}
11 changes: 11 additions & 0 deletions test/integration/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ func StartArgs() []string {
return strings.Split(*startArgs, " ")
}

type ContextKey string

func StartArgsWithContext(ctx context.Context) []string {
res := strings.Split(*startArgs, " ")
value := ctx.Value(ContextKey("k8sVersion"))
if value != nil && value != "" {
res = append(res, fmt.Sprintf("--kubernetes-version=%s", value))
}
return res
}

// Target returns where the minikube binary can be found
func Target() string {
return *binaryPath
Expand Down
Loading