Revert "Remove host ports from the update demo and update tests"

This commit is contained in:
Zach Loafman
2015-02-25 09:56:03 -08:00
parent ea62dbff1c
commit 84a2a9766a
9 changed files with 56 additions and 74 deletions

View File

@@ -35,34 +35,13 @@ const (
kittenImage = "kubernetes/update-demo:kitten"
updateDemoSelector = "name=update-demo"
updateDemoContainer = "update-demo"
kubectlProxyPort = 8011
)
var _ = Describe("kubectl", func() {
// Constants.
var (
updateDemoRoot = filepath.Join(root, "examples/update-demo")
nautilusPath = filepath.Join(updateDemoRoot, "nautilus-rc.yaml")
kittenPath = filepath.Join(updateDemoRoot, "kitten-rc.yaml")
)
var cmd *exec.Cmd
BeforeEach(func() {
cmd = kubectlCmd("proxy", fmt.Sprintf("--port=%d", kubectlProxyPort))
if err := cmd.Start(); err != nil {
Failf("Unable to start kubectl proxy: %v", err)
}
})
AfterEach(func() {
// Kill the proxy
if cmd.Process != nil {
Logf("Stopping kubectl proxy (pid %d)", cmd.Process.Pid)
cmd.Process.Kill()
}
})
updateDemoRoot := filepath.Join(root, "examples/update-demo")
nautilusPath := filepath.Join(updateDemoRoot, "nautilus-rc.yaml")
kittenPath := filepath.Join(updateDemoRoot, "kitten-rc.yaml")
It("should create and stop a replication controller", func() {
defer cleanup(nautilusPath)
@@ -127,6 +106,8 @@ func validateController(image string, replicas int, timeout time.Duration) {
getImageTemplate := fmt.Sprintf(`--template={{(index .currentState.info "%s").image}}`, updateDemoContainer)
getHostIPTemplate := "--template={{.currentState.hostIP}}"
By(fmt.Sprintf("waiting for all containers in %s pods to come up.", updateDemoSelector))
for start := time.Now(); time.Since(start) < timeout; time.Sleep(5 * time.Second) {
getPodsOutput := runKubectl("get", "pods", "-o", "template", getPodsTemplate, "-l", updateDemoSelector)
@@ -136,31 +117,32 @@ func validateController(image string, replicas int, timeout time.Duration) {
continue
}
var runningPods []string
for _, podID := range pods {
running := runKubectl("get", "pods", podID, "-o", "template", getContainerStateTemplate)
for _, podId := range pods {
running := runKubectl("get", "pods", podId, "-o", "template", getContainerStateTemplate)
if running == "false" {
Logf("%s is created but not running", podID)
By(fmt.Sprintf("%s is created but not running", podId))
continue
}
currentImage := runKubectl("get", "pods", podID, "-o", "template", getImageTemplate)
currentImage := runKubectl("get", "pods", podId, "-o", "template", getImageTemplate)
if currentImage != image {
Logf("%s is created but running wrong image; expected: %s, actual: %s", podID, image, currentImage)
By(fmt.Sprintf("%s is created but running wrong image; expected: %s, actual: %s", podId, image, currentImage))
continue
}
data, err := getData(podID)
hostIP := runKubectl("get", "pods", podId, "-o", "template", getHostIPTemplate)
data, err := getData(hostIP)
if err != nil {
Logf("%s is running right image but fetching data failed: %v", podID, err)
By(fmt.Sprintf("%s is running right image but fetching data failed: %v", podId, err))
continue
}
if strings.Contains(data.image, image) {
Logf("%s is running right image but fetched data has the wrong info: %s", podID, data)
By(fmt.Sprintf("%s is running right image but fetched data has the wrong info: %s", podId, data))
continue
}
Logf("%s is verified up and running", podID)
runningPods = append(runningPods, podID)
Logf("%s is verified up and running", podId)
runningPods = append(runningPods, podId)
}
if len(runningPods) == replicas {
return
@@ -173,8 +155,9 @@ type updateDemoData struct {
image string `json:"image"`
}
func getData(podID string) (*updateDemoData, error) {
resp, err := http.Get(fmt.Sprintf("http://localhost:%d/api/v1beta1/proxy/pods/%s/data.json", kubectlProxyPort, podID))
func getData(hostIP string) (*updateDemoData, error) {
addr := fmt.Sprintf("http://%s:8080/data.json", hostIP)
resp, err := http.Get(fmt.Sprintf(addr))
if err != nil || resp.StatusCode != 200 {
return nil, err
}
@@ -189,17 +172,16 @@ func getData(podID string) (*updateDemoData, error) {
return &data, err
}
func kubectlCmd(args ...string) *exec.Cmd {
func runKubectl(args ...string) string {
// TODO: use kubectl binary directly instead of shell wrapper
path := filepath.Join(root, "cluster/kubectl.sh")
Logf("Running '%v'", path+" "+strings.Join(args, " "))
return exec.Command(path, args...)
}
cmdStr := path + " " + strings.Join(args, " ")
Logf("Running '%v'", cmdStr)
func runKubectl(args ...string) string {
cmd := exec.Command(path, args...)
var stdout, stderr bytes.Buffer
cmd := kubectlCmd(args...)
cmd.Stdout, cmd.Stderr = &stdout, &stderr
cmd.Stdout = &stdout
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
Failf("Error running %v:\nCommand stdout:\n%v\nstderr:\n%v\n", cmd, cmd.Stdout, cmd.Stderr)