Switch to github.com/golang/dep for vendoring
Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
This commit is contained in:
parent
d6ab91be27
commit
8e5b17cf13
15431 changed files with 3971413 additions and 8881 deletions
1
vendor/k8s.io/kubernetes/examples/guestbook-go/.gitignore
generated
vendored
Normal file
1
vendor/k8s.io/kubernetes/examples/guestbook-go/.gitignore
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
guestbook_bin
|
39
vendor/k8s.io/kubernetes/examples/guestbook-go/BUILD
generated
vendored
Normal file
39
vendor/k8s.io/kubernetes/examples/guestbook-go/BUILD
generated
vendored
Normal file
|
@ -0,0 +1,39 @@
|
|||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
licenses(["notice"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_binary",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_binary(
|
||||
name = "guestbook-go",
|
||||
library = ":go_default_library",
|
||||
tags = ["automanaged"],
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["main.go"],
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//vendor:github.com/codegangsta/negroni",
|
||||
"//vendor:github.com/gorilla/mux",
|
||||
"//vendor:github.com/xyproto/simpleredis",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
)
|
24
vendor/k8s.io/kubernetes/examples/guestbook-go/Dockerfile
generated
vendored
Normal file
24
vendor/k8s.io/kubernetes/examples/guestbook-go/Dockerfile
generated
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
# 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 busybox:ubuntu-14.04
|
||||
|
||||
ADD ./guestbook_bin /app/guestbook
|
||||
ADD ./public/index.html /app/public/index.html
|
||||
ADD ./public/script.js /app/public/script.js
|
||||
ADD ./public/style.css /app/public/style.css
|
||||
|
||||
WORKDIR /app
|
||||
CMD ["./guestbook"]
|
||||
EXPOSE 3000
|
41
vendor/k8s.io/kubernetes/examples/guestbook-go/Makefile
generated
vendored
Normal file
41
vendor/k8s.io/kubernetes/examples/guestbook-go/Makefile
generated
vendored
Normal file
|
@ -0,0 +1,41 @@
|
|||
# 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.
|
||||
|
||||
# Build the guestbook-go example
|
||||
|
||||
# Usage:
|
||||
# [VERSION=v3] [REGISTRY="gcr.io/google_containers"] make build
|
||||
VERSION?=v3
|
||||
REGISTRY?=gcr.io/google_containers
|
||||
|
||||
release: clean build push clean
|
||||
|
||||
# builds a docker image that builds the app and packages it into a minimal docker image
|
||||
build:
|
||||
@cp ../../bazel-bin/examples/guestbook-go/guestbook-go guestbook_bin
|
||||
docker build --pull --rm --force-rm -t ${REGISTRY}/guestbook-builder .
|
||||
docker run --rm ${REGISTRY}/guestbook-builder | docker build --pull -t "${REGISTRY}/guestbook:${VERSION}" -
|
||||
|
||||
# push the image to an registry
|
||||
push:
|
||||
gcloud docker -- push ${REGISTRY}/guestbook:${VERSION}
|
||||
|
||||
# remove previous images and containers
|
||||
clean:
|
||||
rm -f guestbook_bin
|
||||
docker rm -f ${REGISTRY}/guestbook-builder 2> /dev/null || true
|
||||
docker rmi -f ${REGISTRY}/guestbook-builder || true
|
||||
docker rmi -f "${REGISTRY}/guestbook:${VERSION}" || true
|
||||
|
||||
.PHONY: release clean build push
|
271
vendor/k8s.io/kubernetes/examples/guestbook-go/README.md
generated
vendored
Normal file
271
vendor/k8s.io/kubernetes/examples/guestbook-go/README.md
generated
vendored
Normal file
|
@ -0,0 +1,271 @@
|
|||
## Guestbook Example
|
||||
|
||||
This example shows how to build a simple multi-tier web application using Kubernetes and Docker. The application consists of a web front-end, Redis master for storage, and replicated set of Redis slaves, all for which we will create Kubernetes replication controllers, pods, and services.
|
||||
|
||||
If you are running a cluster in Google Container Engine (GKE), instead see the [Guestbook Example for Google Container Engine](https://cloud.google.com/container-engine/docs/tutorials/guestbook).
|
||||
|
||||
##### Table of Contents
|
||||
|
||||
* [Step Zero: Prerequisites](#step-zero)
|
||||
* [Step One: Create the Redis master pod](#step-one)
|
||||
* [Step Two: Create the Redis master service](#step-two)
|
||||
* [Step Three: Create the Redis slave pods](#step-three)
|
||||
* [Step Four: Create the Redis slave service](#step-four)
|
||||
* [Step Five: Create the guestbook pods](#step-five)
|
||||
* [Step Six: Create the guestbook service](#step-six)
|
||||
* [Step Seven: View the guestbook](#step-seven)
|
||||
* [Step Eight: Cleanup](#step-eight)
|
||||
|
||||
### Step Zero: Prerequisites <a id="step-zero"></a>
|
||||
|
||||
This example assumes that you have a working cluster. See the [Getting Started Guides](../../docs/getting-started-guides/) for details about creating a cluster.
|
||||
|
||||
**Tip:** View all the `kubectl` commands, including their options and descriptions in the [kubectl CLI reference](../../docs/user-guide/kubectl/kubectl.md).
|
||||
|
||||
### Step One: Create the Redis master pod<a id="step-one"></a>
|
||||
|
||||
Use the `examples/guestbook-go/redis-master-controller.json` file to create a [replication controller](../../docs/user-guide/replication-controller.md) and Redis master [pod](../../docs/user-guide/pods.md). The pod runs a Redis key-value server in a container. Using a replication controller is the preferred way to launch long-running pods, even for 1 replica, so that the pod benefits from the self-healing mechanism in Kubernetes (keeps the pods alive).
|
||||
|
||||
1. Use the [redis-master-controller.json](redis-master-controller.json) file to create the Redis master replication controller in your Kubernetes cluster by running the `kubectl create -f` *`filename`* command:
|
||||
|
||||
```console
|
||||
$ kubectl create -f examples/guestbook-go/redis-master-controller.json
|
||||
replicationcontrollers/redis-master
|
||||
```
|
||||
|
||||
2. To verify that the redis-master controller is up, list the replication controllers you created in the cluster with the `kubectl get rc` command(if you don't specify a `--namespace`, the `default` namespace will be used. The same below):
|
||||
|
||||
```console
|
||||
$ kubectl get rc
|
||||
CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS
|
||||
redis-master redis-master gurpartap/redis app=redis,role=master 1
|
||||
...
|
||||
```
|
||||
|
||||
Result: The replication controller then creates the single Redis master pod.
|
||||
|
||||
3. To verify that the redis-master pod is running, list the pods you created in cluster with the `kubectl get pods` command:
|
||||
|
||||
```console
|
||||
$ kubectl get pods
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
redis-master-xx4uv 1/1 Running 0 1m
|
||||
...
|
||||
```
|
||||
|
||||
Result: You'll see a single Redis master pod and the machine where the pod is running after the pod gets placed (may take up to thirty seconds).
|
||||
|
||||
4. To verify what containers are running in the redis-master pod, you can SSH to that machine with `gcloud compute ssh --zone` *`zone_name`* *`host_name`* and then run `docker ps`:
|
||||
|
||||
```console
|
||||
me@workstation$ gcloud compute ssh --zone us-central1-b kubernetes-node-bz1p
|
||||
|
||||
me@kubernetes-node-3:~$ sudo docker ps
|
||||
CONTAINER ID IMAGE COMMAND CREATED STATUS
|
||||
d5c458dabe50 redis "/entrypoint.sh redis" 5 minutes ago Up 5 minutes
|
||||
```
|
||||
|
||||
Note: The initial `docker pull` can take a few minutes, depending on network conditions.
|
||||
|
||||
### Step Two: Create the Redis master service <a id="step-two"></a>
|
||||
|
||||
A Kubernetes [service](../../docs/user-guide/services.md) is a named load balancer that proxies traffic to one or more pods. The services in a Kubernetes cluster are discoverable inside other pods via environment variables or DNS.
|
||||
|
||||
Services find the pods to load balance based on pod labels. The pod that you created in Step One has the label `app=redis` and `role=master`. The selector field of the service determines which pods will receive the traffic sent to the service.
|
||||
|
||||
1. Use the [redis-master-service.json](redis-master-service.json) file to create the service in your Kubernetes cluster by running the `kubectl create -f` *`filename`* command:
|
||||
|
||||
```console
|
||||
$ kubectl create -f examples/guestbook-go/redis-master-service.json
|
||||
services/redis-master
|
||||
```
|
||||
|
||||
2. To verify that the redis-master service is up, list the services you created in the cluster with the `kubectl get services` command:
|
||||
|
||||
```console
|
||||
$ kubectl get services
|
||||
NAME CLUSTER_IP EXTERNAL_IP PORT(S) SELECTOR AGE
|
||||
redis-master 10.0.136.3 <none> 6379/TCP app=redis,role=master 1h
|
||||
...
|
||||
```
|
||||
|
||||
Result: All new pods will see the `redis-master` service running on the host (`$REDIS_MASTER_SERVICE_HOST` environment variable) at port 6379, or running on `redis-master:6379`. After the service is created, the service proxy on each node is configured to set up a proxy on the specified port (in our example, that's port 6379).
|
||||
|
||||
|
||||
### Step Three: Create the Redis slave pods <a id="step-three"></a>
|
||||
|
||||
The Redis master we created earlier is a single pod (REPLICAS = 1), while the Redis read slaves we are creating here are 'replicated' pods. In Kubernetes, a replication controller is responsible for managing the multiple instances of a replicated pod.
|
||||
|
||||
1. Use the file [redis-slave-controller.json](redis-slave-controller.json) to create the replication controller by running the `kubectl create -f` *`filename`* command:
|
||||
|
||||
```console
|
||||
$ kubectl create -f examples/guestbook-go/redis-slave-controller.json
|
||||
replicationcontrollers/redis-slave
|
||||
```
|
||||
|
||||
2. To verify that the redis-slave controller is running, run the `kubectl get rc` command:
|
||||
|
||||
```console
|
||||
$ kubectl get rc
|
||||
CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS
|
||||
redis-master redis-master redis app=redis,role=master 1
|
||||
redis-slave redis-slave kubernetes/redis-slave:v2 app=redis,role=slave 2
|
||||
...
|
||||
```
|
||||
|
||||
Result: The replication controller creates and configures the Redis slave pods through the redis-master service (name:port pair, in our example that's `redis-master:6379`).
|
||||
|
||||
Example:
|
||||
The Redis slaves get started by the replication controller with the following command:
|
||||
|
||||
```console
|
||||
redis-server --slaveof redis-master 6379
|
||||
```
|
||||
|
||||
3. To verify that the Redis master and slaves pods are running, run the `kubectl get pods` command:
|
||||
|
||||
```console
|
||||
$ kubectl get pods
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
redis-master-xx4uv 1/1 Running 0 18m
|
||||
redis-slave-b6wj4 1/1 Running 0 1m
|
||||
redis-slave-iai40 1/1 Running 0 1m
|
||||
...
|
||||
```
|
||||
|
||||
Result: You see the single Redis master and two Redis slave pods.
|
||||
|
||||
### Step Four: Create the Redis slave service <a id="step-four"></a>
|
||||
|
||||
Just like the master, we want to have a service to proxy connections to the read slaves. In this case, in addition to discovery, the Redis slave service provides transparent load balancing to clients.
|
||||
|
||||
1. Use the [redis-slave-service.json](redis-slave-service.json) file to create the Redis slave service by running the `kubectl create -f` *`filename`* command:
|
||||
|
||||
```console
|
||||
$ kubectl create -f examples/guestbook-go/redis-slave-service.json
|
||||
services/redis-slave
|
||||
```
|
||||
|
||||
2. To verify that the redis-slave service is up, list the services you created in the cluster with the `kubectl get services` command:
|
||||
|
||||
```console
|
||||
$ kubectl get services
|
||||
NAME CLUSTER_IP EXTERNAL_IP PORT(S) SELECTOR AGE
|
||||
redis-master 10.0.136.3 <none> 6379/TCP app=redis,role=master 1h
|
||||
redis-slave 10.0.21.92 <none> 6379/TCP app-redis,role=slave 1h
|
||||
...
|
||||
```
|
||||
|
||||
Result: The service is created with labels `app=redis` and `role=slave` to identify that the pods are running the Redis slaves.
|
||||
|
||||
Tip: It is helpful to set labels on your services themselves--as we've done here--to make it easy to locate them later.
|
||||
|
||||
### Step Five: Create the guestbook pods <a id="step-five"></a>
|
||||
|
||||
This is a simple Go `net/http` ([negroni](https://github.com/codegangsta/negroni) based) server that is configured to talk to either the slave or master services depending on whether the request is a read or a write. The pods we are creating expose a simple JSON interface and serves a jQuery-Ajax based UI. Like the Redis read slaves, these pods are also managed by a replication controller.
|
||||
|
||||
1. Use the [guestbook-controller.json](guestbook-controller.json) file to create the guestbook replication controller by running the `kubectl create -f` *`filename`* command:
|
||||
|
||||
```console
|
||||
$ kubectl create -f examples/guestbook-go/guestbook-controller.json
|
||||
replicationcontrollers/guestbook
|
||||
```
|
||||
|
||||
Tip: If you want to modify the guestbook code open the `_src` of this example and read the README.md and the Makefile. If you have pushed your custom image be sure to update the `image` accordingly in the guestbook-controller.json.
|
||||
|
||||
2. To verify that the guestbook replication controller is running, run the `kubectl get rc` command:
|
||||
|
||||
```console
|
||||
$ kubectl get rc
|
||||
CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS
|
||||
guestbook guestbook gcr.io/google_containers/guestbook:v3 app=guestbook 3
|
||||
redis-master redis-master redis app=redis,role=master 1
|
||||
redis-slave redis-slave kubernetes/redis-slave:v2 app=redis,role=slave 2
|
||||
...
|
||||
```
|
||||
|
||||
3. To verify that the guestbook pods are running (it might take up to thirty seconds to create the pods), list the pods you created in cluster with the `kubectl get pods` command:
|
||||
|
||||
```console
|
||||
$ kubectl get pods
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
guestbook-3crgn 1/1 Running 0 2m
|
||||
guestbook-gv7i6 1/1 Running 0 2m
|
||||
guestbook-x405a 1/1 Running 0 2m
|
||||
redis-master-xx4uv 1/1 Running 0 23m
|
||||
redis-slave-b6wj4 1/1 Running 0 6m
|
||||
redis-slave-iai40 1/1 Running 0 6m
|
||||
...
|
||||
```
|
||||
|
||||
Result: You see a single Redis master, two Redis slaves, and three guestbook pods.
|
||||
|
||||
### Step Six: Create the guestbook service <a id="step-six"></a>
|
||||
|
||||
Just like the others, we create a service to group the guestbook pods but this time, to make the guestbook front-end externally visible, we specify `"type": "LoadBalancer"`.
|
||||
|
||||
1. Use the [guestbook-service.json](guestbook-service.json) file to create the guestbook service by running the `kubectl create -f` *`filename`* command:
|
||||
|
||||
```console
|
||||
$ kubectl create -f examples/guestbook-go/guestbook-service.json
|
||||
```
|
||||
|
||||
|
||||
2. To verify that the guestbook service is up, list the services you created in the cluster with the `kubectl get services` command:
|
||||
|
||||
```console
|
||||
$ kubectl get services
|
||||
NAME CLUSTER_IP EXTERNAL_IP PORT(S) SELECTOR AGE
|
||||
guestbook 10.0.217.218 146.148.81.8 3000/TCP app=guestbook 1h
|
||||
redis-master 10.0.136.3 <none> 6379/TCP app=redis,role=master 1h
|
||||
redis-slave 10.0.21.92 <none> 6379/TCP app-redis,role=slave 1h
|
||||
...
|
||||
```
|
||||
|
||||
Result: The service is created with label `app=guestbook`.
|
||||
|
||||
### Step Seven: View the guestbook <a id="step-seven"></a>
|
||||
|
||||
You can now play with the guestbook that you just created by opening it in a browser (it might take a few moments for the guestbook to come up).
|
||||
|
||||
* **Local Host:**
|
||||
If you are running Kubernetes locally, to view the guestbook, navigate to `http://localhost:3000` in your browser.
|
||||
|
||||
* **Remote Host:**
|
||||
1. To view the guestbook on a remote host, locate the external IP of the load balancer in the **IP** column of the `kubectl get services` output. In our example, the internal IP address is `10.0.217.218` and the external IP address is `146.148.81.8` (*Note: you might need to scroll to see the IP column*).
|
||||
|
||||
2. Append port `3000` to the IP address (for example `http://146.148.81.8:3000`), and then navigate to that address in your browser.
|
||||
|
||||
Result: The guestbook displays in your browser:
|
||||
|
||||

|
||||
|
||||
**Further Reading:**
|
||||
If you're using Google Compute Engine, see the details about limiting traffic to specific sources at [Google Compute Engine firewall documentation][gce-firewall-docs].
|
||||
|
||||
[cloud-console]: https://console.developer.google.com
|
||||
[gce-firewall-docs]: https://cloud.google.com/compute/docs/networking#firewalls
|
||||
|
||||
### Step Eight: Cleanup <a id="step-eight"></a>
|
||||
|
||||
After you're done playing with the guestbook, you can cleanup by deleting the guestbook service and removing the associated resources that were created, including load balancers, forwarding rules, target pools, and Kubernetes replication controllers and services.
|
||||
|
||||
Delete all the resources by running the following `kubectl delete -f` *`filename`* command:
|
||||
|
||||
```console
|
||||
$ kubectl delete -f examples/guestbook-go
|
||||
guestbook-controller
|
||||
guestbook
|
||||
redid-master-controller
|
||||
redis-master
|
||||
redis-slave-controller
|
||||
redis-slave
|
||||
```
|
||||
|
||||
Tip: To turn down your Kubernetes cluster, follow the corresponding instructions in the version of the
|
||||
[Getting Started Guides](../../docs/getting-started-guides/) that you previously used to create your cluster.
|
||||
|
||||
|
||||
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
|
||||
[]()
|
||||
<!-- END MUNGE: GENERATED_ANALYTICS -->
|
37
vendor/k8s.io/kubernetes/examples/guestbook-go/guestbook-controller.json
generated
vendored
Normal file
37
vendor/k8s.io/kubernetes/examples/guestbook-go/guestbook-controller.json
generated
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
{
|
||||
"kind":"ReplicationController",
|
||||
"apiVersion":"v1",
|
||||
"metadata":{
|
||||
"name":"guestbook",
|
||||
"labels":{
|
||||
"app":"guestbook"
|
||||
}
|
||||
},
|
||||
"spec":{
|
||||
"replicas":3,
|
||||
"selector":{
|
||||
"app":"guestbook"
|
||||
},
|
||||
"template":{
|
||||
"metadata":{
|
||||
"labels":{
|
||||
"app":"guestbook"
|
||||
}
|
||||
},
|
||||
"spec":{
|
||||
"containers":[
|
||||
{
|
||||
"name":"guestbook",
|
||||
"image":"gcr.io/google_containers/guestbook:v3",
|
||||
"ports":[
|
||||
{
|
||||
"name":"http-server",
|
||||
"containerPort":3000
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
BIN
vendor/k8s.io/kubernetes/examples/guestbook-go/guestbook-page.png
generated
vendored
Normal file
BIN
vendor/k8s.io/kubernetes/examples/guestbook-go/guestbook-page.png
generated
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 39 KiB |
22
vendor/k8s.io/kubernetes/examples/guestbook-go/guestbook-service.json
generated
vendored
Normal file
22
vendor/k8s.io/kubernetes/examples/guestbook-go/guestbook-service.json
generated
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"kind":"Service",
|
||||
"apiVersion":"v1",
|
||||
"metadata":{
|
||||
"name":"guestbook",
|
||||
"labels":{
|
||||
"app":"guestbook"
|
||||
}
|
||||
},
|
||||
"spec":{
|
||||
"ports": [
|
||||
{
|
||||
"port":3000,
|
||||
"targetPort":"http-server"
|
||||
}
|
||||
],
|
||||
"selector":{
|
||||
"app":"guestbook"
|
||||
},
|
||||
"type": "LoadBalancer"
|
||||
}
|
||||
}
|
91
vendor/k8s.io/kubernetes/examples/guestbook-go/main.go
generated
vendored
Normal file
91
vendor/k8s.io/kubernetes/examples/guestbook-go/main.go
generated
vendored
Normal file
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/codegangsta/negroni"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/xyproto/simpleredis"
|
||||
)
|
||||
|
||||
var (
|
||||
masterPool *simpleredis.ConnectionPool
|
||||
slavePool *simpleredis.ConnectionPool
|
||||
)
|
||||
|
||||
func ListRangeHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
key := mux.Vars(req)["key"]
|
||||
list := simpleredis.NewList(slavePool, key)
|
||||
members := HandleError(list.GetAll()).([]string)
|
||||
membersJSON := HandleError(json.MarshalIndent(members, "", " ")).([]byte)
|
||||
rw.Write(membersJSON)
|
||||
}
|
||||
|
||||
func ListPushHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
key := mux.Vars(req)["key"]
|
||||
value := mux.Vars(req)["value"]
|
||||
list := simpleredis.NewList(masterPool, key)
|
||||
HandleError(nil, list.Add(value))
|
||||
ListRangeHandler(rw, req)
|
||||
}
|
||||
|
||||
func InfoHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
info := HandleError(masterPool.Get(0).Do("INFO")).([]byte)
|
||||
rw.Write(info)
|
||||
}
|
||||
|
||||
func EnvHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
environment := make(map[string]string)
|
||||
for _, item := range os.Environ() {
|
||||
splits := strings.Split(item, "=")
|
||||
key := splits[0]
|
||||
val := strings.Join(splits[1:], "=")
|
||||
environment[key] = val
|
||||
}
|
||||
|
||||
envJSON := HandleError(json.MarshalIndent(environment, "", " ")).([]byte)
|
||||
rw.Write(envJSON)
|
||||
}
|
||||
|
||||
func HandleError(result interface{}, err error) (r interface{}) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func main() {
|
||||
masterPool = simpleredis.NewConnectionPoolHost("redis-master:6379")
|
||||
defer masterPool.Close()
|
||||
slavePool = simpleredis.NewConnectionPoolHost("redis-slave:6379")
|
||||
defer slavePool.Close()
|
||||
|
||||
r := mux.NewRouter()
|
||||
r.Path("/lrange/{key}").Methods("GET").HandlerFunc(ListRangeHandler)
|
||||
r.Path("/rpush/{key}/{value}").Methods("GET").HandlerFunc(ListPushHandler)
|
||||
r.Path("/info").Methods("GET").HandlerFunc(InfoHandler)
|
||||
r.Path("/env").Methods("GET").HandlerFunc(EnvHandler)
|
||||
|
||||
n := negroni.Classic()
|
||||
n.UseHandler(r)
|
||||
n.Run(":3000")
|
||||
}
|
34
vendor/k8s.io/kubernetes/examples/guestbook-go/public/index.html
generated
vendored
Normal file
34
vendor/k8s.io/kubernetes/examples/guestbook-go/public/index.html
generated
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||
<meta charset="utf-8">
|
||||
<meta content="width=device-width" name="viewport">
|
||||
<link href="style.css" rel="stylesheet">
|
||||
<title>Guestbook</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="header">
|
||||
<h1>Guestbook</h1>
|
||||
</div>
|
||||
|
||||
<div id="guestbook-entries">
|
||||
<p>Waiting for database connection...</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<form id="guestbook-form">
|
||||
<input autocomplete="off" id="guestbook-entry-content" type="text">
|
||||
<a href="#" id="guestbook-submit">Submit</a>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p><h2 id="guestbook-host-address"></h2></p>
|
||||
<p><a href="env">/env</a>
|
||||
<a href="info">/info</a></p>
|
||||
</div>
|
||||
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
|
||||
<script src="script.js"></script>
|
||||
</body>
|
||||
</html>
|
46
vendor/k8s.io/kubernetes/examples/guestbook-go/public/script.js
generated
vendored
Normal file
46
vendor/k8s.io/kubernetes/examples/guestbook-go/public/script.js
generated
vendored
Normal file
|
@ -0,0 +1,46 @@
|
|||
$(document).ready(function() {
|
||||
var headerTitleElement = $("#header h1");
|
||||
var entriesElement = $("#guestbook-entries");
|
||||
var formElement = $("#guestbook-form");
|
||||
var submitElement = $("#guestbook-submit");
|
||||
var entryContentElement = $("#guestbook-entry-content");
|
||||
var hostAddressElement = $("#guestbook-host-address");
|
||||
|
||||
var appendGuestbookEntries = function(data) {
|
||||
entriesElement.empty();
|
||||
$.each(data, function(key, val) {
|
||||
entriesElement.append("<p>" + val + "</p>");
|
||||
});
|
||||
}
|
||||
|
||||
var handleSubmission = function(e) {
|
||||
e.preventDefault();
|
||||
var entryValue = entryContentElement.val()
|
||||
if (entryValue.length > 0) {
|
||||
entriesElement.append("<p>...</p>");
|
||||
$.getJSON("rpush/guestbook/" + entryValue, appendGuestbookEntries);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// colors = purple, blue, red, green, yellow
|
||||
var colors = ["#549", "#18d", "#d31", "#2a4", "#db1"];
|
||||
var randomColor = colors[Math.floor(5 * Math.random())];
|
||||
(function setElementsColor(color) {
|
||||
headerTitleElement.css("color", color);
|
||||
entryContentElement.css("box-shadow", "inset 0 0 0 2px " + color);
|
||||
submitElement.css("background-color", color);
|
||||
})(randomColor);
|
||||
|
||||
submitElement.click(handleSubmission);
|
||||
formElement.submit(handleSubmission);
|
||||
hostAddressElement.append(document.URL);
|
||||
|
||||
// Poll every second.
|
||||
(function fetchGuestbook() {
|
||||
$.getJSON("lrange/guestbook").done(appendGuestbookEntries).always(
|
||||
function() {
|
||||
setTimeout(fetchGuestbook, 1000);
|
||||
});
|
||||
})();
|
||||
});
|
61
vendor/k8s.io/kubernetes/examples/guestbook-go/public/style.css
generated
vendored
Normal file
61
vendor/k8s.io/kubernetes/examples/guestbook-go/public/style.css
generated
vendored
Normal file
|
@ -0,0 +1,61 @@
|
|||
body, input {
|
||||
color: #123;
|
||||
font-family: "Gill Sans", sans-serif;
|
||||
}
|
||||
|
||||
div {
|
||||
overflow: hidden;
|
||||
padding: 1em 0;
|
||||
position: relative;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
h1, h2, p, input, a {
|
||||
font-weight: 300;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #BDB76B;
|
||||
font-size: 3.5em;
|
||||
}
|
||||
|
||||
h2 {
|
||||
color: #999;
|
||||
}
|
||||
|
||||
form {
|
||||
margin: 0 auto;
|
||||
max-width: 50em;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
input {
|
||||
border: 0;
|
||||
border-radius: 1000px;
|
||||
box-shadow: inset 0 0 0 2px #BDB76B;
|
||||
display: inline;
|
||||
font-size: 1.5em;
|
||||
margin-bottom: 1em;
|
||||
outline: none;
|
||||
padding: .5em 5%;
|
||||
width: 55%;
|
||||
}
|
||||
|
||||
form a {
|
||||
background: #BDB76B;
|
||||
border: 0;
|
||||
border-radius: 1000px;
|
||||
color: #FFF;
|
||||
font-size: 1.25em;
|
||||
font-weight: 400;
|
||||
padding: .75em 2em;
|
||||
text-decoration: none;
|
||||
text-transform: uppercase;
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
p {
|
||||
font-size: 1.5em;
|
||||
line-height: 1.5;
|
||||
}
|
40
vendor/k8s.io/kubernetes/examples/guestbook-go/redis-master-controller.json
generated
vendored
Normal file
40
vendor/k8s.io/kubernetes/examples/guestbook-go/redis-master-controller.json
generated
vendored
Normal file
|
@ -0,0 +1,40 @@
|
|||
{
|
||||
"kind":"ReplicationController",
|
||||
"apiVersion":"v1",
|
||||
"metadata":{
|
||||
"name":"redis-master",
|
||||
"labels":{
|
||||
"app":"redis",
|
||||
"role":"master"
|
||||
}
|
||||
},
|
||||
"spec":{
|
||||
"replicas":1,
|
||||
"selector":{
|
||||
"app":"redis",
|
||||
"role":"master"
|
||||
},
|
||||
"template":{
|
||||
"metadata":{
|
||||
"labels":{
|
||||
"app":"redis",
|
||||
"role":"master"
|
||||
}
|
||||
},
|
||||
"spec":{
|
||||
"containers":[
|
||||
{
|
||||
"name":"redis-master",
|
||||
"image":"redis:2.8.23",
|
||||
"ports":[
|
||||
{
|
||||
"name":"redis-server",
|
||||
"containerPort":6379
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
23
vendor/k8s.io/kubernetes/examples/guestbook-go/redis-master-service.json
generated
vendored
Normal file
23
vendor/k8s.io/kubernetes/examples/guestbook-go/redis-master-service.json
generated
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"kind":"Service",
|
||||
"apiVersion":"v1",
|
||||
"metadata":{
|
||||
"name":"redis-master",
|
||||
"labels":{
|
||||
"app":"redis",
|
||||
"role":"master"
|
||||
}
|
||||
},
|
||||
"spec":{
|
||||
"ports": [
|
||||
{
|
||||
"port":6379,
|
||||
"targetPort":"redis-server"
|
||||
}
|
||||
],
|
||||
"selector":{
|
||||
"app":"redis",
|
||||
"role":"master"
|
||||
}
|
||||
}
|
||||
}
|
40
vendor/k8s.io/kubernetes/examples/guestbook-go/redis-slave-controller.json
generated
vendored
Normal file
40
vendor/k8s.io/kubernetes/examples/guestbook-go/redis-slave-controller.json
generated
vendored
Normal file
|
@ -0,0 +1,40 @@
|
|||
{
|
||||
"kind":"ReplicationController",
|
||||
"apiVersion":"v1",
|
||||
"metadata":{
|
||||
"name":"redis-slave",
|
||||
"labels":{
|
||||
"app":"redis",
|
||||
"role":"slave"
|
||||
}
|
||||
},
|
||||
"spec":{
|
||||
"replicas":2,
|
||||
"selector":{
|
||||
"app":"redis",
|
||||
"role":"slave"
|
||||
},
|
||||
"template":{
|
||||
"metadata":{
|
||||
"labels":{
|
||||
"app":"redis",
|
||||
"role":"slave"
|
||||
}
|
||||
},
|
||||
"spec":{
|
||||
"containers":[
|
||||
{
|
||||
"name":"redis-slave",
|
||||
"image":"kubernetes/redis-slave:v2",
|
||||
"ports":[
|
||||
{
|
||||
"name":"redis-server",
|
||||
"containerPort":6379
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
23
vendor/k8s.io/kubernetes/examples/guestbook-go/redis-slave-service.json
generated
vendored
Normal file
23
vendor/k8s.io/kubernetes/examples/guestbook-go/redis-slave-service.json
generated
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"kind":"Service",
|
||||
"apiVersion":"v1",
|
||||
"metadata":{
|
||||
"name":"redis-slave",
|
||||
"labels":{
|
||||
"app":"redis",
|
||||
"role":"slave"
|
||||
}
|
||||
},
|
||||
"spec":{
|
||||
"ports": [
|
||||
{
|
||||
"port":6379,
|
||||
"targetPort":"redis-server"
|
||||
}
|
||||
],
|
||||
"selector":{
|
||||
"app":"redis",
|
||||
"role":"slave"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue