Updates for gcloud changes (alpha, kubeconfig)

This commit is contained in:
Jeff Lowdermilk 2015-03-31 16:36:31 -07:00
parent 2de37624e8
commit cfc04f41b8
15 changed files with 102 additions and 95 deletions

View File

@ -91,6 +91,7 @@ function verify-prereqs() {
gcloud_prompt="-q" gcloud_prompt="-q"
fi fi
gcloud ${gcloud_prompt:-} components update preview || true gcloud ${gcloud_prompt:-} components update preview || true
gcloud ${gcloud_prompt:-} components update alpha || true
gcloud ${gcloud_prompt:-} components update || true gcloud ${gcloud_prompt:-} components update || true
} }
@ -128,7 +129,7 @@ function kube-up() {
fi fi
# Bring up the cluster. # Bring up the cluster.
"${GCLOUD}" preview container clusters create "${CLUSTER_NAME}" \ "${GCLOUD}" alpha container clusters create "${CLUSTER_NAME}" \
--zone="${ZONE}" \ --zone="${ZONE}" \
--project="${PROJECT}" \ --project="${PROJECT}" \
--cluster-api-version="${CLUSTER_API_VERSION:-}" \ --cluster-api-version="${CLUSTER_API_VERSION:-}" \
@ -175,10 +176,10 @@ function test-setup() {
function get-password() { function get-password() {
echo "... in get-password()" >&2 echo "... in get-password()" >&2
detect-project >&2 detect-project >&2
KUBE_USER=$("${GCLOUD}" preview container clusters describe \ KUBE_USER=$("${GCLOUD}" alpha container clusters describe \
--project="${PROJECT}" --zone="${ZONE}" "${CLUSTER_NAME}" \ --project="${PROJECT}" --zone="${ZONE}" "${CLUSTER_NAME}" \
| grep user | cut -f 4 -d ' ') | grep user | cut -f 4 -d ' ')
KUBE_PASSWORD=$("${GCLOUD}" preview container clusters describe \ KUBE_PASSWORD=$("${GCLOUD}" alpha container clusters describe \
--project="${PROJECT}" --zone="${ZONE}" "${CLUSTER_NAME}" \ --project="${PROJECT}" --zone="${ZONE}" "${CLUSTER_NAME}" \
| grep password | cut -f 4 -d ' ') | grep password | cut -f 4 -d ' ')
} }
@ -195,7 +196,7 @@ function detect-master() {
echo "... in detect-master()" >&2 echo "... in detect-master()" >&2
detect-project >&2 detect-project >&2
KUBE_MASTER="k8s-${CLUSTER_NAME}-master" KUBE_MASTER="k8s-${CLUSTER_NAME}-master"
KUBE_MASTER_IP=$("${GCLOUD}" preview container clusters describe \ KUBE_MASTER_IP=$("${GCLOUD}" alpha container clusters describe \
--project="${PROJECT}" --zone="${ZONE}" "${CLUSTER_NAME}" \ --project="${PROJECT}" --zone="${ZONE}" "${CLUSTER_NAME}" \
| grep endpoint | cut -f 2 -d ' ') | grep endpoint | cut -f 2 -d ' ')
} }
@ -218,7 +219,7 @@ function detect-minions() {
function detect-minion-names { function detect-minion-names {
detect-project detect-project
export MINION_NAMES="" export MINION_NAMES=""
count=$("${GCLOUD}" preview container clusters describe --project="${PROJECT}" --zone="${ZONE}" "${CLUSTER_NAME}" | grep numNodes | cut -f 2 -d ' ') count=$("${GCLOUD}" alpha container clusters describe --project="${PROJECT}" --zone="${ZONE}" "${CLUSTER_NAME}" | grep numNodes | cut -f 2 -d ' ')
for x in $(seq 1 $count); do for x in $(seq 1 $count); do
export MINION_NAMES="${MINION_NAMES} k8s-${CLUSTER_NAME}-node-${x} "; export MINION_NAMES="${MINION_NAMES} k8s-${CLUSTER_NAME}-node-${x} ";
done done
@ -286,6 +287,6 @@ function test-teardown() {
function kube-down() { function kube-down() {
echo "... in kube-down()" >&2 echo "... in kube-down()" >&2
detect-project >&2 detect-project >&2
"${GCLOUD}" preview container clusters delete --project="${PROJECT}" \ "${GCLOUD}" alpha container clusters delete --project="${PROJECT}" \
--zone="${ZONE}" "${CLUSTER_NAME}" --zone="${ZONE}" "${CLUSTER_NAME}"
} }

View File

@ -108,7 +108,7 @@ if [[ "$KUBERNETES_PROVIDER" == "gke" ]]; then
kubectl="${GCLOUD}" kubectl="${GCLOUD}"
# GKE runs kubectl through gcloud. # GKE runs kubectl through gcloud.
config=( config=(
"preview" "alpha"
"container" "container"
"kubectl" "kubectl"
"--project=${PROJECT}" "--project=${PROJECT}"

View File

@ -28,16 +28,10 @@ import (
) )
var ( var (
kubeConfig = flag.String(clientcmd.RecommendedConfigPathFlag, "", "Path to kubeconfig containing embeded authinfo. Will use cluster/user info from 'current-context'") context = &e2e.TestContextType{}
authConfig = flag.String("auth_config", "", "Path to the auth info file.") gceConfig = &context.GCEConfig
certDir = flag.String("cert_dir", "", "Path to the directory containing the certs. Default is empty, which doesn't use certs.")
gceProject = flag.String("gce_project", "", "The GCE project being used, if applicable")
gceZone = flag.String("gce_zone", "", "GCE zone being used, if applicable")
host = flag.String("host", "", "The host to connect to")
masterName = flag.String("kube_master", "", "Name of the kubernetes master. Only required if provider is gce or gke")
provider = flag.String("provider", "", "The name of the Kubernetes provider")
orderseed = flag.Int64("orderseed", 0, "If non-zero, seed of random test shuffle order. (Otherwise random.)") orderseed = flag.Int64("orderseed", 0, "If non-zero, seed of random test shuffle order. (Otherwise random.)")
repoRoot = flag.String("repo_root", "./", "Root directory of kubernetes repository, for finding test files. Default assumes working directory is repository root")
reportDir = flag.String("report_dir", "", "Path to the directory where the JUnit XML reports should be saved. Default is empty, which doesn't generate these reports.") reportDir = flag.String("report_dir", "", "Path to the directory where the JUnit XML reports should be saved. Default is empty, which doesn't generate these reports.")
times = flag.Int("times", 1, "Number of times each test is eligible to be run. Individual order is determined by shuffling --times instances of each test using --orderseed (like a multi-deck shoe of cards).") times = flag.Int("times", 1, "Number of times each test is eligible to be run. Individual order is determined by shuffling --times instances of each test using --orderseed (like a multi-deck shoe of cards).")
testList util.StringList testList util.StringList
@ -45,12 +39,23 @@ var (
func init() { func init() {
flag.VarP(&testList, "test", "t", "Test to execute (may be repeated or comma separated list of tests.) Defaults to running all tests.") flag.VarP(&testList, "test", "t", "Test to execute (may be repeated or comma separated list of tests.) Defaults to running all tests.")
flag.StringVar(&context.KubeConfig, clientcmd.RecommendedConfigPathFlag, "", "Path to kubeconfig containing embeded authinfo.")
flag.StringVar(&context.KubeContext, clientcmd.FlagContext, "", "kubeconfig context to use/override. If unset, will use value from 'current-context'")
flag.StringVar(&context.AuthConfig, "auth_config", "", "Path to the auth info file.")
flag.StringVar(&context.CertDir, "cert_dir", "", "Path to the directory containing the certs. Default is empty, which doesn't use certs.")
flag.StringVar(&context.Host, "host", "", "The host to connect to")
flag.StringVar(&context.RepoRoot, "repo_root", "./", "Root directory of kubernetes repository, for finding test files. Default assumes working directory is repository root")
flag.StringVar(&context.Provider, "provider", "", "The name of the Kubernetes provider")
flag.StringVar(&gceConfig.MasterName, "kube_master", "", "Name of the kubernetes master. Only required if provider is gce or gke")
flag.StringVar(&gceConfig.ProjectID, "gce_project", "", "The GCE project being used, if applicable")
flag.StringVar(&gceConfig.Zone, "gce_zone", "", "GCE zone being used, if applicable")
} }
func main() { func main() {
util.InitFlags() util.InitFlags()
goruntime.GOMAXPROCS(goruntime.NumCPU()) goruntime.GOMAXPROCS(goruntime.NumCPU())
if *provider == "" { if context.Provider == "" {
glog.Info("The --provider flag is not set. Treating as a conformance test. Some tests may not be run.") glog.Info("The --provider flag is not set. Treating as a conformance test. Some tests may not be run.")
os.Exit(1) os.Exit(1)
} }
@ -58,10 +63,5 @@ func main() {
glog.Error("Invalid --times (negative or no testing requested)!") glog.Error("Invalid --times (negative or no testing requested)!")
os.Exit(1) os.Exit(1)
} }
gceConfig := &e2e.GCEConfig{ e2e.RunE2ETests(context, *orderseed, *times, *reportDir, testList)
ProjectID: *gceProject,
Zone: *gceZone,
MasterName: *masterName,
}
e2e.RunE2ETests(*kubeConfig, *authConfig, *certDir, *host, *repoRoot, *provider, gceConfig, *orderseed, *times, *reportDir, testList)
} }

View File

@ -95,12 +95,12 @@ if [[ -z "${AUTH_CONFIG:-}" ]]; then
"--kubeconfig=${HOME}/.kubernetes_vagrant_kubeconfig" "--kubeconfig=${HOME}/.kubernetes_vagrant_kubeconfig"
) )
elif [[ "${KUBERNETES_PROVIDER}" == "gke" ]]; then elif [[ "${KUBERNETES_PROVIDER}" == "gke" ]]; then
# With GKE, our auth and certs are in gcloud's config directory. # GKE stores its own kubeconfig in gcloud's config directory.
detect-project &> /dev/null detect-project &> /dev/null
cfg_dir="${GCLOUD_CONFIG_DIR}/${PROJECT}.${ZONE}.${CLUSTER_NAME}"
auth_config=( auth_config=(
"--auth_config=${cfg_dir}/kubernetes_auth" "--kubeconfig=${GCLOUD_CONFIG_DIR}/kubeconfig"
"--cert_dir=${cfg_dir}" # gcloud doesn't set the current-context, so we have to set it
"--context=gke_${PROJECT}_${ZONE}_${CLUSTER_NAME}"
) )
elif [[ "${KUBERNETES_PROVIDER}" == "gce" ]]; then elif [[ "${KUBERNETES_PROVIDER}" == "gce" ]]; then
auth_config=( auth_config=(

View File

@ -32,14 +32,14 @@ var _ = Describe("MasterCerts", func() {
}) })
It("should have all expected certs on the master", func() { It("should have all expected certs on the master", func() {
if testContext.provider != "gce" && testContext.provider != "gke" { if testContext.Provider != "gce" && testContext.Provider != "gke" {
By(fmt.Sprintf("Skipping MasterCerts test for cloud provider %s (only supported for gce and gke)", testContext.provider)) By(fmt.Sprintf("Skipping MasterCerts test for cloud provider %s (only supported for gce and gke)", testContext.Provider))
return return
} }
for _, certFile := range []string{"kubecfg.key", "kubecfg.crt", "ca.crt"} { for _, certFile := range []string{"kubecfg.key", "kubecfg.crt", "ca.crt"} {
cmd := exec.Command("gcloud", "compute", "ssh", "--project", testContext.gceConfig.ProjectID, cmd := exec.Command("gcloud", "compute", "ssh", "--project", testContext.GCEConfig.ProjectID,
"--zone", testContext.gceConfig.Zone, testContext.gceConfig.MasterName, "--zone", testContext.GCEConfig.Zone, testContext.GCEConfig.MasterName,
"--command", fmt.Sprintf("ls /srv/kubernetes/%s", certFile)) "--command", fmt.Sprintf("ls /srv/kubernetes/%s", certFile))
if _, err := cmd.CombinedOutput(); err != nil { if _, err := cmd.CombinedOutput(); err != nil {
Fail(fmt.Sprintf("Error checking for cert file %s on master: %v", certFile, err)) Fail(fmt.Sprintf("Error checking for cert file %s on master: %v", certFile, err))

View File

@ -53,8 +53,8 @@ func (t *testResult) Fail() { *t = false }
// Run each Go end-to-end-test. This function assumes the // Run each Go end-to-end-test. This function assumes the
// creation of a test cluster. // creation of a test cluster.
func RunE2ETests(kubeConfig, authConfig, certDir, host, repoRoot, provider string, gceConfig *GCEConfig, orderseed int64, times int, reportDir string, testList []string) { func RunE2ETests(context *TestContextType, orderseed int64, times int, reportDir string, testList []string) {
testContext = testContextType{kubeConfig, authConfig, certDir, host, repoRoot, provider, *gceConfig} testContext = *context
util.ReallyCrash = true util.ReallyCrash = true
util.InitLogs() util.InitLogs()
defer util.FlushLogs() defer util.FlushLogs()

View File

@ -60,8 +60,8 @@ func ClusterLevelLoggingWithElasticsearch(c *client.Client) {
// TODO: For now assume we are only testing cluster logging with Elasticsearch // TODO: For now assume we are only testing cluster logging with Elasticsearch
// on GCE. Once we are sure that Elasticsearch cluster level logging // on GCE. Once we are sure that Elasticsearch cluster level logging
// works for other providers we should widen this scope of this test. // works for other providers we should widen this scope of this test.
if testContext.provider != "gce" { if testContext.Provider != "gce" {
Logf("Skipping cluster level logging test for provider %s", testContext.provider) Logf("Skipping cluster level logging test for provider %s", testContext.Provider)
return return
} }

View File

@ -41,7 +41,7 @@ var _ = Describe("Events", func() {
}) })
It("should be sent by kubelets and the scheduler about pods scheduling and running", func() { It("should be sent by kubelets and the scheduler about pods scheduling and running", func() {
provider := testContext.provider provider := testContext.Provider
if len(provider) > 0 && provider != "gce" && provider != "gke" && provider != "aws" { if len(provider) > 0 && provider != "gce" && provider != "gke" && provider != "aws" {
By(fmt.Sprintf("skipping TestKubeletSendsEvent on cloud provider %s", provider)) By(fmt.Sprintf("skipping TestKubeletSendsEvent on cloud provider %s", provider))
return return

View File

@ -53,7 +53,7 @@ var _ = Describe("kubectl", func() {
Describe("update-demo", func() { Describe("update-demo", func() {
var ( var (
updateDemoRoot = filepath.Join(testContext.repoRoot, "examples/update-demo/v1beta1") updateDemoRoot = filepath.Join(testContext.RepoRoot, "examples/update-demo/v1beta1")
nautilusPath = filepath.Join(updateDemoRoot, "nautilus-rc.yaml") nautilusPath = filepath.Join(updateDemoRoot, "nautilus-rc.yaml")
kittenPath = filepath.Join(updateDemoRoot, "kitten-rc.yaml") kittenPath = filepath.Join(updateDemoRoot, "kitten-rc.yaml")
) )
@ -94,7 +94,7 @@ var _ = Describe("kubectl", func() {
}) })
Describe("guestbook", func() { Describe("guestbook", func() {
var guestbookPath = filepath.Join(testContext.repoRoot, "examples/guestbook") var guestbookPath = filepath.Join(testContext.RepoRoot, "examples/guestbook")
It("should create and stop a working application", func() { It("should create and stop a working application", func() {
defer cleanup(guestbookPath, frontendSelector, redisMasterSelector, redisSlaveSelector) defer cleanup(guestbookPath, frontendSelector, redisMasterSelector, redisSlaveSelector)

View File

@ -40,9 +40,9 @@ var _ = Describe("Monitoring", func() {
}) })
It("verify monitoring pods and all cluster nodes are available on influxdb using heapster.", func() { It("verify monitoring pods and all cluster nodes are available on influxdb using heapster.", func() {
if testContext.provider != "gce" { if testContext.Provider != "gce" {
By(fmt.Sprintf("Skipping Monitoring test, which is only supported for provider gce (not %s)", By(fmt.Sprintf("Skipping Monitoring test, which is only supported for provider gce (not %s)",
testContext.provider)) testContext.Provider))
return return
} }
testMonitoringUsingHeapsterInfluxdb(c) testMonitoringUsingHeapsterInfluxdb(c)
@ -192,7 +192,7 @@ func validatePodsAndNodes(influxdbClient *influxdb.Client, expectedPods, expecte
} }
func getMasterHost() string { func getMasterHost() string {
masterUrl, err := url.Parse(testContext.host) masterUrl, err := url.Parse(testContext.Host)
expectNoError(err) expectNoError(err)
return masterUrl.Host return masterUrl.Host
} }

View File

@ -42,7 +42,7 @@ var _ = Describe("Networking", func() {
ns := "nettest-" + randomSuffix() ns := "nettest-" + randomSuffix()
It("should function for pods", func() { It("should function for pods", func() {
if testContext.provider == "vagrant" { if testContext.Provider == "vagrant" {
By("Skipping test which is broken for vagrant (See https://github.com/GoogleCloudPlatform/kubernetes/issues/3580)") By("Skipping test which is broken for vagrant (See https://github.com/GoogleCloudPlatform/kubernetes/issues/3580)")
return return
} }

View File

@ -55,9 +55,9 @@ var _ = Describe("PD", func() {
}) })
It("should schedule a pod w/ a RW PD, remove it, then schedule it on another host", func() { It("should schedule a pod w/ a RW PD, remove it, then schedule it on another host", func() {
if testContext.provider != "gce" { if testContext.Provider != "gce" {
By(fmt.Sprintf("Skipping PD test, which is only supported for provider gce (not %s)", By(fmt.Sprintf("Skipping PD test, which is only supported for provider gce (not %s)",
testContext.provider)) testContext.Provider))
return return
} }
@ -65,7 +65,7 @@ var _ = Describe("PD", func() {
host1Pod := testPDPod(diskName, host1Name, false) host1Pod := testPDPod(diskName, host1Name, false)
By(fmt.Sprintf("creating PD %q", diskName)) By(fmt.Sprintf("creating PD %q", diskName))
expectNoError(createPD(diskName, testContext.gceConfig.Zone), "Error creating PD") expectNoError(createPD(diskName, testContext.GCEConfig.Zone), "Error creating PD")
defer func() { defer func() {
By("cleaning up PD-RW test environment") By("cleaning up PD-RW test environment")
@ -73,9 +73,9 @@ var _ = Describe("PD", func() {
// Teardown should do nothing unless test failed. // Teardown should do nothing unless test failed.
podClient.Delete(host0Pod.Name) podClient.Delete(host0Pod.Name)
podClient.Delete(host1Pod.Name) podClient.Delete(host1Pod.Name)
detachPD(host0Name, diskName, testContext.gceConfig.Zone) detachPD(host0Name, diskName, testContext.GCEConfig.Zone)
detachPD(host1Name, diskName, testContext.gceConfig.Zone) detachPD(host1Name, diskName, testContext.GCEConfig.Zone)
deletePD(diskName, testContext.gceConfig.Zone) deletePD(diskName, testContext.GCEConfig.Zone)
}() }()
By("submitting host0Pod to kubernetes") By("submitting host0Pod to kubernetes")
@ -98,7 +98,7 @@ var _ = Describe("PD", func() {
By(fmt.Sprintf("deleting PD %q", diskName)) By(fmt.Sprintf("deleting PD %q", diskName))
for start := time.Now(); time.Since(start) < 180*time.Second; time.Sleep(5 * time.Second) { for start := time.Now(); time.Since(start) < 180*time.Second; time.Sleep(5 * time.Second) {
if err = deletePD(diskName, testContext.gceConfig.Zone); err != nil { if err = deletePD(diskName, testContext.GCEConfig.Zone); err != nil {
Logf("Couldn't delete PD. Sleeping 5 seconds") Logf("Couldn't delete PD. Sleeping 5 seconds")
continue continue
} }
@ -110,9 +110,9 @@ var _ = Describe("PD", func() {
}) })
It("should schedule a pod w/ a readonly PD on two hosts, then remove both.", func() { It("should schedule a pod w/ a readonly PD on two hosts, then remove both.", func() {
if testContext.provider != "gce" { if testContext.Provider != "gce" {
By(fmt.Sprintf("Skipping PD test, which is only supported for provider gce (not %s)", By(fmt.Sprintf("Skipping PD test, which is only supported for provider gce (not %s)",
testContext.provider)) testContext.Provider))
return return
} }
@ -127,13 +127,13 @@ var _ = Describe("PD", func() {
podClient.Delete(rwPod.Name) podClient.Delete(rwPod.Name)
podClient.Delete(host0ROPod.Name) podClient.Delete(host0ROPod.Name)
podClient.Delete(host1ROPod.Name) podClient.Delete(host1ROPod.Name)
detachPD(host0Name, diskName, testContext.gceConfig.Zone) detachPD(host0Name, diskName, testContext.GCEConfig.Zone)
detachPD(host1Name, diskName, testContext.gceConfig.Zone) detachPD(host1Name, diskName, testContext.GCEConfig.Zone)
deletePD(diskName, testContext.gceConfig.Zone) deletePD(diskName, testContext.GCEConfig.Zone)
}() }()
By(fmt.Sprintf("creating PD %q", diskName)) By(fmt.Sprintf("creating PD %q", diskName))
expectNoError(createPD(diskName, testContext.gceConfig.Zone), "Error creating PD") expectNoError(createPD(diskName, testContext.GCEConfig.Zone), "Error creating PD")
By("submitting rwPod to ensure PD is formatted") By("submitting rwPod to ensure PD is formatted")
_, err := podClient.Create(rwPod) _, err := podClient.Create(rwPod)
@ -161,7 +161,7 @@ var _ = Describe("PD", func() {
By(fmt.Sprintf("deleting PD %q", diskName)) By(fmt.Sprintf("deleting PD %q", diskName))
for start := time.Now(); time.Since(start) < 180*time.Second; time.Sleep(5 * time.Second) { for start := time.Now(); time.Since(start) < 180*time.Second; time.Sleep(5 * time.Second) {
if err = deletePD(diskName, testContext.gceConfig.Zone); err != nil { if err = deletePD(diskName, testContext.GCEConfig.Zone); err != nil {
Logf("Couldn't delete PD. Sleeping 5 seconds") Logf("Couldn't delete PD. Sleeping 5 seconds")
continue continue
} }

View File

@ -44,12 +44,12 @@ var _ = Describe("ReplicationController", func() {
}) })
It("should serve a basic image on each replica with a private image", func() { It("should serve a basic image on each replica with a private image", func() {
switch testContext.provider { switch testContext.Provider {
case "gce", "gke": case "gce", "gke":
ServeImageOrFail(c, "private", "gcr.io/_b_k8s_authenticated_test/serve_hostname:1.1") ServeImageOrFail(c, "private", "gcr.io/_b_k8s_authenticated_test/serve_hostname:1.1")
default: default:
By(fmt.Sprintf("Skipping private variant, which is only supported for providers gce and gke (not %s)", By(fmt.Sprintf("Skipping private variant, which is only supported for providers gce and gke (not %s)",
testContext.provider)) testContext.Provider))
} }
}) })
}) })

View File

@ -46,7 +46,7 @@ var _ = Describe("Services", func() {
}) })
It("should provide DNS for the cluster", func() { It("should provide DNS for the cluster", func() {
if testContext.provider == "vagrant" { if testContext.Provider == "vagrant" {
By("Skipping test which is broken for vagrant (See https://github.com/GoogleCloudPlatform/kubernetes/issues/3580)") By("Skipping test which is broken for vagrant (See https://github.com/GoogleCloudPlatform/kubernetes/issues/3580)")
return return
} }

View File

@ -41,17 +41,18 @@ const (
podStartTimeout = 5 * time.Minute podStartTimeout = 5 * time.Minute
) )
type testContextType struct { type TestContextType struct {
kubeConfig string KubeConfig string
authConfig string KubeContext string
certDir string AuthConfig string
host string CertDir string
repoRoot string Host string
provider string RepoRoot string
gceConfig GCEConfig Provider string
GCEConfig GCEConfig
} }
var testContext testContextType var testContext TestContextType
func Logf(format string, a ...interface{}) { func Logf(format string, a ...interface{}) {
fmt.Fprintf(GinkgoWriter, "INFO: "+format+"\n", a...) fmt.Fprintf(GinkgoWriter, "INFO: "+format+"\n", a...)
@ -133,32 +134,37 @@ func waitForPodSuccess(c *client.Client, podName string, contName string) error
func loadConfig() (*client.Config, error) { func loadConfig() (*client.Config, error) {
switch { switch {
case testContext.kubeConfig != "": case testContext.KubeConfig != "":
fmt.Printf(">>> testContext.kubeConfig: %s\n", testContext.kubeConfig) fmt.Printf(">>> testContext.KubeConfig: %s\n", testContext.KubeConfig)
c, err := clientcmd.LoadFromFile(testContext.kubeConfig) c, err := clientcmd.LoadFromFile(testContext.KubeConfig)
if err != nil { if err != nil {
return nil, fmt.Errorf("error loading kubeConfig: %v", err.Error()) return nil, fmt.Errorf("error loading KubeConfig: %v", err.Error())
}
if testContext.KubeContext != "" {
fmt.Printf(">>> testContext.KubeContext: %s\n", testContext.KubeContext)
c.CurrentContext = testContext.KubeContext
} }
return clientcmd.NewDefaultClientConfig(*c, &clientcmd.ConfigOverrides{}).ClientConfig() return clientcmd.NewDefaultClientConfig(*c, &clientcmd.ConfigOverrides{}).ClientConfig()
case testContext.authConfig != "": case testContext.AuthConfig != "":
fmt.Printf(">>> testContext.AuthConfig: %s\n", testContext.AuthConfig)
config := &client.Config{ config := &client.Config{
Host: testContext.host, Host: testContext.Host,
} }
info, err := clientauth.LoadFromFile(testContext.authConfig) info, err := clientauth.LoadFromFile(testContext.AuthConfig)
if err != nil { if err != nil {
return nil, fmt.Errorf("error loading authConfig: %v", err.Error()) return nil, fmt.Errorf("error loading AuthConfig: %v", err.Error())
} }
// If the certificate directory is provided, set the cert paths to be there. // If the certificate directory is provided, set the cert paths to be there.
if testContext.certDir != "" { if testContext.CertDir != "" {
Logf("Expecting certs in %v.", testContext.certDir) Logf("Expecting certs in %v.", testContext.CertDir)
info.CAFile = filepath.Join(testContext.certDir, "ca.crt") info.CAFile = filepath.Join(testContext.CertDir, "ca.crt")
info.CertFile = filepath.Join(testContext.certDir, "kubecfg.crt") info.CertFile = filepath.Join(testContext.CertDir, "kubecfg.crt")
info.KeyFile = filepath.Join(testContext.certDir, "kubecfg.key") info.KeyFile = filepath.Join(testContext.CertDir, "kubecfg.key")
} }
mergedConfig, err := info.MergeWithConfig(*config) mergedConfig, err := info.MergeWithConfig(*config)
return &mergedConfig, err return &mergedConfig, err
default: default:
return nil, fmt.Errorf("either kubeConfig or authConfig must be specified to load client config") return nil, fmt.Errorf("either KubeConfig or AuthConfig must be specified to load client config")
} }
} }
@ -267,21 +273,21 @@ func validateController(c *client.Client, containerImage string, replicas int, c
// kubectlCmd runs the kubectl executable. // kubectlCmd runs the kubectl executable.
func kubectlCmd(args ...string) *exec.Cmd { func kubectlCmd(args ...string) *exec.Cmd {
defaultArgs := []string{} defaultArgs := []string{}
if testContext.kubeConfig != "" { if testContext.KubeConfig != "" {
defaultArgs = append(defaultArgs, "--"+clientcmd.RecommendedConfigPathFlag+"="+testContext.kubeConfig) defaultArgs = append(defaultArgs, "--"+clientcmd.RecommendedConfigPathFlag+"="+testContext.KubeConfig)
} else { } else {
defaultArgs = append(defaultArgs, "--"+clientcmd.FlagAuthPath+"="+testContext.authConfig) defaultArgs = append(defaultArgs, "--"+clientcmd.FlagAuthPath+"="+testContext.AuthConfig)
if testContext.certDir != "" { if testContext.CertDir != "" {
defaultArgs = append(defaultArgs, defaultArgs = append(defaultArgs,
fmt.Sprintf("--certificate-authority=%s", filepath.Join(testContext.certDir, "ca.crt")), fmt.Sprintf("--certificate-authority=%s", filepath.Join(testContext.CertDir, "ca.crt")),
fmt.Sprintf("--client-certificate=%s", filepath.Join(testContext.certDir, "kubecfg.crt")), fmt.Sprintf("--client-certificate=%s", filepath.Join(testContext.CertDir, "kubecfg.crt")),
fmt.Sprintf("--client-key=%s", filepath.Join(testContext.certDir, "kubecfg.key"))) fmt.Sprintf("--client-key=%s", filepath.Join(testContext.CertDir, "kubecfg.key")))
} }
} }
kubectlArgs := append(defaultArgs, args...) kubectlArgs := append(defaultArgs, args...)
// TODO: Remove this once gcloud writes a proper entry in the kubeconfig file. // TODO: Remove this once gcloud writes a proper entry in the kubeconfig file.
if testContext.provider == "gke" { if testContext.Provider == "gke" {
kubectlArgs = append(kubectlArgs, "--server="+testContext.host) kubectlArgs = append(kubectlArgs, "--server="+testContext.Host)
} }
//TODO: the "kubectl" path string might be worth externalizing into an (optional) ginko arg. //TODO: the "kubectl" path string might be worth externalizing into an (optional) ginko arg.
cmd := exec.Command("kubectl", kubectlArgs...) cmd := exec.Command("kubectl", kubectlArgs...)