mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-06 02:34:03 +00:00
add 'porter' test container
This commit is contained in:
parent
cdef8ae844
commit
1a1307765c
2
contrib/for-tests/porter/.gitignore
vendored
Normal file
2
contrib/for-tests/porter/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
porter
|
||||||
|
.tag
|
18
contrib/for-tests/porter/Dockerfile
Normal file
18
contrib/for-tests/porter/Dockerfile
Normal file
@ -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 <dbsmith@google.com>
|
||||||
|
ADD porter porter
|
||||||
|
ENTRYPOINT ["/porter"]
|
32
contrib/for-tests/porter/Makefile
Normal file
32
contrib/for-tests/porter/Makefile
Normal file
@ -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
|
5
contrib/for-tests/porter/README.md
Normal file
5
contrib/for-tests/porter/README.md
Normal file
@ -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.
|
||||||
|
|
||||||
|
|
||||||
|
[]()
|
53
contrib/for-tests/porter/pod.json
Normal file
53
contrib/for-tests/porter/pod.json
Normal file
@ -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": {}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
BIN
contrib/for-tests/porter/porter
Executable file
BIN
contrib/for-tests/porter/porter
Executable file
Binary file not shown.
56
contrib/for-tests/porter/porter.go
Normal file
56
contrib/for-tests/porter/porter.go
Normal file
@ -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())
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user