Skip to content

Instantly share code, notes, and snippets.

@ncdc
Created August 28, 2015 14:50
Show Gist options
  • Save ncdc/4815f60d170adb160c3b to your computer and use it in GitHub Desktop.
Save ncdc/4815f60d170adb160c3b to your computer and use it in GitHub Desktop.
/*
Copyright 2015 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 e2e
import (
"fmt"
"path/filepath"
"k8s.io/kubernetes/pkg/api"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/util"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
const ()
var _ = Describe("Remote command execution", func() {
defer GinkgoRecover()
var c *client.Client
var ns string
var testingNs *api.Namespace
BeforeEach(func() {
var err error
c, err = loadClient()
expectNoError(err)
testingNs, err = createTestingNS("kubectl", c)
Expect(err).NotTo(HaveOccurred())
ns = testingNs.Name
})
AfterEach(func() {
By(fmt.Sprintf("Destroying namespace for this suite %v", ns))
if err := deleteNS(c, ns); err != nil {
Failf("Couldn't delete ns %s", err)
}
})
Describe("Using a proxy", func() {
BeforeEach(func() {
podPath := filepath.Join(testContext.RepoRoot, "docs/user-guide/pod.yaml")
By("creating the nginx pod")
runKubectl("create", "-f", podPath, fmt.Sprintf("--namespace=%v", ns))
checkPodsRunningReady(c, ns, []string{simplePodName}, podStartTimeout)
By("creating the proxy pod")
//runKubectl("create", "-f", podPath, fmt.Sprintf("--namespace=%v", ns))
podName := "proxy-" + string(util.NewUUID())
pod := &api.Pod{
ObjectMeta: api.ObjectMeta{
Name: podName,
Labels: map[string]string{"name": podName},
},
Spec: api.PodSpec{
Containers: []api.Container{
{
Name: "test-proxy",
Image: "ncdc/goproxy",
},
},
RestartPolicy: api.RestartPolicyNever,
},
}
if _, err := c.Pods(ns).Create(pod); err != nil {
Failf("Error creating proxy pod: %v", err)
}
checkPodsRunningReady(c, ns, []string{podName}, podStartTimeout)
pod, err := c.Pods(ns).Get(podName)
if err != nil {
Failf("Error getting proxy pod: %v", err)
}
//pod.Status.PodIP
})
AfterEach(func() {
//cleanup(podPath, ns, simplePodSelector)
})
It("should support exec", func() {
By("executing a command in the container using an http proxy")
execOutput := newKubectlCommand("exec", fmt.Sprintf("--namespace=%v", ns), simplePodName, "echo", "running", "in", "container").
withEnv("http_proxy=").
exec()
expectedExecOutput := "running in container"
if execOutput != expectedExecOutput {
Failf("Unexpected kubectl exec output. Wanted '%s', got '%s'", execOutput, expectedExecOutput)
}
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment