Skip to content

Commit

Permalink
Update guestbook example to use replication controller.
Browse files Browse the repository at this point in the history
  • Loading branch information
rsokolowski committed Feb 24, 2015
1 parent e77322a commit 635281e
Show file tree
Hide file tree
Showing 15 changed files with 315 additions and 264 deletions.
12 changes: 6 additions & 6 deletions examples/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ func TestExampleObjectSchemas(t *testing.T) {
"service-list": &api.ServiceList{},
},
"../examples/guestbook": {
"frontend-controller": &api.ReplicationController{},
"redis-slave-controller": &api.ReplicationController{},
"redis-master": &api.Pod{},
"frontend-service": &api.Service{},
"redis-master-service": &api.Service{},
"redis-slave-service": &api.Service{},
"frontend-controller": &api.ReplicationController{},
"redis-slave-controller": &api.ReplicationController{},
"redis-master-controller": &api.ReplicationController{},
"frontend-service": &api.Service{},
"redis-master-service": &api.Service{},
"redis-slave-service": &api.Service{},
},
"../examples/guestbook/v1beta3": {
"frontend-controller": &api.ReplicationController{},
Expand Down
208 changes: 129 additions & 79 deletions examples/guestbook/README.md

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions examples/guestbook/frontend-controller.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@
"desiredState": {
"manifest": {
"version": "v1beta1",
"id": "frontend-controller",
"id": "frontend",
"containers": [{
"name": "php-redis",
"image": "kubernetes/example-guestbook-php-redis",
"cpu": 100,
"memory": 50000000,
"ports": [{"containerPort": 80, "hostPort": 8000}]
"ports": [{"name": "http-server", "containerPort": 80}]
}]
}
},
"labels": {
"name": "frontend",
"uses": "redisslave,redis-master"
"uses": "redis-slave,redis-master",
"app": "frontend"
}
}},
"labels": {"name": "frontend"}
Expand Down
7 changes: 4 additions & 3 deletions examples/guestbook/frontend-service.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
"id": "frontend",
"kind": "Service",
"apiVersion": "v1beta1",
"port": 80,
"containerPort": 80,
"port": 8000,
"containerPort": "http-server",
"selector": {
"name": "frontend"
},
"labels": {
"name": "frontend"
}
},
"createExternalLoadBalancer": true
}
31 changes: 31 additions & 0 deletions examples/guestbook/redis-master-controller.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"id": "redis-master-controller",
"kind": "ReplicationController",
"apiVersion": "v1beta1",
"desiredState": {
"replicas": 1,
"replicaSelector": {"name": "redis-master"},
"podTemplate": {
"desiredState": {
"manifest": {
"version": "v1beta1",
"id": "redis-master",
"containers": [{
"name": "redis-master",
"image": "dockerfile/redis",
"cpu": 100,
"ports": [{"containerPort": 6379}]
}]
}
},
"labels": {
"name": "redis-master",
"app": "redis"
}
}
},
"labels": {
"name": "redis-master"
}
}

24 changes: 0 additions & 24 deletions examples/guestbook/redis-master.json

This file was deleted.

15 changes: 8 additions & 7 deletions examples/guestbook/redis-slave-controller.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,26 @@
"apiVersion": "v1beta1",
"desiredState": {
"replicas": 2,
"replicaSelector": {"name": "redisslave"},
"replicaSelector": {"name": "redis-slave"},
"podTemplate": {
"desiredState": {
"manifest": {
"version": "v1beta1",
"id": "redis-slave-controller",
"id": "redis-slave",
"containers": [{
"name": "slave",
"name": "redis-slave",
"image": "brendanburns/redis-slave",
"cpu": 200,
"ports": [{"containerPort": 6379, "hostPort": 6380}]
"ports": [{"containerPort": 6379}]
}]
}
},
"labels": {
"name": "redisslave",
"uses": "redis-master"
"name": "redis-slave",
"uses": "redis-master",
"app": "redis"
}
}
},
"labels": {"name": "redisslave"}
"labels": {"name": "redis-slave"}
}
4 changes: 2 additions & 2 deletions examples/guestbook/redis-slave-service.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"port": 6379,
"containerPort": 6379,
"labels": {
"name": "redisslave"
"name": "redis-slave"
},
"selector": {
"name": "redisslave"
"name": "redis-slave"
}
}
4 changes: 2 additions & 2 deletions examples/limitrange/valid-pod.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"desiredState": {
"manifest": {
"version": "v1beta1",
"id": "invalid-pod",
"id": "valid-pod",
"containers": [{
"name": "kubernetes-serve-hostname",
"image": "kubernetes/serve_hostname",
Expand All @@ -17,4 +17,4 @@
}]
}
},
}
}
77 changes: 39 additions & 38 deletions hack/test-cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -132,67 +132,68 @@ for version in "${kube_api_versions[@]}"; do

