diff --git a/contrib/for-tests/porter/.gitignore b/contrib/for-tests/porter/.gitignore new file mode 100644 index 00000000000..c6f989a1ac4 --- /dev/null +++ b/contrib/for-tests/porter/.gitignore @@ -0,0 +1,2 @@ +porter +.tag diff --git a/contrib/for-tests/porter/Dockerfile b/contrib/for-tests/porter/Dockerfile new file mode 100644 index 00000000000..48a47c28778 --- /dev/null +++ b/contrib/for-tests/porter/Dockerfile @@ -0,0 +1,18 @@ +# Copyright 2015 Google Inc. 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. + +FROM scratch +MAINTAINER Daniel Smith +ADD porter porter +ENTRYPOINT ["/porter"] diff --git a/contrib/for-tests/porter/Makefile b/contrib/for-tests/porter/Makefile new file mode 100644 index 00000000000..290fb6d7b23 --- /dev/null +++ b/contrib/for-tests/porter/Makefile @@ -0,0 +1,32 @@ +# Use: +# +# `make porter` will build porter. +# `make tag` will suggest a tag. +# `make container` will build a container-- you must supply a tag. +# `make push` will push the container-- you must supply a tag. + +REPO ?= gcr.io/google_containers + +porter: porter.go + CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-w' ./porter.go + +.tag: porter + md5sum porter | cut -d " " -f 1 > .tag + +tag: .tag + @echo "Suggest using TAG=$(shell cat .tag)" + @echo "$$ make container TAG=$(shell cat .tag)" + @echo "or" + @echo "$$ make push TAG=$(shell cat .tag)" + +container: + $(if $(TAG),,$(error TAG is not defined. Use 'make tag' to see a suggestion)) + docker build -t $(REPO)/porter:$(TAG) . + +push: + $(if $(TAG),,$(error TAG is not defined. Use 'make tag' to see a suggestion)) + gcloud preview docker push $(REPO)/porter:$(TAG) + +clean: + rm -f porter + rm -f .tag diff --git a/contrib/for-tests/porter/README.md b/contrib/for-tests/porter/README.md new file mode 100644 index 00000000000..30923d7241e --- /dev/null +++ b/contrib/for-tests/porter/README.md @@ -0,0 +1,5 @@ +This directory contains go source, Dockerfile and Makefile for making a test +container which serves requested data on ports specified in ENV variables. + + +[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/contrib/for-tests/porter/README.md?pixel)]() diff --git a/contrib/for-tests/porter/pod.json b/contrib/for-tests/porter/pod.json new file mode 100644 index 00000000000..ed0ec6599c3 --- /dev/null +++ b/contrib/for-tests/porter/pod.json @@ -0,0 +1,53 @@ +{ + "kind": "Pod", + "apiVersion": "v1", + "metadata": { + "name": "kubectl-tester" + }, + "spec": { + "containers": [ + { + "name": "bb", + "image": "gcr.io/google_containers/busybox", + "command": [ + "sh", "-c", "sleep 5; wget -O - ${KUBERNETES_RO_SERVICE_HOST}:${KUBERNETES_RO_SERVICE_PORT}/api/v1/pods/; sleep 10000" + ], + "ports": [ + { + "containerPort": 8080 + } + ], + "env": [ + { + "name": "KUBERNETES_RO_SERVICE_HOST", + "value": "127.0.0.1" + }, + { + "name": "KUBERNETES_RO_SERVICE_PORT", + "value": "8001" + } + ], + "volumeMounts": [ + { + "name": "test-volume", + "mountPath": "/mount/test-volume" + } + ] + }, + { + "name": "kubectl", + "image": "gcr.io/google_containers/kubectl:v0.18.0-120-gaeb4ac55ad12b1-dirty", + "imagePullPolicy": "Always", + "args": [ + "proxy", "-p", "8001" + ] + } + ], + "volumes": [ + { + "name": "test-volume", + "emptyDir": {} + } + ] + } +} diff --git a/contrib/for-tests/porter/porter b/contrib/for-tests/porter/porter new file mode 100755 index 00000000000..44d19c3e6b6 Binary files /dev/null and b/contrib/for-tests/porter/porter differ diff --git a/contrib/for-tests/porter/porter.go b/contrib/for-tests/porter/porter.go new file mode 100644 index 00000000000..1e5a3f35e35 --- /dev/null +++ b/contrib/for-tests/porter/porter.go @@ -0,0 +1,56 @@ +/* +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. +*/ + +// A tiny binary for testing ports. +// +// Reads env vars; for every var of the form SERVE_PORT_X, where X is a valid +// port number, porter starts an HTTP server which serves the env var's value +// in response to any query. +package main + +import ( + "fmt" + "log" + "net/http" + "os" + "strings" +) + +const prefix = "SERVE_PORT_" + +func main() { + for _, vk := range os.Environ() { + parts := strings.Split(vk, "=") + key := parts[0] + value := parts[1] + if strings.HasPrefix(key, prefix) { + port := strings.TrimPrefix(key, prefix) + go servePort(port, value) + } + } + + select {} +} + +func servePort(port, value string) { + s := &http.Server{ + Addr: "0.0.0.0:" + port, + Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + fmt.Fprint(w, value) + }), + } + log.Printf("server on port %q failed: %v", port, s.ListenAndServe()) +}