github.com/terraform-modules-krish/terratest@v0.29.0/modules/k8s/minikube.go (about) 1 package k8s 2 3 import ( 4 "strings" 5 6 "github.com/terraform-modules-krish/terratest/modules/testing" 7 corev1 "k8s.io/api/core/v1" 8 ) 9 10 // IsMinikubeE returns true if the underlying kubernetes cluster is Minikube. This is determined by getting the 11 // associated nodes and checking if all nodes has at least one label namespaced with "minikube.k8s.io". 12 func IsMinikubeE(t testing.TestingT, options *KubectlOptions) (bool, error) { 13 nodes, err := GetNodesE(t, options) 14 if err != nil { 15 return false, err 16 } 17 18 // ASSUMPTION: All minikube setups will have nodes with labels that are namespaced with minikube.k8s.io 19 for _, node := range nodes { 20 if !nodeHasMinikubeLabel(node) { 21 return false, nil 22 } 23 } 24 25 // At this point we know that all the nodes in the cluster has the minikube label, so we return true. 26 return true, nil 27 } 28 29 // nodeHasMinikubeLabel returns true if any of the labels on the node is namespaced with minikube.k8s.io 30 func nodeHasMinikubeLabel(node corev1.Node) bool { 31 labels := node.GetLabels() 32 for key, _ := range labels { 33 if strings.HasPrefix(key, "minikube.k8s.io") { 34 return true 35 } 36 } 37 return false 38 }