...
 
Commits (11)
......@@ -28,8 +28,10 @@ import (
"github.com/golang/glog"
"github.com/pkg/errors"
"github.com/spf13/viper"
"k8s.io/minikube/pkg/drivers/kic/oci"
"k8s.io/minikube/pkg/kapi"
"k8s.io/minikube/pkg/minikube/assets"
"k8s.io/minikube/pkg/minikube/command"
"k8s.io/minikube/pkg/minikube/config"
......@@ -311,6 +313,30 @@ func enableOrDisableStorageClasses(cc *config.ClusterConfig, name string, val st
return enableOrDisableAddon(cc, name, val)
}
func verifyAddonStatus(cc *config.ClusterConfig, name string, val string) error {
glog.Infof("Verifying addon %s=%s in %q", name, val, cc.Name)
enable, err := strconv.ParseBool(val)
if err != nil {
return errors.Wrapf(err, "parsing bool: %s", name)
}
label, ok := addonPodLabels[name]
if ok && enable {
out.T(out.HealthCheck, "Verifying {{.addon_name}} addon...", out.V{"addon_name": name})
client, err := kapi.Client(viper.GetString(config.ProfileName))
if err != nil {
return errors.Wrapf(err, "get kube-client to validate %s addon: %v", name, err)
}
err = kapi.WaitForPods(client, "kube-system", label, time.Minute*3)
if err != nil {
return errors.Wrapf(err, "verifying %s addon pods : %v", name, err)
}
}
return nil
}
// Start enables the default addons for a profile, plus any additional
func Start(wg *sync.WaitGroup, cc *config.ClusterConfig, toEnable map[string]bool, additional []string) {
wg.Add(1)
......
......@@ -28,6 +28,13 @@ type Addon struct {
callbacks []setFn
}
// addonPodLabels holds the pod label that will be used to verify if the addon is enabled
var addonPodLabels = map[string]string{
"ingress": "app.kubernetes.io/name=ingress-nginx",
"registry": "kubernetes.io/minikube-addons=registry",
"gvisor": "kubernetes.io/minikube-addons=gvisor",
}
// Addons is a list of all addons
var Addons = []*Addon{
{
......@@ -55,7 +62,7 @@ var Addons = []*Addon{
name: "gvisor",
set: SetBool,
validations: []setFn{IsRuntimeContainerd},
callbacks: []setFn{enableOrDisableAddon},
callbacks: []setFn{enableOrDisableAddon, verifyAddonStatus},
},
{
name: "helm-tiller",
......@@ -65,7 +72,7 @@ var Addons = []*Addon{
{
name: "ingress",
set: SetBool,
callbacks: []setFn{enableOrDisableAddon},
callbacks: []setFn{enableOrDisableAddon, verifyAddonStatus},
},
{
name: "ingress-dns",
......@@ -115,7 +122,7 @@ var Addons = []*Addon{
{
name: "registry",
set: SetBool,
callbacks: []setFn{enableOrDisableAddon},
callbacks: []setFn{enableOrDisableAddon, verifyAddonStatus},
},
{
name: "registry-creds",
......
......@@ -28,7 +28,6 @@ import (
apierr "k8s.io/apimachinery/pkg/api/errors"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apimachinery/pkg/watch"
......@@ -70,21 +69,21 @@ func Client(context string) (*kubernetes.Clientset, error) {
return kubernetes.NewForConfig(c)
}
// WaitForPodsWithLabelRunning waits for all matching pods to become Running and at least one matching pod exists.
func WaitForPodsWithLabelRunning(c kubernetes.Interface, ns string, label labels.Selector, timeOut ...time.Duration) error {
// WaitForPods waits for all matching pods to become Running or finish successfully and at least one matching pod exists.
func WaitForPods(c kubernetes.Interface, ns string, selector string, timeOut ...time.Duration) error {
start := time.Now()
glog.Infof("Waiting for pod with label %q in ns %q ...", ns, label)
glog.Infof("Waiting for pod with label %q in ns %q ...", ns, selector)
lastKnownPodNumber := -1
f := func() (bool, error) {
listOpts := meta.ListOptions{LabelSelector: label.String()}
listOpts := meta.ListOptions{LabelSelector: selector}
pods, err := c.CoreV1().Pods(ns).List(listOpts)
if err != nil {
glog.Infof("temporary error: getting Pods with label selector %q : [%v]\n", label.String(), err)
glog.Infof("temporary error: getting Pods with label selector %q : [%v]\n", selector, err)
return false, nil
}
if lastKnownPodNumber != len(pods.Items) {
glog.Infof("Found %d Pods for label selector %s\n", len(pods.Items), label.String())
glog.Infof("Found %d Pods for label selector %s\n", len(pods.Items), selector)
lastKnownPodNumber = len(pods.Items)
}
......@@ -93,8 +92,8 @@ func WaitForPodsWithLabelRunning(c kubernetes.Interface, ns string, label labels
}
for _, pod := range pods.Items {
if pod.Status.Phase != core.PodRunning {
glog.Infof("waiting for pod %q, current state: %s: [%v]\n", label.String(), pod.Status.Phase, err)
if pod.Status.Phase != core.PodRunning && pod.Status.Phase != core.PodSucceeded {
glog.Infof("waiting for pod %q, current state: %s: [%v]\n", selector, pod.Status.Phase, err)
return false, nil
}
}
......@@ -106,7 +105,7 @@ func WaitForPodsWithLabelRunning(c kubernetes.Interface, ns string, label labels
t = timeOut[0]
}
err := wait.PollImmediate(kconst.APICallRetryInterval, t, f)
glog.Infof("duration metric: took %s to wait for %s ...", time.Since(start), label)
glog.Infof("duration metric: took %s to wait for %s ...", time.Since(start), selector)
return err
}
......