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

add verification for enabling ingress, registry and gvisor addons #8563

Merged
merged 10 commits into from
Jun 26, 2020
Merged
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
26 changes: 26 additions & 0 deletions pkg/addons/addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 10 additions & 3 deletions pkg/addons/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
{
Expand Down Expand Up @@ -55,7 +62,7 @@ var Addons = []*Addon{
name: "gvisor",
set: SetBool,
validations: []setFn{IsRuntimeContainerd},
callbacks: []setFn{enableOrDisableAddon},
callbacks: []setFn{enableOrDisableAddon, verifyAddonStatus},
},
{
name: "helm-tiller",
Expand All @@ -65,7 +72,7 @@ var Addons = []*Addon{
{
name: "ingress",
set: SetBool,
callbacks: []setFn{enableOrDisableAddon},
callbacks: []setFn{enableOrDisableAddon, verifyAddonStatus},
},
{
name: "ingress-dns",
Expand Down Expand Up @@ -115,7 +122,7 @@ var Addons = []*Addon{
{
name: "registry",
set: SetBool,
callbacks: []setFn{enableOrDisableAddon},
callbacks: []setFn{enableOrDisableAddon, verifyAddonStatus},
},
{
name: "registry-creds",
Expand Down
19 changes: 9 additions & 10 deletions pkg/kapi/kapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}

Expand All @@ -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
}
}
Expand All @@ -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
}

Expand Down