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

label minikube nodes #6717

Merged
merged 7 commits into from
Feb 22, 2020
Merged
Changes from 1 commit
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
32 changes: 32 additions & 0 deletions pkg/minikube/bootstrapper/kubeadm/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import (
"k8s.io/minikube/pkg/minikube/out"
"k8s.io/minikube/pkg/minikube/vmpath"
"k8s.io/minikube/pkg/util/retry"
"k8s.io/minikube/pkg/version"
)

// Bootstrapper is a bootstrapper using kubeadm
Expand Down Expand Up @@ -230,6 +231,10 @@ func (k *Bootstrapper) StartCluster(cfg config.MachineConfig) error {
return errors.Wrap(err, "timed out waiting to elevate kube-system RBAC privileges")
}
}
fmt.Println("about to apply node labels")
if err := k.applyNodeLabels(cfg); err != nil {
glog.Warningf("unable to apply node labels: %v", err)
}

if err := bsutil.AdjustResourceLimits(k.c); err != nil {
glog.Warningf("unable to adjust resource limits: %v", err)
Expand Down Expand Up @@ -483,3 +488,30 @@ func (k *Bootstrapper) applyKicOverlay(cfg config.MachineConfig) error {
}
return nil
}

// applyNodeLabels applies minikube labels to all the nodes
func (k *Bootstrapper) applyNodeLabels(cfg config.MachineConfig) error {
start := time.Now()
// based on ISO 8601 (RFC 3339) except converting - and : to _ because of kubernetes label restriction
createdAtLbl := "k8s.minikube.io/updated_at=" + start.Format("2006_01_02T15_04_05_0700")
medyagh marked this conversation as resolved.
Show resolved Hide resolved
verLbl := "k8s.minikube.io/version=" + version.GetVersion()
commitLbl := "k8s.minikube.io/commit=" + version.GetGitCommitID()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we omit the commit id? At least until someone declares a use case for it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the use case for it is, if I am developing locally, I wanna know my developoing-code created this cluster not the minikube stable

nameLbl := "k8s.minikube.io/name=" + cfg.Name

// example:
// /var/lib/minikube/binaries/v1.17.3/kubectl label nodes --kubeconfig /var/lib/minikube/kubeconfig k8s.minikube.io/version=1.7.3 --all --overwrite
cmd := exec.Command("sudo",
path.Join(vmpath.GuestPersistentDir, "binaries", cfg.KubernetesConfig.KubernetesVersion, "kubectl"),
"label", "nodes", verLbl, commitLbl, nameLbl, createdAtLbl, "--all", "--overwrite",
fmt.Sprintf("--kubeconfig=%s", path.Join(vmpath.GuestPersistentDir, "kubeconfig")))

rr, err := k.c.RunCmd(cmd)
elapsed := time.Since(start)
if elapsed > (1 * time.Second) {
glog.Infof("Completed: %s: (%s)", rr.Command(), elapsed)
medyagh marked this conversation as resolved.
Show resolved Hide resolved
}
if err != nil {
return errors.Wrapf(err, "applying node labels")
}
return nil
}