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

@@ -32,14 +32,14 @@ var _ = Describe("MasterCerts", func() {
})
It("should have all expected certs on the master", func() {
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))
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))
return
}
for _, certFile := range []string{"kubecfg.key", "kubecfg.crt", "ca.crt"} {
cmd := exec.Command("gcloud", "compute", "ssh", "--project", testContext.gceConfig.ProjectID,
"--zone", testContext.gceConfig.Zone, testContext.gceConfig.MasterName,
cmd := exec.Command("gcloud", "compute", "ssh", "--project", testContext.GCEConfig.ProjectID,
"--zone", testContext.GCEConfig.Zone, testContext.GCEConfig.MasterName,
"--command", fmt.Sprintf("ls /srv/kubernetes/%s", certFile))
if _, err := cmd.CombinedOutput(); err != nil {
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
// creation of a test cluster.
func RunE2ETests(kubeConfig, authConfig, certDir, host, repoRoot, provider string, gceConfig *GCEConfig, orderseed int64, times int, reportDir string, testList []string) {
testContext = testContextType{kubeConfig, authConfig, certDir, host, repoRoot, provider, *gceConfig}
func RunE2ETests(context *TestContextType, orderseed int64, times int, reportDir string, testList []string) {
testContext = *context
util.ReallyCrash = true
util.InitLogs()
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
// on GCE. Once we are sure that Elasticsearch cluster level logging
// works for other providers we should widen this scope of this test.
if testContext.provider != "gce" {
Logf("Skipping cluster level logging test for provider %s", testContext.provider)
if testContext.Provider != "gce" {
Logf("Skipping cluster level logging test for provider %s", testContext.Provider)
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() {
provider := testContext.provider
provider := testContext.Provider
if len(provider) > 0 && provider != "gce" && provider != "gke" && provider != "aws" {
By(fmt.Sprintf("skipping TestKubeletSendsEvent on cloud provider %s", provider))
return

View File

@@ -53,7 +53,7 @@ var _ = Describe("kubectl", func() {
Describe("update-demo", func() {
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")
kittenPath = filepath.Join(updateDemoRoot, "kitten-rc.yaml")
)
@@ -94,7 +94,7 @@ var _ = Describe("kubectl", 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() {
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() {
if testContext.provider != "gce" {
if testContext.Provider != "gce" {
By(fmt.Sprintf("Skipping Monitoring test, which is only supported for provider gce (not %s)",
testContext.provider))
testContext.Provider))
return
}
testMonitoringUsingHeapsterInfluxdb(c)
@@ -192,7 +192,7 @@ func validatePodsAndNodes(influxdbClient *influxdb.Client, expectedPods, expecte
}
func getMasterHost() string {
masterUrl, err := url.Parse(testContext.host)
masterUrl, err := url.Parse(testContext.Host)
expectNoError(err)
return masterUrl.Host
}

View File

@@ -42,7 +42,7 @@ var _ = Describe("Networking", func() {
ns := "nettest-" + randomSuffix()
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)")
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() {
if testContext.provider != "gce" {
if testContext.Provider != "gce" {
By(fmt.Sprintf("Skipping PD test, which is only supported for provider gce (not %s)",
testContext.provider))
testContext.Provider))
return
}
@@ -65,7 +65,7 @@ var _ = Describe("PD", func() {
host1Pod := testPDPod(diskName, host1Name, false)
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() {
By("cleaning up PD-RW test environment")
@@ -73,9 +73,9 @@ var _ = Describe("PD", func() {
// Teardown should do nothing unless test failed.
podClient.Delete(host0Pod.Name)
podClient.Delete(host1Pod.Name)
detachPD(host0Name, diskName, testContext.gceConfig.Zone)
detachPD(host1Name, diskName, testContext.gceConfig.Zone)
deletePD(diskName, testContext.gceConfig.Zone)
detachPD(host0Name, diskName, testContext.GCEConfig.Zone)
detachPD(host1Name, diskName, testContext.GCEConfig.Zone)
deletePD(diskName, testContext.GCEConfig.Zone)
}()
By("submitting host0Pod to kubernetes")
@@ -98,7 +98,7 @@ var _ = Describe("PD", func() {
By(fmt.Sprintf("deleting PD %q", diskName))
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")
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() {
if testContext.provider != "gce" {
if testContext.Provider != "gce" {
By(fmt.Sprintf("Skipping PD test, which is only supported for provider gce (not %s)",
testContext.provider))
testContext.Provider))
return
}
@@ -127,13 +127,13 @@ var _ = Describe("PD", func() {
podClient.Delete(rwPod.Name)
podClient.Delete(host0ROPod.Name)
podClient.Delete(host1ROPod.Name)
detachPD(host0Name, diskName, testContext.gceConfig.Zone)
detachPD(host1Name, diskName, testContext.gceConfig.Zone)
deletePD(diskName, testContext.gceConfig.Zone)
detachPD(host0Name, diskName, testContext.GCEConfig.Zone)
detachPD(host1Name, diskName, testContext.GCEConfig.Zone)
deletePD(diskName, testContext.GCEConfig.Zone)
}()
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")
_, err := podClient.Create(rwPod)
@@ -161,7 +161,7 @@ var _ = Describe("PD", func() {
By(fmt.Sprintf("deleting PD %q", diskName))
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")
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() {
switch testContext.provider {
switch testContext.Provider {
case "gce", "gke":
ServeImageOrFail(c, "private", "gcr.io/_b_k8s_authenticated_test/serve_hostname:1.1")
default:
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() {
if testContext.provider == "vagrant" {
if testContext.Provider == "vagrant" {
By("Skipping test which is broken for vagrant (See https://github.com/GoogleCloudPlatform/kubernetes/issues/3580)")
return
}

View File

@@ -41,17 +41,18 @@ const (
podStartTimeout = 5 * time.Minute
)
type testContextType struct {
kubeConfig string
authConfig string
certDir string
host string
repoRoot string
provider string
gceConfig GCEConfig
type TestContextType struct {
KubeConfig string
KubeContext string
AuthConfig string
CertDir string
Host string
RepoRoot string
Provider string
GCEConfig GCEConfig
}
var testContext testContextType
var testContext TestContextType
func Logf(format string, a ...interface{}) {
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) {
switch {
case testContext.kubeConfig != "":
fmt.Printf(">>> testContext.kubeConfig: %s\n", testContext.kubeConfig)
c, err := clientcmd.LoadFromFile(testContext.kubeConfig)
case testContext.KubeConfig != "":
fmt.Printf(">>> testContext.KubeConfig: %s\n", testContext.KubeConfig)
c, err := clientcmd.LoadFromFile(testContext.KubeConfig)
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()
case testContext.authConfig != "":
case testContext.AuthConfig != "":
fmt.Printf(">>> testContext.AuthConfig: %s\n", testContext.AuthConfig)
config := &client.Config{
Host: testContext.host,
Host: testContext.Host,
}
info, err := clientauth.LoadFromFile(testContext.authConfig)
info, err := clientauth.LoadFromFile(testContext.AuthConfig)
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 testContext.certDir != "" {
Logf("Expecting certs in %v.", testContext.certDir)
info.CAFile = filepath.Join(testContext.certDir, "ca.crt")
info.CertFile = filepath.Join(testContext.certDir, "kubecfg.crt")
info.KeyFile = filepath.Join(testContext.certDir, "kubecfg.key")
if testContext.CertDir != "" {
Logf("Expecting certs in %v.", testContext.CertDir)
info.CAFile = filepath.Join(testContext.CertDir, "ca.crt")
info.CertFile = filepath.Join(testContext.CertDir, "kubecfg.crt")
info.KeyFile = filepath.Join(testContext.CertDir, "kubecfg.key")
}
mergedConfig, err := info.MergeWithConfig(*config)
return &mergedConfig, err
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.
func kubectlCmd(args ...string) *exec.Cmd {
defaultArgs := []string{}
if testContext.kubeConfig != "" {
defaultArgs = append(defaultArgs, "--"+clientcmd.RecommendedConfigPathFlag+"="+testContext.kubeConfig)
if testContext.KubeConfig != "" {
defaultArgs = append(defaultArgs, "--"+clientcmd.RecommendedConfigPathFlag+"="+testContext.KubeConfig)
} else {
defaultArgs = append(defaultArgs, "--"+clientcmd.FlagAuthPath+"="+testContext.authConfig)
if testContext.certDir != "" {
defaultArgs = append(defaultArgs, "--"+clientcmd.FlagAuthPath+"="+testContext.AuthConfig)
if testContext.CertDir != "" {
defaultArgs = append(defaultArgs,
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-key=%s", filepath.Join(testContext.certDir, "kubecfg.key")))
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-key=%s", filepath.Join(testContext.CertDir, "kubecfg.key")))
}
}
kubectlArgs := append(defaultArgs, args...)
// TODO: Remove this once gcloud writes a proper entry in the kubeconfig file.
if testContext.provider == "gke" {
kubectlArgs = append(kubectlArgs, "--server="+testContext.host)
if testContext.Provider == "gke" {
kubectlArgs = append(kubectlArgs, "--server="+testContext.Host)
}
//TODO: the "kubectl" path string might be worth externalizing into an (optional) ginko arg.
cmd := exec.Command("kubectl", kubectlArgs...)