kube::log::status "Testing kubectl(${version}:pods)"
kubectl get pods "${kube_flags[@]}"
kubectl create -f examples/guestbook/redis-master.json "${kube_flags[@]}"
kubectl create -f examples/limitrange/valid-pod.json "${kube_flags[@]}"
kubectl get pods "${kube_flags[@]}"
kubectl get pod redis-master "${kube_flags[@]}"
[ "$(kubectl get pod redis-master -o template --output-version=v1beta1 -t '{{ .id }}' "${kube_flags[@]}")" == "redis-master" ]
output_pod=$(kubectl get pod redis-master -o yaml --output-version=v1beta1 "${kube_flags[@]}")
kubectl delete pod redis-master "${kube_flags[@]}"
kubectl get pod valid-pod "${kube_flags[@]}"
[ "$(kubectl get pod valid-pod -o template --output-version=v1beta1 -t '{{ .id }}' "${kube_flags[@]}")" == "valid-pod" ]
output_pod=$(kubectl get pod valid-pod -o yaml --output-version=v1beta1 "${kube_flags[@]}")
kubectl delete pod valid-pod "${kube_flags[@]}"
before="$(kubectl get pods -o template -t "{{ len .items }}" "${kube_flags[@]}")"
echo "${output_pod}" | kubectl create -f - "${kube_flags[@]}"
after="$(kubectl get pods -o template -t "{{ len .items }}" "${kube_flags[@]}")"
[ "$((${after} - ${before}))" -eq 1 ]
kubectl get pods -o yaml --output-version=v1beta1 "${kube_flags[@]}" | grep -q "id: redis-master"
kubectl describe pod redis-master "${kube_flags[@]}" | grep -q 'Name:.*redis-master'
kubectl delete -f examples/guestbook/redis-master.json "${kube_flags[@]}"
kubectl delete pods -l name=redis-master "${kube_flags[@]}"
[ ! $(kubectl get pods "${kube_flags[@]}" -lname=redis-master | grep -q 'redis-master') ]
kubectl create -f examples/guestbook/redis-master.json "${kube_flags[@]}"
kubectl get pods "${kube_flags[@]}" -lname=redis-master | grep -q 'redis-master'
kubectl get pods -o yaml --output-version=v1beta1 "${kube_flags[@]}" | grep -q "id: valid-pod"
kubectl describe pod valid-pod "${kube_flags[@]}" | grep -q 'Name:.*valid-pod'
kubectl delete -f examples/limitrange/valid-pod.json "${kube_flags[@]}"

kubectl delete pods -l name=valid-pod "${kube_flags[@]}"
[ ! $(kubectl get pods "${kube_flags[@]}" -lname=valid-pod | grep -q 'valid-pod') ]
kubectl create -f examples/limitrange/valid-pod.json "${kube_flags[@]}"
kubectl get pods "${kube_flags[@]}" -lname=valid-pod | grep -q 'valid-pod'
[ ! $(kubectl delete pods "${kube_flags[@]}" ) ]
kubectl get pods "${kube_flags[@]}" -lname=redis-master | grep -q 'redis-master'
[ ! $(kubectl delete pods --all pods -l name=redis-master "${kube_flags[@]}" ) ] # not --all and label selector together
kubectl get pods "${kube_flags[@]}" -lname=valid-pod | grep -q 'valid-pod'
[ ! $(kubectl delete pods --all pods -l name=valid-pod "${kube_flags[@]}" ) ] # not --all and label selector together
kubectl delete --all pods "${kube_flags[@]}" # --all remove all the pods
kubectl create -f examples/guestbook/redis-master.json "${kube_flags[@]}"
kubectl create -f examples/limitrange/valid-pod.json "${kube_flags[@]}"
kubectl create -f examples/redis/redis-proxy.yaml "${kube_flags[@]}"
kubectl get pods redis-master redis-proxy "${kube_flags[@]}"
kubectl delete pods redis-master redis-proxy # delete multiple pods at once
kubectl get pods valid-pod redis-proxy "${kube_flags[@]}"
kubectl delete pods valid-pod redis-proxy "${kube_flags[@]}" # delete multiple pods at once
howmanypods="$(kubectl get pods -o template -t "{{ len .items }}" "${kube_flags[@]}")"
[ "$howmanypods" -eq 0 ]
kubectl create -f examples/guestbook/redis-master.json "${kube_flags[@]}"
kubectl create -f examples/limitrange/valid-pod.json "${kube_flags[@]}"
kubectl create -f examples/redis/redis-proxy.yaml "${kube_flags[@]}"
kubectl stop pods redis-master redis-proxy # stop multiple pods at once
kubectl stop pods valid-pod redis-proxy "${kube_flags[@]}" # stop multiple pods at once
howmanypods="$(kubectl get pods -o template -t "{{ len .items }}" "${kube_flags[@]}")"
[ "$howmanypods" -eq 0 ]
kubectl create -f examples/guestbook/redis-master.json "${kube_flags[@]}"
kubectl create -f examples/limitrange/valid-pod.json "${kube_flags[@]}"
howmanypods="$(kubectl get pods -o template -t "{{ len .items }}" "${kube_flags[@]}")"
[ "$howmanypods" -eq 1 ]

