Add glide.yaml and vendor deps

This commit is contained in:
Dalton Hubble 2016-12-03 22:43:32 -08:00
parent db918f12ad
commit 5b3d5e81bd
18880 changed files with 5166045 additions and 1 deletions

View file

@ -0,0 +1,17 @@
package(default_visibility = ["//visibility:public"])
licenses(["notice"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_binary",
"go_library",
"go_test",
"cgo_library",
)
go_binary(
name = "serve_hostname",
srcs = ["serve_hostname.go"],
tags = ["automanaged"],
)

View file

@ -0,0 +1,19 @@
# Copyright 2016 The Kubernetes Authors.
#
# 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 BASEIMAGE
MAINTAINER Tim Hockin <thockin@google.com>
ADD serve_hostname /serve_hostname
EXPOSE 9376
ENTRYPOINT ["/serve_hostname"]

View file

@ -0,0 +1,100 @@
# Copyright 2016 The Kubernetes Authors.
#
# 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.
# Cross-build the serve_hostname image
#
# Usage:
# [TAG=v1.5] [PREFIX=gcr.io/google_containers] [TEST_REGISTRY=b.gcr.io/k8s_authenticated_test] [ARCH=amd64] [BASEIMAGE=busybox] make all
.PHONY: all push container clean
TAG ?= v1.5
REGISTRY ?= gcr.io/google_containers
TEST_REGISTRY ?= b.gcr.io/k8s_authenticated_test
# Architectures supported: amd64, arm, arm64 and ppc64le
ARCH ?= amd64
ALL_ARCH = amd64 arm arm64 ppc64le
GOARM=6
TEMP_DIR := $(shell mktemp -d)
GOLANG_VERSION = 1.6.3
BIN = serve_hostname
SRCS = serve_hostname.go
IMAGE = $(REGISTRY)/$(BIN)-$(ARCH)
TEST_IMAGE = $(TEST_REGISTRY)/$(BIN)-$(ARCH)
# Set default base image dynamically for each arch
ifeq ($(ARCH),amd64)
BASEIMAGE?=busybox
endif
ifeq ($(ARCH),arm)
BASEIMAGE?=armel/busybox
endif
ifeq ($(ARCH),arm64)
BASEIMAGE?=aarch64/busybox
endif
ifeq ($(ARCH),ppc64le)
BASEIMAGE?=ppc64le/busybox
endif
# If you want to build AND push all containers, see the 'all-push' rule.
all: all-container
sub-container-%:
$(MAKE) ARCH=$* container
sub-push-%:
$(MAKE) ARCH=$* push
all-container: $(addprefix sub-container-,$(ALL_ARCH))
all-push: $(addprefix sub-push-,$(ALL_ARCH))
build: bin/$(BIN)-$(ARCH)
bin/$(BIN)-$(ARCH): $(SRCS)
# Copy the content in this dir to the temp dir
cp ./* $(TEMP_DIR)
docker run -it -v $(TEMP_DIR):/build \
golang:$(GOLANG_VERSION) \
/bin/bash -c "\
cd /build && \
CGO_ENABLED=0 GOARM=$(GOARM) GOARCH=$(ARCH) go build -a -installsuffix cgo --ldflags '-w' -o $(BIN) ./$(SRCS)"
container: .container-$(ARCH)
.container-$(ARCH): bin/$(BIN)-$(ARCH)
# Set the base image
cd $(TEMP_DIR) && sed -i.bak 's|BASEIMAGE|$(BASEIMAGE)|g' Dockerfile
docker build -t $(IMAGE):$(TAG) $(TEMP_DIR)
if [ -n "$(TEST_REGISTRY)" ]; then \
docker tag $(IMAGE):$(TAG) $(TEST_IMAGE):$(TAG) ;\
fi
push: .push-$(ARCH)
.push-$(ARCH): .container-$(ARCH)
gcloud docker -- push $(IMAGE):$(TAG)
if [ -n "$(TEST_REGISTRY)" ]; then \
gcloud docker -- push $(TEST_IMAGE):$(TAG) ;\
fi
clean:
rm -rf $(BIN)

View file

@ -0,0 +1,36 @@
## serve_hostname
This is a small util app to serve your hostname on TCP and/or UDP. Useful for testing.
The `serve_hostname` Makefile supports multiple architectures, which means it may cross-compile and build an docker image easily.
Arch-specific busybox images serve as base images.
If you are releasing a new version, please bump the `TAG` value in the `Makefile` before building the images.
## How to release:
```
# Build cross-platform binaries
$ make all-push
# Build for linux/amd64 (default)
$ make push ARCH=amd64
# ---> gcr.io/google_containers/serve_hostname-amd64:TAG
$ make push ARCH=arm
# ---> gcr.io/google_containers/serve_hostname-arm:TAG
$ make push ARCH=arm64
# ---> gcr.io/google_containers/serve_hostname-arm64:TAG
$ make push ARCH=ppc64le
# ---> gcr.io/google_containers/serve_hostname-ppc64le:TAG
```
Of course, if you don't want to push the images, run `make all-container` or `make container ARCH={target_arch}` instead.
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/contrib/for-demos/serve_hostname/README.md?pixel)]()
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/test/images/serve_hostname/README.md?pixel)]()

View file

@ -0,0 +1,105 @@
/*
Copyright 2014 The Kubernetes Authors.
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 small utility to just serve the hostname on TCP and/or UDP.
package main
import (
"flag"
"fmt"
"log"
"net"
"net/http"
"os"
"os/signal"
"syscall"
)
var (
doTCP = flag.Bool("tcp", false, "Serve raw over TCP.")
doUDP = flag.Bool("udp", false, "Serve raw over UDP.")
doHTTP = flag.Bool("http", true, "Serve HTTP.")
port = flag.Int("port", 9376, "Port number.")
)
func main() {
flag.Parse()
if *doHTTP && (*doTCP || *doUDP) {
log.Fatalf("Can't server TCP/UDP mode and HTTP mode at the same time")
}
hostname, err := os.Hostname()
if err != nil {
log.Fatalf("Error from os.Hostname(): %s", err)
}
if *doTCP {
listener, err := net.Listen("tcp", fmt.Sprintf(":%d", *port))
if err != nil {
log.Fatalf("Error from net.Listen(): %s", err)
}
go func() {
for {
conn, err := listener.Accept()
if err != nil {
log.Fatalf("Error from Accept(): %s", err)
}
log.Printf("TCP request from %s", conn.RemoteAddr().String())
conn.Write([]byte(hostname))
conn.Close()
}
}()
}
if *doUDP {
addr, err := net.ResolveUDPAddr("udp", fmt.Sprintf(":%d", *port))
if err != nil {
log.Fatalf("Error from net.ResolveUDPAddr(): %s", err)
}
sock, err := net.ListenUDP("udp", addr)
if err != nil {
log.Fatalf("Error from ListenUDP(): %s", err)
}
go func() {
var buffer [16]byte
for {
_, cliAddr, err := sock.ReadFrom(buffer[0:])
if err != nil {
log.Fatalf("Error from ReadFrom(): %s", err)
}
log.Printf("UDP request from %s", cliAddr.String())
sock.WriteTo([]byte(hostname), cliAddr)
}
}()
}
if *doHTTP {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
log.Printf("HTTP request from %s", r.RemoteAddr)
fmt.Fprintf(w, "%s", hostname)
})
go func() {
// Run in a closure so http.ListenAndServe doesn't block
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), nil))
}()
}
// Write to stdout after receiving SIGTERM and SIGINT to help with debugging kubernetes issue #21605
signals := make(chan os.Signal)
signal.Notify(signals, syscall.SIGTERM, syscall.SIGINT)
sig := <-signals
// Keep behavior consistent with how the signal is handled by default (default is to panic)
log.Panicf("Terminating after receiving signal: %s.\n", sig)
}