addons_test.go 2.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
// +build integration

/*
Copyright 2016 The Kubernetes Authors All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package integration

import (
	"fmt"
	"testing"
	"time"

	"k8s.io/kubernetes/pkg/api"
	commonutil "k8s.io/minikube/pkg/util"

	"k8s.io/minikube/test/integration/util"
)

var (
	addonManagerCmd = []string{"get", "pod", "kube-addon-manager-127.0.0.1", "--namespace=kube-system"}
	dashboardCmd    = []string{"get", "rc", "kubernetes-dashboard", "--namespace=kube-system"}
)

func TestAddons(t *testing.T) {
	minikubeRunner := util.MinikubeRunner{BinaryPath: *binaryPath, T: t}
D
dlorenc 已提交
39
	minikubeRunner.EnsureRunning()
40 41 42 43
	kubectlRunner := util.NewKubectlRunner(t)

	checkAddon := func() error {
		p := api.Pod{}
A
aprindle 已提交
44
		if err := kubectlRunner.RunCommandParseOutput(addonManagerCmd, &p); err != nil {
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
			return err
		}

		if p.Status.Phase != "Running" {
			return fmt.Errorf("Pod is not Running. Status: %s", p.Status.Phase)
		}
		return nil
	}

	if err := commonutil.RetryAfter(10, checkAddon, 5*time.Second); err != nil {
		t.Fatalf("Addon Manager pod is unhealthy: %s", err)
	}
}

func TestDashboard(t *testing.T) {
	minikubeRunner := util.MinikubeRunner{BinaryPath: *binaryPath, T: t}
	minikubeRunner.RunCommand("start", true)
	minikubeRunner.CheckStatus("Running")
	kubectlRunner := util.NewKubectlRunner(t)

	checkDashboard := func() error {
		rc := api.ReplicationController{}
A
aprindle 已提交
67
		if err := kubectlRunner.RunCommandParseOutput(dashboardCmd, &rc); err != nil {
68 69 70 71 72 73 74 75 76 77 78 79 80
			return err
		}

		if rc.Status.Replicas != rc.Status.FullyLabeledReplicas {
			return fmt.Errorf("Not enough pods running. Expected %s, got %s.", rc.Status.Replicas, rc.Status.FullyLabeledReplicas)
		}
		return nil
	}

	if err := commonutil.RetryAfter(10, checkDashboard, 5*time.Second); err != nil {
		t.Fatalf("Dashboard is unhealthy: %s", err)
	}
}