addons_test.go 2.9 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
// +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"
23
	"strings"
24 25 26 27 28 29 30 31 32 33
	"testing"
	"time"

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

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

var (
D
Dan Lorenc 已提交
34
	addonManagerCmd = []string{"get", "pods", "--namespace=kube-system"}
35 36
	dashboardRcCmd  = []string{"get", "rc", "kubernetes-dashboard", "--namespace=kube-system"}
	dashboardSvcCmd = []string{"get", "svc", "kubernetes-dashboard", "--namespace=kube-system"}
37 38 39
)

func TestAddons(t *testing.T) {
40 41 42 43 44
	minikubeRunner := util.MinikubeRunner{
		BinaryPath: *binaryPath,
		Args:       *args,
		T:          t}

D
dlorenc 已提交
45
	minikubeRunner.EnsureRunning()
46 47 48
	kubectlRunner := util.NewKubectlRunner(t)

	checkAddon := func() error {
49 50
		pods := api.PodList{}
		if err := kubectlRunner.RunCommandParseOutput(addonManagerCmd, &pods); err != nil {
51 52 53
			return err
		}

54 55 56 57 58
		for _, p := range pods.Items {
			if strings.HasPrefix(p.ObjectMeta.Name, "kube-addon-manager-") {
				if p.Status.Phase == "Running" {
					return nil
				}
59
				return &commonutil.RetriableError{Err: fmt.Errorf("Pod is not Running. Status: %s", p.Status.Phase)}
60
			}
61
		}
62

J
Jimmi Dyson 已提交
63
		return &commonutil.RetriableError{Err: fmt.Errorf("Addon manager not found. Found pods: %v", pods)}
64 65
	}

66
	if err := commonutil.RetryAfter(20, checkAddon, 5*time.Second); err != nil {
67 68 69 70 71
		t.Fatalf("Addon Manager pod is unhealthy: %s", err)
	}
}

func TestDashboard(t *testing.T) {
72 73 74 75 76
	minikubeRunner := util.MinikubeRunner{
		BinaryPath: *binaryPath,
		Args:       *args,
		T:          t}
	minikubeRunner.Start()
77 78 79 80 81
	minikubeRunner.CheckStatus("Running")
	kubectlRunner := util.NewKubectlRunner(t)

	checkDashboard := func() error {
		rc := api.ReplicationController{}
82 83 84 85 86 87
		svc := api.Service{}
		if err := kubectlRunner.RunCommandParseOutput(dashboardRcCmd, &rc); err != nil {
			return err
		}

		if err := kubectlRunner.RunCommandParseOutput(dashboardSvcCmd, &svc); err != nil {
88 89 90 91
			return err
		}

		if rc.Status.Replicas != rc.Status.FullyLabeledReplicas {
J
Jimmi Dyson 已提交
92
			return &commonutil.RetriableError{Err: fmt.Errorf("Not enough pods running. Expected %d, got %d.", rc.Status.Replicas, rc.Status.FullyLabeledReplicas)}
93
		}
94 95

		if svc.Spec.Ports[0].NodePort != 30000 {
J
Jimmi Dyson 已提交
96
			return fmt.Errorf("Dashboard is not exposed on port %d", svc.Spec.Ports[0].NodePort)
97 98
		}

99 100 101 102 103 104 105
		return nil
	}

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