#testing pods and label command command
kubectl label pods redis-master new-name=new-redis-master "${kube_flags[@]}"
kubectl delete pods -lnew-name=new-redis-master "${kube_flags[@]}"
kubectl label pods valid-pod new-name=new-valid-pod "${kube_flags[@]}"
kubectl delete pods -lnew-name=new-valid-pod "${kube_flags[@]}"
howmanypods="$(kubectl get pods -o template -t "{{ len .items }}" "${kube_flags[@]}")"
[ "$howmanypods" -eq 0 ]
kubectl create -f examples/guestbook/redis-master.json "${kube_flags[@]}"
kubectl create -f examples/limitrange/valid-pod.json "${kube_flags[@]}"
howmanypods="$(kubectl get pods -o template -t "{{ len .items }}" "${kube_flags[@]}")"
[ "$howmanypods" -eq 1 ]
! $(kubectl label pods redis-master name=redis-super-sayan "${kube_flags[@]}" )
kubectl label --overwrite pods redis-master name=redis-super-sayan "${kube_flags[@]}"
kubectl delete pods -lname=redis-super-sayan "${kube_flags[@]}"
howmanypods="$(kubectl get pods -lname=redis-super-sayan -o template -t "{{ len .items }}" "${kube_flags[@]}")"
! $(kubectl label pods valid-pod name=valid-pod-super-sayan "${kube_flags[@]}" )
kubectl label --overwrite pods valid-pod name=valid-pod-super-sayan "${kube_flags[@]}"
kubectl delete pods -lname=valid-pod-super-sayan "${kube_flags[@]}"
howmanypods="$(kubectl get pods -lname=valid-pod-super-sayan -o template -t "{{ len .items }}" "${kube_flags[@]}")"
[ "$howmanypods" -eq 0 ]

# make calls in another namespace
kubectl create --namespace=other -f examples/guestbook/redis-master.json "${kube_flags[@]}"
kubectl get pod --namespace=other redis-master
kubectl delete pod --namespace=other redis-master
kubectl create "${kube_flags[@]}" --namespace=other -f examples/limitrange/valid-pod.json
kubectl get "${kube_flags[@]}" pod --namespace=other valid-pod
kubectl delete "${kube_flags[@]}" pod --namespace=other valid-pod

kube::log::status "Testing kubectl(${version}:services)"
kubectl get services "${kube_flags[@]}"
kubectl create -f examples/guestbook/frontend-service.json "${kube_flags[@]}"
kubectl create -f examples/guestbook/redis-master-service.json "${kube_flags[@]}"
kubectl get services "${kube_flags[@]}"
output_service=$(kubectl get service frontend -o json --output-version=v1beta3 "${kube_flags[@]}")
kubectl delete service frontend "${kube_flags[@]}"
output_service=$(kubectl get service redis-master -o json --output-version=v1beta3 "${kube_flags[@]}")
kubectl delete service redis-master "${kube_flags[@]}"
echo "${output_service}" | kubectl create -f - "${kube_flags[@]}"
kubectl create -f - "${kube_flags[@]}" << __EOF__
{
Expand All @@ -206,15 +207,15 @@ for version in "${kube_api_versions[@]}"; do
}
}
__EOF__
kubectl update service service-${version}-test --patch="{\"selector\":{\"version\":\"${version}\"},\"apiVersion\":\"${version}\"}"
kubectl get service service-${version}-test -o json | kubectl update -f -
kubectl update service "${kube_flags[@]}" service-${version}-test --patch="{\"selector\":{\"version\":\"${version}\"},\"apiVersion\":\"${version}\"}"
kubectl get service "${kube_flags[@]}" service-${version}-test -o json | kubectl update "${kube_flags[@]}" -f -
kubectl get services "${kube_flags[@]}"
kubectl get services "service-${version}-test" "${kube_flags[@]}"
kubectl delete service frontend "${kube_flags[@]}"
kubectl delete service redis-master "${kube_flags[@]}"
servicesbefore="$(kubectl get services -o template -t "{{ len .items }}" "${kube_flags[@]}")"
kubectl create -f examples/guestbook/frontend-service.json "${kube_flags[@]}"
kubectl create -f examples/guestbook/redis-master-service.json "${kube_flags[@]}"
kubectl create -f examples/guestbook/redis-slave-service.json "${kube_flags[@]}"
kubectl delete services frontend redisslave # delete multiple services at once
kubectl delete services redis-master redisslave "${kube_flags[@]}" # delete multiple services at once
servicesafter="$(kubectl get services -o template -t "{{ len .items }}" "${kube_flags[@]}")"
[ "$((${servicesafter} - ${servicesbefore}))" -eq 0 ]

Expand Down
Loading

0 comments on commit 635281e

Please sign in to comment.