2021-09-13 18:58:43 +00:00
//go:build integration
2016-04-29 23:18:49 +00:00
/ *
2016-05-01 15:49:51 +00:00
Copyright 2016 The Kubernetes Authors All rights reserved .
2016-05-02 17:37:01 +00:00
2016-04-29 23:18:49 +00:00
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
2016-05-02 17:37:01 +00:00
2016-04-29 23:18:49 +00:00
http : //www.apache.org/licenses/LICENSE-2.0
2016-05-02 17:37:01 +00:00
2016-04-29 23:18:49 +00:00
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 .
* /
package integration
import (
2019-09-11 16:59:38 +00:00
"context"
2019-12-10 22:02:12 +00:00
"encoding/json"
2019-03-26 01:25:01 +00:00
"fmt"
2019-09-11 16:59:38 +00:00
"os/exec"
"path/filepath"
2019-12-10 22:02:12 +00:00
"sort"
2019-10-29 05:31:57 +00:00
"strconv"
2016-05-17 15:48:57 +00:00
"strings"
2016-04-29 23:18:49 +00:00
"testing"
2016-05-14 01:47:43 +00:00
2022-04-23 13:59:26 +00:00
"github.com/blang/semver/v4"
2017-02-22 03:27:51 +00:00
"github.com/docker/machine/libmachine/state"
2019-12-10 22:02:12 +00:00
"github.com/google/go-cmp/cmp"
"k8s.io/minikube/pkg/minikube/bootstrapper/images"
2019-03-26 01:25:01 +00:00
"k8s.io/minikube/pkg/minikube/constants"
2021-08-12 21:40:42 +00:00
"k8s.io/minikube/pkg/minikube/detect"
2022-04-23 13:59:26 +00:00
"k8s.io/minikube/pkg/util"
2016-04-29 23:18:49 +00:00
)
2021-04-16 20:42:41 +00:00
// TestStartStop tests starting, stopping and restarting a minikube clusters with various Kubernetes versions and configurations
// The oldest supported, newest supported and default Kubernetes versions are always tested.
2016-04-29 23:18:49 +00:00
func TestStartStop ( t * testing . T ) {
2019-09-11 16:59:38 +00:00
MaybeParallel ( t )
2019-08-01 05:50:04 +00:00
2021-01-21 20:02:28 +00:00
t . Run ( "group" , func ( t * testing . T ) {
tests := [ ] struct {
name string
version string
args [ ] string
} {
2020-04-17 18:58:09 +00:00
{ "old-k8s-version" , constants . OldestKubernetesVersion , [ ] string {
2019-07-30 23:36:53 +00:00
// default is the network created by libvirt, if we change the name minikube won't boot
// because the given network doesn't exist
"--kvm-network=default" ,
"--kvm-qemu-uri=qemu:///system" ,
2019-09-11 16:59:38 +00:00
"--disable-driver-mounts" ,
"--keep-context=false" ,
2019-07-30 23:36:53 +00:00
} } ,
2019-12-10 22:02:12 +00:00
{ "newest-cni" , constants . NewestKubernetesVersion , [ ] string {
2019-07-30 23:36:53 +00:00
"--feature-gates" ,
"ServerSideApply=true" ,
"--network-plugin=cni" ,
2022-12-14 23:38:45 +00:00
"--extra-config=kubeadm.pod-network-cidr=10.42.0.0/16" ,
2019-07-30 23:36:53 +00:00
} } ,
2022-10-04 19:05:48 +00:00
{ "default-k8s-diff-port" , constants . DefaultKubernetesVersion , [ ] string {
2021-01-22 19:40:25 +00:00
"--apiserver-port=8444" ,
} } ,
2021-01-22 21:08:18 +00:00
{ "no-preload" , constants . NewestKubernetesVersion , [ ] string {
2021-01-22 20:03:17 +00:00
"--preload=false" ,
} } ,
{ "disable-driver-mounts" , constants . DefaultKubernetesVersion , [ ] string {
2019-08-09 00:12:33 +00:00
"--disable-driver-mounts" ,
2019-08-09 13:35:39 +00:00
"--extra-config=kubeadm.ignore-preflight-errors=SystemVerification" ,
2019-07-30 23:36:53 +00:00
} } ,
2021-01-21 20:02:28 +00:00
{ "embed-certs" , constants . DefaultKubernetesVersion , [ ] string {
"--embed-certs" ,
} } ,
}
2021-08-12 21:40:42 +00:00
if detect . IsCloudShell ( ) {
tests = [ ] struct {
name string
version string
args [ ] string
} {
2021-08-20 22:34:53 +00:00
{ "cloud-shell" , constants . DefaultKubernetesVersion , [ ] string { } } ,
2021-08-12 21:40:42 +00:00
}
}
2021-01-21 20:02:28 +00:00
for _ , tc := range tests {
tc := tc
t . Run ( tc . name , func ( t * testing . T ) {
MaybeParallel ( t )
profile := UniqueProfileName ( tc . name )
2021-02-16 18:24:43 +00:00
ctx , cancel := context . WithTimeout ( context . Background ( ) , Minutes ( 30 ) )
2021-01-21 20:02:28 +00:00
defer Cleanup ( t , profile , cancel )
type validateStartStopFunc func ( context . Context , * testing . T , string , string , string , [ ] string )
if ! strings . Contains ( tc . name , "docker" ) && NoneDriver ( ) {
t . Skipf ( "skipping %s - incompatible with none driver" , t . Name ( ) )
}
2021-01-26 21:10:18 +00:00
if strings . Contains ( tc . name , "disable-driver-mounts" ) && ! VirtualboxDriver ( ) {
2021-01-21 22:40:08 +00:00
t . Skipf ( "skipping %s - only runs on virtualbox" , t . Name ( ) )
}
2021-01-21 20:02:28 +00:00
waitFlag := "--wait=true"
if strings . Contains ( tc . name , "cni" ) { // wait=app_running is broken for CNI https://github.com/kubernetes/minikube/issues/7354
waitFlag = "--wait=apiserver,system_pods,default_sa"
}
startArgs := append ( [ ] string { "start" , "-p" , profile , "--memory=2200" , "--alsologtostderr" , waitFlag } , tc . args ... )
startArgs = append ( startArgs , StartArgs ( ) ... )
startArgs = append ( startArgs , fmt . Sprintf ( "--kubernetes-version=%s" , tc . version ) )
2022-04-23 13:59:26 +00:00
version , err := util . ParseKubernetesVersion ( tc . version )
if err != nil {
t . Errorf ( "failed to parse %s: %v" , tc . version , err )
}
if version . GTE ( semver . MustParse ( "1.24.0-alpha.2" ) ) {
args := [ ] string { }
2022-05-19 16:44:22 +00:00
for _ , arg := range startArgs {
2022-04-23 13:59:26 +00:00
if arg == "--extra-config=kubelet.network-plugin=cni" {
continue
}
args = append ( args , arg )
}
startArgs = args
}
2021-01-21 20:02:28 +00:00
t . Run ( "serial" , func ( t * testing . T ) {
serialTests := [ ] struct {
name string
validator validateStartStopFunc
} {
{ "FirstStart" , validateFirstStart } ,
{ "DeployApp" , validateDeploying } ,
2021-05-17 18:43:53 +00:00
{ "EnableAddonWhileActive" , validateEnableAddonWhileActive } ,
2021-01-21 20:02:28 +00:00
{ "Stop" , validateStop } ,
{ "EnableAddonAfterStop" , validateEnableAddonAfterStop } ,
{ "SecondStart" , validateSecondStart } ,
{ "UserAppExistsAfterStop" , validateAppExistsAfterStop } ,
{ "AddonExistsAfterStop" , validateAddonAfterStop } ,
{ "VerifyKubernetesImages" , validateKubernetesImages } ,
{ "Pause" , validatePauseAfterStart } ,
2021-01-21 00:23:19 +00:00
}
2021-01-21 20:02:28 +00:00
for _ , stc := range serialTests {
if ctx . Err ( ) == context . DeadlineExceeded {
t . Fatalf ( "Unable to run more tests (deadline exceeded)" )
}
tcName := tc . name
tcVersion := tc . version
stc := stc
2020-08-22 17:21:40 +00:00
2021-01-21 20:02:28 +00:00
t . Run ( stc . name , func ( t * testing . T ) {
stc . validator ( ctx , t , profile , tcName , tcVersion , startArgs )
} )
2020-05-06 22:47:47 +00:00
}
2019-09-11 16:59:38 +00:00
2021-01-21 20:02:28 +00:00
if * cleanup {
// Normally handled by cleanuprofile, but not fatal there
rr , err := Run ( t , exec . CommandContext ( ctx , Target ( ) , "delete" , "-p" , profile ) )
if err != nil {
t . Errorf ( "failed to clean up: args %q: %v" , rr . Command ( ) , err )
2020-05-06 22:47:47 +00:00
}
2021-01-21 00:23:19 +00:00
2021-01-21 20:02:28 +00:00
rr , err = Run ( t , exec . CommandContext ( ctx , "kubectl" , "config" , "get-contexts" , profile ) )
if err != nil {
t . Logf ( "config context error: %v (may be ok)" , err )
2020-05-06 22:47:47 +00:00
}
2021-01-21 20:02:28 +00:00
if rr . ExitCode != 1 {
t . Errorf ( "expected exit code 1, got %d. output: %s" , rr . ExitCode , rr . Output ( ) )
}
}
2019-09-11 16:59:38 +00:00
2020-05-06 22:47:47 +00:00
} )
2020-05-12 01:51:01 +00:00
2021-01-21 20:02:28 +00:00
} )
}
} )
2020-05-06 22:47:47 +00:00
}
2020-02-03 18:50:06 +00:00
2021-04-16 20:42:41 +00:00
// validateFirstStart runs the initial minikube start
2023-03-20 19:43:07 +00:00
func validateFirstStart ( ctx context . Context , t * testing . T , profile , _ , _ string , startArgs [ ] string ) {
2020-05-12 01:51:01 +00:00
defer PostMortemLogs ( t , profile )
2020-05-06 22:47:47 +00:00
rr , err := Run ( t , exec . CommandContext ( ctx , Target ( ) , startArgs ... ) )
if err != nil {
t . Fatalf ( "failed starting minikube -first start-. args %q: %v" , rr . Command ( ) , err )
}
}
2019-09-11 16:59:38 +00:00
2021-04-16 20:42:41 +00:00
// validateDeploying deploys an app the minikube cluster
2023-03-20 19:43:07 +00:00
func validateDeploying ( ctx context . Context , t * testing . T , profile , tcName , _ string , _ [ ] string ) {
2020-05-12 01:51:01 +00:00
defer PostMortemLogs ( t , profile )
2020-05-07 00:33:30 +00:00
if ! strings . Contains ( tcName , "cni" ) {
testPodScheduling ( ctx , t , profile )
}
2020-05-06 22:47:47 +00:00
}
2021-05-18 17:27:53 +00:00
// validateEnableAddonWhileActive makes sure addons can be enabled while cluster is active.
2023-03-20 19:43:07 +00:00
func validateEnableAddonWhileActive ( ctx context . Context , t * testing . T , profile , tcName , _ string , _ [ ] string ) {
2021-05-17 18:43:53 +00:00
defer PostMortemLogs ( t , profile )
// Enable an addon to assert it requests the correct image.
2023-03-30 16:45:52 +00:00
rr , err := Run ( t , exec . CommandContext ( ctx , Target ( ) , "addons" , "enable" , "metrics-server" , "-p" , profile , "--images=MetricsServer=registry.k8s.io/echoserver:1.4" , "--registries=MetricsServer=fake.domain" ) )
2021-05-17 18:43:53 +00:00
if err != nil {
t . Errorf ( "failed to enable an addon post-stop. args %q: %v" , rr . Command ( ) , err )
}
if strings . Contains ( tcName , "cni" ) {
t . Logf ( "WARNING: cni mode requires additional setup before pods can schedule :(" )
return
}
rr , err = Run ( t , exec . CommandContext ( ctx , "kubectl" , "--context" , profile , "describe" , "deploy/metrics-server" , "-n" , "kube-system" ) )
if err != nil {
t . Errorf ( "failed to get info on auto-pause deployments. args %q: %v" , rr . Command ( ) , err )
}
deploymentInfo := rr . Stdout . String ( )
2023-03-30 16:45:52 +00:00
if ! strings . Contains ( deploymentInfo , " fake.domain/registry.k8s.io/echoserver:1.4" ) {
t . Errorf ( "addon did not load correct image. Expected to contain \" fake.domain/registry.k8s.io/echoserver:1.4\". Addon deployment info: %s" , deploymentInfo )
2021-05-17 18:43:53 +00:00
}
}
2021-04-16 20:42:41 +00:00
// validateStop tests minikube stop
2023-03-20 19:43:07 +00:00
func validateStop ( ctx context . Context , t * testing . T , profile , _ , _ string , _ [ ] string ) {
2020-05-12 01:51:01 +00:00
defer PostMortemLogs ( t , profile )
2020-05-06 22:47:47 +00:00
rr , err := Run ( t , exec . CommandContext ( ctx , Target ( ) , "stop" , "-p" , profile , "--alsologtostderr" , "-v=3" ) )
if err != nil {
2020-05-12 01:51:01 +00:00
t . Fatalf ( "failed stopping minikube - first stop-. args %q : %v" , rr . Command ( ) , err )
2020-05-06 22:47:47 +00:00
}
}
2019-07-30 20:20:44 +00:00
2021-04-16 20:42:41 +00:00
// validateEnableAddonAfterStop makes sure addons can be enabled on a stopped cluster
2023-03-20 19:43:07 +00:00
func validateEnableAddonAfterStop ( ctx context . Context , t * testing . T , profile , _ , _ string , _ [ ] string ) {
2020-05-12 01:51:01 +00:00
defer PostMortemLogs ( t , profile )
2020-05-06 22:47:47 +00:00
// The none driver never really stops
if ! NoneDriver ( ) {
2020-05-21 21:44:47 +00:00
got := Status ( ctx , t , Target ( ) , profile , "Host" , profile )
2020-05-06 22:47:47 +00:00
if got != state . Stopped . String ( ) {
t . Errorf ( "expected post-stop host status to be -%q- but got *%q*" , state . Stopped , got )
}
}
2020-01-22 23:50:09 +00:00
2020-05-06 22:47:47 +00:00
// Enable an addon to assert it comes up afterwards
2023-03-30 16:45:52 +00:00
rr , err := Run ( t , exec . CommandContext ( ctx , Target ( ) , "addons" , "enable" , "dashboard" , "-p" , profile , "--images=MetricsScraper=registry.k8s.io/echoserver:1.4" ) )
2020-05-06 22:47:47 +00:00
if err != nil {
t . Errorf ( "failed to enable an addon post-stop. args %q: %v" , rr . Command ( ) , err )
}
2019-07-30 20:20:44 +00:00
2020-05-06 22:47:47 +00:00
}
2020-02-07 07:08:59 +00:00
2021-04-16 20:42:41 +00:00
// validateSecondStart verifies that starting a stopped cluster works
2023-03-20 19:43:07 +00:00
func validateSecondStart ( ctx context . Context , t * testing . T , profile , _ , _ string , startArgs [ ] string ) {
2020-05-12 01:51:01 +00:00
defer PostMortemLogs ( t , profile )
2020-05-06 22:47:47 +00:00
rr , err := Run ( t , exec . CommandContext ( ctx , Target ( ) , startArgs ... ) )
if err != nil {
// Explicit fatal so that failures don't move directly to deletion
t . Fatalf ( "failed to start minikube post-stop. args %q: %v" , rr . Command ( ) , err )
}
2020-05-21 21:44:47 +00:00
got := Status ( ctx , t , Target ( ) , profile , "Host" , profile )
2020-05-06 22:47:47 +00:00
if got != state . Running . String ( ) {
t . Errorf ( "expected host status after start-stop-start to be -%q- but got *%q*" , state . Running , got )
}
}
2020-05-06 23:03:30 +00:00
// validateAppExistsAfterStop verifies that a user's app will not vanish after a minikube stop
2023-03-20 19:43:07 +00:00
func validateAppExistsAfterStop ( ctx context . Context , t * testing . T , profile , tcName , _ string , _ [ ] string ) {
2020-05-12 01:51:01 +00:00
defer PostMortemLogs ( t , profile )
2020-05-06 22:47:47 +00:00
if strings . Contains ( tcName , "cni" ) {
t . Logf ( "WARNING: cni mode requires additional setup before pods can schedule :(" )
2020-05-06 23:10:03 +00:00
} else if _ , err := PodWait ( ctx , t , profile , "kubernetes-dashboard" , "k8s-app=kubernetes-dashboard" , Minutes ( 9 ) ) ; err != nil {
2020-05-12 01:51:01 +00:00
t . Errorf ( "failed waiting for 'addon dashboard' pod post-stop-start: %v" , err )
2020-05-06 23:03:30 +00:00
}
2020-05-06 23:10:03 +00:00
2020-05-06 23:03:30 +00:00
}
// validateAddonAfterStop validates that an addon which was enabled when minikube is stopped will be enabled and working..
2023-03-20 19:43:07 +00:00
func validateAddonAfterStop ( ctx context . Context , t * testing . T , profile , tcName , _ string , _ [ ] string ) {
2020-05-12 01:51:01 +00:00
defer PostMortemLogs ( t , profile )
2020-05-06 23:03:30 +00:00
if strings . Contains ( tcName , "cni" ) {
t . Logf ( "WARNING: cni mode requires additional setup before pods can schedule :(" )
2021-05-17 18:43:53 +00:00
return
}
if _ , err := PodWait ( ctx , t , profile , "kubernetes-dashboard" , "k8s-app=kubernetes-dashboard" , Minutes ( 9 ) ) ; err != nil {
2020-05-12 01:51:01 +00:00
t . Errorf ( "failed waiting for 'addon dashboard' pod post-stop-start: %v" , err )
2020-05-06 22:47:47 +00:00
}
2021-05-17 18:43:53 +00:00
rr , err := Run ( t , exec . CommandContext ( ctx , "kubectl" , "--context" , profile , "describe" , "deploy/dashboard-metrics-scraper" , "-n" , "kubernetes-dashboard" ) )
if err != nil {
t . Errorf ( "failed to get info on kubernetes-dashboard deployments. args %q: %v" , rr . Command ( ) , err )
}
deploymentInfo := rr . Stdout . String ( )
2023-03-30 16:45:52 +00:00
if ! strings . Contains ( deploymentInfo , " registry.k8s.io/echoserver:1.4" ) {
t . Errorf ( "addon did not load correct image. Expected to contain \" registry.k8s.io/echoserver:1.4\". Addon deployment info: %s" , deploymentInfo )
2021-05-17 18:43:53 +00:00
}
2020-05-06 22:47:47 +00:00
}
2021-04-16 20:42:41 +00:00
// validateKubernetesImages verifies that a restarted cluster contains all the necessary images
2023-03-20 19:43:07 +00:00
func validateKubernetesImages ( ctx context . Context , t * testing . T , profile , _ , tcVersion string , _ [ ] string ) {
2020-05-06 22:47:47 +00:00
if ! NoneDriver ( ) {
testPulledImages ( ctx , t , profile , tcVersion )
}
}
2021-04-16 20:42:41 +00:00
// validatePauseAfterStart verifies that minikube pause works
2023-03-20 19:43:07 +00:00
func validatePauseAfterStart ( ctx context . Context , t * testing . T , profile , _ , _ string , _ [ ] string ) {
2020-05-12 01:51:01 +00:00
defer PostMortemLogs ( t , profile )
2020-05-06 22:47:47 +00:00
testPause ( ctx , t , profile )
2016-04-29 23:18:49 +00:00
}
2019-12-19 20:54:05 +00:00
2020-01-23 00:39:26 +00:00
// testPodScheduling asserts that this configuration can schedule new pods
func testPodScheduling ( ctx context . Context , t * testing . T , profile string ) {
2020-05-08 20:12:30 +00:00
defer PostMortemLogs ( t , profile )
2020-01-23 00:39:26 +00:00
t . Helper ( )
// schedule a pod to assert persistence
rr , err := Run ( t , exec . CommandContext ( ctx , "kubectl" , "--context" , profile , "create" , "-f" , filepath . Join ( * testdataDir , "busybox.yaml" ) ) )
if err != nil {
2020-03-26 05:21:19 +00:00
t . Fatalf ( "%s failed: %v" , rr . Command ( ) , err )
2020-01-23 00:39:26 +00:00
}
// 8 minutes, because 4 is not enough for images to pull in all cases.
2020-02-21 00:40:18 +00:00
names , err := PodWait ( ctx , t , profile , "default" , "integration-test=busybox" , Minutes ( 8 ) )
2020-01-23 00:39:26 +00:00
if err != nil {
t . Fatalf ( "wait: %v" , err )
}
// Use this pod to confirm that the runtime resource limits are sane
rr , err = Run ( t , exec . CommandContext ( ctx , "kubectl" , "--context" , profile , "exec" , names [ 0 ] , "--" , "/bin/sh" , "-c" , "ulimit -n" ) )
if err != nil {
t . Fatalf ( "ulimit: %v" , err )
}
got , err := strconv . ParseInt ( strings . TrimSpace ( rr . Stdout . String ( ) ) , 10 , 64 )
if err != nil {
t . Errorf ( "ParseInt(%q): %v" , rr . Stdout . String ( ) , err )
}
// Arbitrary value set by some container runtimes. If higher, apps like MySQL may make bad decisions.
expected := int64 ( 1048576 )
if got != expected {
t . Errorf ( "'ulimit -n' returned %d, expected %d" , got , expected )
}
}
// testPulledImages asserts that this configuration pulls only expected images
2023-03-20 19:43:07 +00:00
func testPulledImages ( ctx context . Context , t * testing . T , profile , version string ) {
2020-01-23 00:39:26 +00:00
t . Helper ( )
2020-05-08 20:12:30 +00:00
defer PostMortemLogs ( t , profile )
2020-01-23 00:39:26 +00:00
rr , err := Run ( t , exec . CommandContext ( ctx , Target ( ) , "ssh" , "-p" , profile , "sudo crictl images -o json" ) )
if err != nil {
2023-03-29 16:58:47 +00:00
t . Errorf ( "failed to get images inside minikube. args %q: %v" , rr . Command ( ) , err )
2020-01-23 00:39:26 +00:00
}
jv := map [ string ] [ ] struct {
Tags [ ] string ` json:"repoTags" `
} { }
2021-01-21 21:44:02 +00:00
stdout := rr . Stdout . String ( )
err = json . Unmarshal ( [ ] byte ( stdout ) , & jv )
2020-01-23 00:39:26 +00:00
if err != nil {
2021-01-21 21:44:02 +00:00
t . Errorf ( "failed to decode images json %v. output:\n%s" , err , stdout )
2020-01-23 00:39:26 +00:00
}
2020-03-21 17:47:08 +00:00
found := map [ string ] bool { }
2020-01-23 00:39:26 +00:00
for _ , img := range jv [ "images" ] {
for _ , i := range img . Tags {
2020-11-10 22:33:59 +00:00
i = trimImageName ( i )
2020-01-23 00:39:26 +00:00
if defaultImage ( i ) {
2020-03-21 17:47:08 +00:00
found [ i ] = true
2020-01-23 00:39:26 +00:00
} else {
t . Logf ( "Found non-minikube image: %s" , i )
}
}
}
2023-03-29 16:58:47 +00:00
mirror := ""
// Kubernetes versions prior to v1.25 will contain the old registry due to the preload
2023-03-29 17:02:46 +00:00
if v , _ := util . ParseKubernetesVersion ( version ) ; v . LT ( semver . MustParse ( "1.25.0-alpha.1" ) ) {
2023-03-29 16:58:47 +00:00
mirror = "k8s.gcr.io"
}
wantRaw , err := images . Kubeadm ( mirror , version )
2020-01-23 00:39:26 +00:00
if err != nil {
2020-03-26 05:10:32 +00:00
t . Errorf ( "failed to get kubeadm images for %s : %v" , version , err )
2020-01-23 00:39:26 +00:00
}
2020-11-10 21:21:11 +00:00
// we need to trim the want raw, because if runtime is docker it will not report the full name with docker.io as prefix
want := [ ] string { }
2020-11-10 22:33:59 +00:00
for _ , i := range wantRaw {
want = append ( want , trimImageName ( i ) )
2020-11-10 21:21:11 +00:00
}
2020-03-21 17:47:08 +00:00
gotImages := [ ] string { }
for k := range found {
gotImages = append ( gotImages , k )
}
2020-01-23 00:39:26 +00:00
sort . Strings ( want )
sort . Strings ( gotImages )
2020-11-25 21:23:30 +00:00
// check if we got all the images we want, ignoring any extraneous ones in cache (eg, may be created by other tests)
missing := false
for _ , img := range want {
if sort . SearchStrings ( gotImages , img ) == len ( gotImages ) {
missing = true
break
}
}
if missing {
t . Errorf ( "%s images missing (-want +got):\n%s" , version , cmp . Diff ( want , gotImages ) )
2020-01-23 00:39:26 +00:00
}
}
// testPause asserts that this configuration can be paused and unpaused
func testPause ( ctx context . Context , t * testing . T , profile string ) {
t . Helper ( )
2020-05-08 20:12:30 +00:00
defer PostMortemLogs ( t , profile )
2020-01-23 00:39:26 +00:00
rr , err := Run ( t , exec . CommandContext ( ctx , Target ( ) , "pause" , "-p" , profile , "--alsologtostderr" , "-v=1" ) )
if err != nil {
2020-03-26 05:21:19 +00:00
t . Fatalf ( "%s failed: %v" , rr . Command ( ) , err )
2020-01-23 00:39:26 +00:00
}
2020-05-21 21:44:47 +00:00
got := Status ( ctx , t , Target ( ) , profile , "APIServer" , profile )
2020-01-23 00:39:26 +00:00
if got != state . Paused . String ( ) {
2020-02-03 18:50:06 +00:00
t . Errorf ( "post-pause apiserver status = %q; want = %q" , got , state . Paused )
2020-01-23 00:39:26 +00:00
}
2020-05-21 21:44:47 +00:00
got = Status ( ctx , t , Target ( ) , profile , "Kubelet" , profile )
2020-01-23 00:39:26 +00:00
if got != state . Stopped . String ( ) {
2020-02-03 18:50:06 +00:00
t . Errorf ( "post-pause kubelet status = %q; want = %q" , got , state . Stopped )
2020-01-23 00:39:26 +00:00
}
rr , err = Run ( t , exec . CommandContext ( ctx , Target ( ) , "unpause" , "-p" , profile , "--alsologtostderr" , "-v=1" ) )
if err != nil {
2020-03-26 05:21:19 +00:00
t . Fatalf ( "%s failed: %v" , rr . Command ( ) , err )
2020-01-23 00:39:26 +00:00
}
2020-05-21 21:44:47 +00:00
got = Status ( ctx , t , Target ( ) , profile , "APIServer" , profile )
2020-01-23 00:39:26 +00:00
if got != state . Running . String ( ) {
2020-02-03 18:50:06 +00:00
t . Errorf ( "post-unpause apiserver status = %q; want = %q" , got , state . Running )
2020-01-23 00:39:26 +00:00
}
2020-05-21 21:44:47 +00:00
got = Status ( ctx , t , Target ( ) , profile , "Kubelet" , profile )
2020-01-23 00:39:26 +00:00
if got != state . Running . String ( ) {
2020-02-03 18:50:06 +00:00
t . Errorf ( "post-unpause kubelet status = %q; want = %q" , got , state . Running )
2020-01-23 00:39:26 +00:00
}
}
2020-11-10 21:21:11 +00:00
// Remove container-specific prefixes for naming consistency
// for example in `docker` runtime we get this:
2022-08-08 16:29:19 +00:00
//
// $ docker@minikube:~$ sudo crictl images -o json | grep dash
// "kubernetesui/dashboard:vX.X.X"
//
2020-11-10 21:21:11 +00:00
// but for 'containerd' we get full name
2022-08-08 16:29:19 +00:00
//
// $ docker@minikube:~$ sudo crictl images -o json | grep dash
// "docker.io/kubernetesui/dashboard:vX.X.X"
2020-11-10 22:33:59 +00:00
func trimImageName ( name string ) string {
2020-11-10 21:21:11 +00:00
name = strings . TrimPrefix ( name , "docker.io/" )
name = strings . TrimPrefix ( name , "localhost/" )
return name
}
2019-12-19 20:54:05 +00:00
// defaultImage returns true if this image is expected in a default minikube install
2019-12-19 21:03:43 +00:00
func defaultImage ( name string ) bool {
2019-12-19 20:54:05 +00:00
if strings . Contains ( name , ":latest" ) {
return false
}
2022-08-31 21:16:51 +00:00
if strings . Contains ( name , "k8s.gcr.io" ) || strings . Contains ( name , "registry.k8s.io" ) || strings . Contains ( name , "kubernetesui" ) || strings . Contains ( name , "storage-provisioner" ) {
2019-12-19 20:54:05 +00:00
return true
}
2019-12-19 21:03:43 +00:00
return false
2019-12-19 20:54:05 +00:00
}