From 08f4677511af75330c567845b0b3fbfc8852cee2 Mon Sep 17 00:00:00 2001 From: kairen Date: Wed, 10 Jan 2018 02:15:07 +0800 Subject: [PATCH] Change kubernetes-dashboard from RC to Deployment --- .../{dashboard-rc.yaml => dashboard-dp.yaml} | 11 ++++--- pkg/minikube/assets/addons.go | 4 +-- pkg/minikube/constants/constants.go | 4 +-- pkg/util/kubernetes.go | 31 +++++++++++++++++++ test/integration/util/util.go | 4 +-- 5 files changed, 43 insertions(+), 11 deletions(-) rename deploy/addons/dashboard/{dashboard-rc.yaml => dashboard-dp.yaml} (89%) diff --git a/deploy/addons/dashboard/dashboard-rc.yaml b/deploy/addons/dashboard/dashboard-dp.yaml similarity index 89% rename from deploy/addons/dashboard/dashboard-rc.yaml rename to deploy/addons/dashboard/dashboard-dp.yaml index a0af480fbe63..53efeb2e80e3 100644 --- a/deploy/addons/dashboard/dashboard-rc.yaml +++ b/deploy/addons/dashboard/dashboard-dp.yaml @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -apiVersion: v1 -kind: ReplicationController +apiVersion: apps/v1 +kind: Deployment metadata: name: kubernetes-dashboard namespace: kube-system @@ -24,9 +24,10 @@ metadata: spec: replicas: 1 selector: - app: kubernetes-dashboard - version: v1.8.1 - addonmanager.kubernetes.io/mode: Reconcile + matchLabels: + app: kubernetes-dashboard + version: v1.8.1 + addonmanager.kubernetes.io/mode: Reconcile template: metadata: labels: diff --git a/pkg/minikube/assets/addons.go b/pkg/minikube/assets/addons.go index dd390c7d8aac..8c0e2f251fcf 100644 --- a/pkg/minikube/assets/addons.go +++ b/pkg/minikube/assets/addons.go @@ -65,9 +65,9 @@ var Addons = map[string]*Addon{ }, true, "addon-manager"), "dashboard": NewAddon([]*BinDataAsset{ NewBinDataAsset( - "deploy/addons/dashboard/dashboard-rc.yaml", + "deploy/addons/dashboard/dashboard-dp.yaml", constants.AddonsPath, - "dashboard-rc.yaml", + "dashboard-dp.yaml", "0640"), NewBinDataAsset( "deploy/addons/dashboard/dashboard-svc.yaml", diff --git a/pkg/minikube/constants/constants.go b/pkg/minikube/constants/constants.go index 7818dee473eb..bf352badaba3 100644 --- a/pkg/minikube/constants/constants.go +++ b/pkg/minikube/constants/constants.go @@ -168,7 +168,7 @@ const FileScheme = "file" var LocalkubeCachedImages = []string{ // Dashboard - "k8s.gcr.io/kubernetes-dashboard-amd64:v1.6.3", + "k8s.gcr.io/kubernetes-dashboard-amd64:v1.8.1", // DNS "k8s.gcr.io/k8s-dns-kube-dns-amd64:1.14.5", @@ -188,7 +188,7 @@ var LocalkubeCachedImages = []string{ func GetKubeadmCachedImages(version string) []string { return []string{ // Dashboard - "k8s.gcr.io/kubernetes-dashboard-amd64:v1.6.3", + "k8s.gcr.io/kubernetes-dashboard-amd64:v1.8.1", // Addon Manager "gcr.io/google-containers/kube-addon-manager:v6.5", diff --git a/pkg/util/kubernetes.go b/pkg/util/kubernetes.go index c69180f5afef..59e408b326ab 100755 --- a/pkg/util/kubernetes.go +++ b/pkg/util/kubernetes.go @@ -31,6 +31,7 @@ import ( "k8s.io/apimachinery/pkg/watch" "k8s.io/kubernetes/cmd/kubeadm/app/constants" + appsv1 "k8s.io/api/apps/v1" "k8s.io/api/core/v1" apierrs "k8s.io/apimachinery/pkg/api/errors" "k8s.io/client-go/kubernetes" @@ -168,6 +169,36 @@ func WaitForRCToStabilize(c kubernetes.Interface, ns, name string, timeout time. return err } +// WaitForDeploymentToStabilize waits till the Deployment has a matching generation/replica count between spec and status. +func WaitForDeploymentToStabilize(c kubernetes.Interface, ns, name string, timeout time.Duration) error { + options := metav1.ListOptions{FieldSelector: fields.Set{ + "metadata.name": name, + "metadata.namespace": ns, + }.AsSelector().String()} + w, err := c.AppsV1().Deployments(ns).Watch(options) + if err != nil { + return err + } + _, err = watch.Until(timeout, w, func(event watch.Event) (bool, error) { + switch event.Type { + case watch.Deleted: + return false, apierrs.NewNotFound(schema.GroupResource{Resource: "deployments"}, "") + } + switch dp := event.Object.(type) { + case *appsv1.Deployment: + if dp.Name == name && dp.Namespace == ns && + dp.Generation <= dp.Status.ObservedGeneration && + *(dp.Spec.Replicas) == dp.Status.Replicas { + return true, nil + } + glog.Infof("Waiting for deployment %s to stabilize, generation %v observed generation %v spec.replicas %d status.replicas %d", + name, dp.Generation, dp.Status.ObservedGeneration, *(dp.Spec.Replicas), dp.Status.Replicas) + } + return false, nil + }) + return err +} + // WaitForService waits until the service appears (exist == true), or disappears (exist == false) func WaitForService(c kubernetes.Interface, namespace, name string, exist bool, interval, timeout time.Duration) error { err := wait.PollImmediate(interval, timeout, func() (bool, error) { diff --git a/test/integration/util/util.go b/test/integration/util/util.go index a7bc3c64b22a..c6f4a30d9926 100644 --- a/test/integration/util/util.go +++ b/test/integration/util/util.go @@ -248,8 +248,8 @@ func WaitForDashboardRunning(t *testing.T) error { if err != nil { return errors.Wrap(err, "getting kubernetes client") } - if err := commonutil.WaitForRCToStabilize(client, "kube-system", "kubernetes-dashboard", time.Minute*10); err != nil { - return errors.Wrap(err, "waiting for dashboard RC to stabilize") + if err := commonutil.WaitForDeploymentToStabilize(client, "kube-system", "kubernetes-dashboard", time.Minute*10); err != nil { + return errors.Wrap(err, "waiting for dashboard deployment to stabilize") } if err := commonutil.WaitForService(client, "kube-system", "kubernetes-dashboard", true, time.Millisecond*500, time.Minute*10); err != nil {