2014-07-28 00:01:52 +00:00
#!/bin/bash
2015-05-01 16:19:44 +00:00
# Copyright 2014 The Kubernetes Authors All rights reserved.
2014-07-28 00:01:52 +00:00
#
# 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.
# This command checks that the built commands can function together for
# simple scenarios. It does not require Docker so it can run in travis.
2014-10-06 20:25:27 +00:00
set -o errexit
set -o nounset
set -o pipefail
2014-10-03 21:58:49 +00:00
KUBE_ROOT = $( dirname " ${ BASH_SOURCE } " ) /..
2014-10-22 23:26:59 +00:00
source " ${ KUBE_ROOT } /hack/lib/init.sh "
2015-02-23 15:20:55 +00:00
source " ${ KUBE_ROOT } /hack/lib/test.sh "
2014-07-28 00:01:52 +00:00
2015-06-23 01:41:25 +00:00
# Stops the running kubectl proxy, if there is one.
function stop-proxy( )
{
[ [ -n " ${ PROXY_PID - } " ] ] && kill " ${ PROXY_PID } " 1>& 2 2>/dev/null
PROXY_PID =
2015-09-30 00:02:28 +00:00
PROXY_PORT =
2015-06-23 01:41:25 +00:00
}
2015-10-14 22:47:52 +00:00
# Starts "kubect proxy" to test the client proxy. $1: api_prefix
2015-06-23 01:41:25 +00:00
function start-proxy( )
{
stop-proxy
kube::log::status "Starting kubectl proxy"
2015-09-30 00:02:28 +00:00
for retry in $( seq 1 3) ; do
PROXY_PORT = $( kube::util::get_random_port)
kube::log::status " On try ${ retry } , use proxy port ${ PROXY_PORT } if it's free "
if kube::util::test_host_port_free "127.0.0.1" " ${ PROXY_PORT } " ; then
2015-10-14 22:47:52 +00:00
if [ $# -eq 0 ] ; then
kubectl proxy -p ${ PROXY_PORT } --www= . 1>& 2 & break
else
kubectl proxy -p ${ PROXY_PORT } --www= . --api-prefix= " $1 " 1>& 2 & break
fi
2015-09-30 00:02:28 +00:00
fi
sleep 1;
done
2015-06-23 01:41:25 +00:00
PROXY_PID = $!
2015-10-14 22:47:52 +00:00
if [ $# -eq 0 ] ; then
kube::util::wait_for_url " http://127.0.0.1: ${ PROXY_PORT } /healthz " "kubectl proxy"
else
kube::util::wait_for_url " http://127.0.0.1: ${ PROXY_PORT } / $1 /healthz " " kubectl proxy --api-prefix= $1 "
fi
2015-06-23 01:41:25 +00:00
}
2014-07-28 00:01:52 +00:00
function cleanup( )
{
2015-06-23 01:41:25 +00:00
[ [ -n " ${ APISERVER_PID - } " ] ] && kill " ${ APISERVER_PID } " 1>& 2 2>/dev/null
[ [ -n " ${ CTLRMGR_PID - } " ] ] && kill " ${ CTLRMGR_PID } " 1>& 2 2>/dev/null
[ [ -n " ${ KUBELET_PID - } " ] ] && kill " ${ KUBELET_PID } " 1>& 2 2>/dev/null
stop-proxy
2014-10-22 23:26:59 +00:00
2015-06-23 01:41:25 +00:00
kube::etcd::cleanup
rm -rf " ${ KUBE_TEMP } "
2014-10-22 23:26:59 +00:00
2015-06-23 01:41:25 +00:00
kube::log::status "Clean up complete"
}
# Executes curl against the proxy. $1 is the path to use, $2 is the desired
# return code. Prints a helpful message on failure.
function check-curl-proxy-code( )
{
local status
local -r address = $1
local -r desired = $2
local -r full_address = " ${ PROXY_HOST } : ${ PROXY_PORT } ${ address } "
status = $( curl -w "%{http_code}" --silent --output /dev/null " ${ full_address } " )
if [ " ${ status } " = = " ${ desired } " ] ; then
return 0
fi
echo " For address ${ full_address } , got ${ status } but wanted ${ desired } "
return 1
2014-07-28 00:01:52 +00:00
}
2015-10-08 20:08:33 +00:00
# TODO: Remove this function when we do the retry inside the kubectl commands. See #15333.
function kubectl-with-retry( )
{
ERROR_FILE = " ${ KUBE_TEMP } /kubectl-error "
for count in $( seq 0 3) ; do
kubectl " $@ " 2> ${ ERROR_FILE } || true
if grep -q "the object has been modified" " ${ ERROR_FILE } " ; then
kube::log::status " retry $1 , error: $( cat ${ ERROR_FILE } ) "
rm " ${ ERROR_FILE } "
sleep $(( 2 * * count))
else
rm " ${ ERROR_FILE } "
break
fi
done
}
2015-08-21 01:28:05 +00:00
kube::util::trap_add cleanup EXIT SIGINT
2014-07-28 00:01:52 +00:00
2015-03-22 21:43:00 +00:00
kube::util::ensure-temp-dir
2014-10-22 23:26:59 +00:00
kube::etcd::start
2014-07-28 00:01:52 +00:00
2014-08-23 01:12:16 +00:00
ETCD_HOST = ${ ETCD_HOST :- 127 .0.0.1 }
ETCD_PORT = ${ ETCD_PORT :- 4001 }
API_PORT = ${ API_PORT :- 8080 }
API_HOST = ${ API_HOST :- 127 .0.0.1 }
KUBELET_PORT = ${ KUBELET_PORT :- 10250 }
2015-04-01 23:19:17 +00:00
KUBELET_HEALTHZ_PORT = ${ KUBELET_HEALTHZ_PORT :- 10248 }
2014-10-22 01:21:44 +00:00
CTLRMGR_PORT = ${ CTLRMGR_PORT :- 10252 }
2015-06-23 01:41:25 +00:00
PROXY_HOST = 127.0.0.1 # kubectl only serves on localhost.
2014-07-28 00:01:52 +00:00
2015-07-30 04:47:50 +00:00
# ensure ~/.kube/config isn't loaded by tests
HOME = " ${ KUBE_TEMP } "
2014-10-06 01:24:19 +00:00
# Check kubectl
2014-10-22 23:26:59 +00:00
kube::log::status "Running kubectl with no options"
" ${ KUBE_OUTPUT_HOSTBIN } /kubectl "
2014-07-28 00:01:52 +00:00
2015-01-16 21:39:31 +00:00
kube::log::status "Starting kubelet in masterless mode"
2014-10-22 23:26:59 +00:00
" ${ KUBE_OUTPUT_HOSTBIN } /kubelet " \
2015-07-04 23:23:32 +00:00
--really-crash-for-testing= true \
--root-dir= /tmp/kubelet.$$ \
--cert-dir= " ${ TMPDIR :- /tmp/ } " \
--docker-endpoint= "fake://" \
--hostname-override= "127.0.0.1" \
2015-01-16 21:39:31 +00:00
--address= "127.0.0.1" \
2015-04-01 23:19:17 +00:00
--port= " $KUBELET_PORT " \
2015-07-04 23:23:32 +00:00
--healthz-port= " ${ KUBELET_HEALTHZ_PORT } " 1>& 2 &
2015-01-16 21:39:31 +00:00
KUBELET_PID = $!
2015-06-09 21:15:01 +00:00
kube::util::wait_for_url " http://127.0.0.1: ${ KUBELET_HEALTHZ_PORT } /healthz " "kubelet(masterless)"
2015-01-16 21:39:31 +00:00
kill ${ KUBELET_PID } 1>& 2 2>/dev/null
kube::log::status "Starting kubelet in masterful mode"
" ${ KUBE_OUTPUT_HOSTBIN } /kubelet " \
2015-07-04 23:23:32 +00:00
--really-crash-for-testing= true \
--root-dir= /tmp/kubelet.$$ \
--cert-dir= " ${ TMPDIR :- /tmp/ } " \
--docker-endpoint= "fake://" \
--hostname-override= "127.0.0.1" \
2014-07-28 00:01:52 +00:00
--address= "127.0.0.1" \
2015-07-04 23:23:32 +00:00
--api-servers= " ${ API_HOST } : ${ API_PORT } " \
2015-04-01 23:19:17 +00:00
--port= " $KUBELET_PORT " \
2015-07-04 23:23:32 +00:00
--healthz-port= " ${ KUBELET_HEALTHZ_PORT } " 1>& 2 &
2014-07-28 00:01:52 +00:00
KUBELET_PID = $!
2015-06-09 21:15:01 +00:00
kube::util::wait_for_url " http://127.0.0.1: ${ KUBELET_HEALTHZ_PORT } /healthz " "kubelet"
2014-07-28 00:01:52 +00:00
2014-11-11 00:34:21 +00:00
# Start kube-apiserver
kube::log::status "Starting kube-apiserver"
2015-10-09 22:19:13 +00:00
KUBE_API_VERSIONS = "v1,extensions/v1beta1" " ${ KUBE_OUTPUT_HOSTBIN } /kube-apiserver " \
2014-07-28 00:01:52 +00:00
--address= "127.0.0.1" \
2015-07-04 23:23:32 +00:00
--public-address-override= "127.0.0.1" \
2014-07-28 00:01:52 +00:00
--port= " ${ API_PORT } " \
2015-07-04 23:23:32 +00:00
--etcd-servers= " http:// ${ ETCD_HOST } : ${ ETCD_PORT } " \
--public-address-override= "127.0.0.1" \
--kubelet-port= ${ KUBELET_PORT } \
--runtime-config= api/v1 \
--cert-dir= " ${ TMPDIR :- /tmp/ } " \
2015-10-09 19:02:16 +00:00
--runtime_config= "extensions/v1beta1=true" \
2015-05-24 04:59:46 +00:00
--service-cluster-ip-range= "10.0.0.0/24" 1>& 2 &
2014-07-28 00:01:52 +00:00
APISERVER_PID = $!
2015-06-09 21:15:01 +00:00
kube::util::wait_for_url " http://127.0.0.1: ${ API_PORT } /healthz " "apiserver"
2014-10-22 23:26:59 +00:00
2014-10-22 01:21:44 +00:00
# Start controller manager
2015-06-09 21:15:01 +00:00
kube::log::status "Starting controller-manager"
2014-11-11 00:34:21 +00:00
" ${ KUBE_OUTPUT_HOSTBIN } /kube-controller-manager " \
2015-06-09 21:15:01 +00:00
--port= " ${ CTLRMGR_PORT } " \
2014-10-22 01:21:44 +00:00
--master= " 127.0.0.1: ${ API_PORT } " 1>& 2 &
CTLRMGR_PID = $!
2015-06-09 21:15:01 +00:00
kube::util::wait_for_url " http://127.0.0.1: ${ CTLRMGR_PORT } /healthz " "controller-manager"
2015-06-30 02:30:14 +00:00
kube::util::wait_for_url " http://127.0.0.1: ${ API_PORT } /api/v1/nodes/127.0.0.1 " "apiserver(nodes)"
2014-10-22 01:21:44 +00:00
2015-03-06 18:04:52 +00:00
# Expose kubectl directly for readability
2015-01-14 00:04:47 +00:00
PATH = " ${ KUBE_OUTPUT_HOSTBIN } " :$PATH
2015-06-30 02:30:14 +00:00
runTests( ) {
version = " $1 "
echo " Testing api version: $1 "
2015-01-13 23:46:13 +00:00
if [ [ -z " ${ version } " ] ] ; then
kube_flags = (
-s " http://127.0.0.1: ${ API_PORT } "
--match-server-version
)
2015-08-21 13:09:41 +00:00
[ " $( kubectl get nodes -o go-template= '{{ .apiVersion }}' " ${ kube_flags [@] } " ) " = = "v1" ]
2015-01-13 23:46:13 +00:00
else
kube_flags = (
-s " http://127.0.0.1: ${ API_PORT } "
--match-server-version
--api-version= " ${ version } "
)
2015-08-21 13:09:41 +00:00
[ " $( kubectl get nodes -o go-template= '{{ .apiVersion }}' " ${ kube_flags [@] } " ) " = = " ${ version } " ]
2015-01-13 23:46:13 +00:00
fi
2015-04-02 20:15:39 +00:00
id_field = ".metadata.name"
labels_field = ".metadata.labels"
2015-09-30 01:50:05 +00:00
annotations_field = ".metadata.annotations"
2015-04-02 20:15:39 +00:00
service_selector_field = ".spec.selector"
rc_replicas_field = ".spec.replicas"
2015-04-29 22:06:42 +00:00
rc_status_replicas_field = ".status.replicas"
rc_container_image_field = ".spec.template.spec.containers"
2015-04-02 20:15:39 +00:00
port_field = "(index .spec.ports 0).port"
2015-07-16 21:18:17 +00:00
port_name = "(index .spec.ports 0).name"
2015-10-12 09:12:36 +00:00
second_port_field = "(index .spec.ports 1).port"
second_port_name = "(index .spec.ports 1).name"
2015-06-18 17:15:52 +00:00
image_field = "(index .spec.containers 0).image"
2015-10-15 22:15:13 +00:00
hpa_min_field = ".spec.minReplicas"
hpa_max_field = ".spec.maxReplicas"
hpa_cpu_field = ".spec.cpuUtilization.targetPercentage"
2014-12-12 01:24:54 +00:00
2015-03-06 18:04:52 +00:00
# Passing no arguments to create is an error
2015-02-13 22:18:24 +00:00
! kubectl create
2015-01-14 18:06:53 +00:00
2015-06-23 01:41:25 +00:00
#######################
# kubectl local proxy #
#######################
# Make sure the UI can be proxied
2015-10-09 19:02:16 +00:00
start-proxy
2015-06-23 01:41:25 +00:00
check-curl-proxy-code /ui 301
check-curl-proxy-code /metrics 200
2015-10-09 19:02:16 +00:00
check-curl-proxy-code /api/ui 404
2015-06-23 01:41:25 +00:00
if [ [ -n " ${ version } " ] ] ; then
check-curl-proxy-code /api/${ version } /namespaces 200
fi
2015-10-14 22:47:52 +00:00
check-curl-proxy-code /static/ 200
2015-06-23 01:41:25 +00:00
stop-proxy
2015-10-09 19:02:16 +00:00
# Make sure the in-development api is accessible by default
2015-06-23 01:41:25 +00:00
start-proxy
2015-10-09 19:02:16 +00:00
check-curl-proxy-code /apis 200
check-curl-proxy-code /apis/extensions/ 200
2015-06-23 01:41:25 +00:00
stop-proxy
# Custom paths let you see everything.
2015-10-14 22:47:52 +00:00
start-proxy /custom
2015-06-23 01:41:25 +00:00
check-curl-proxy-code /custom/ui 301
check-curl-proxy-code /custom/metrics 200
if [ [ -n " ${ version } " ] ] ; then
check-curl-proxy-code /custom/api/${ version } /namespaces 200
fi
stop-proxy
2015-02-23 15:20:55 +00:00
###########################
# POD creation / deletion #
###########################
2015-01-08 17:42:20 +00:00
kube::log::status " Testing kubectl( ${ version } :pods) "
2015-02-23 15:20:55 +00:00
### Create POD valid-pod from JSON
# Pre-condition: no POD is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " ''
2015-02-23 15:20:55 +00:00
# Command
2015-08-04 14:46:51 +00:00
kubectl create " ${ kube_flags [@] } " -f docs/admin/limitrange/valid-pod.yaml
2015-02-23 15:20:55 +00:00
# Post-condition: valid-pod POD is running
2015-04-16 23:21:13 +00:00
kubectl get " ${ kube_flags [@] } " pods -o json
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " 'valid-pod:'
kube::test::get_object_assert 'pod valid-pod' " {{ $id_field }} " 'valid-pod'
kube::test::get_object_assert 'pod/valid-pod' " {{ $id_field }} " 'valid-pod'
kube::test::get_object_assert 'pods/valid-pod' " {{ $id_field }} " 'valid-pod'
2015-08-04 08:14:31 +00:00
# Repeat above test using jsonpath template
kube::test::get_object_jsonpath_assert pods " {.items[*] $id_field } " 'valid-pod'
kube::test::get_object_jsonpath_assert 'pod valid-pod' " { $id_field } " 'valid-pod'
kube::test::get_object_jsonpath_assert 'pod/valid-pod' " { $id_field } " 'valid-pod'
kube::test::get_object_jsonpath_assert 'pods/valid-pod' " { $id_field } " 'valid-pod'
2015-03-23 16:23:15 +00:00
# Describe command should print detailed information
2015-05-22 23:40:57 +00:00
kube::test::describe_object_assert pods 'valid-pod' "Name:" "Image(s):" "Node:" "Labels:" "Status:" "Replication Controllers"
2015-08-04 07:12:29 +00:00
# Describe command (resource only) should print detailed information
kube::test::describe_resource_assert pods "Name:" "Image(s):" "Node:" "Labels:" "Status:" "Replication Controllers"
2015-02-23 15:20:55 +00:00
### Dump current valid-pod POD
2015-07-23 04:52:05 +00:00
output_pod = $( kubectl get pod valid-pod -o yaml --output-version= v1 " ${ kube_flags [@] } " )
2015-02-23 15:20:55 +00:00
### Delete POD valid-pod by id
# Pre-condition: valid-pod POD is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " 'valid-pod:'
2015-02-23 15:20:55 +00:00
# Command
2015-08-20 02:09:57 +00:00
kubectl delete pod valid-pod " ${ kube_flags [@] } " --grace-period= 0
2015-02-23 15:20:55 +00:00
# Post-condition: no POD is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " ''
2015-02-23 15:20:55 +00:00
### Create POD valid-pod from dumped YAML
# Pre-condition: no POD is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " ''
2015-02-23 15:20:55 +00:00
# Command
2015-01-14 05:03:56 +00:00
echo " ${ output_pod } " | kubectl create -f - " ${ kube_flags [@] } "
2015-02-23 15:20:55 +00:00
# Post-condition: valid-pod POD is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " 'valid-pod:'
2015-02-23 15:20:55 +00:00
### Delete POD valid-pod from JSON
# Pre-condition: valid-pod POD is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " 'valid-pod:'
2015-02-23 15:20:55 +00:00
# Command
2015-08-20 02:09:57 +00:00
kubectl delete -f docs/admin/limitrange/valid-pod.yaml " ${ kube_flags [@] } " --grace-period= 0
2015-02-23 15:20:55 +00:00
# Post-condition: no POD is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " ''
2015-02-23 15:20:55 +00:00
### Create POD redis-master from JSON
# Pre-condition: no POD is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " ''
2015-02-23 15:20:55 +00:00
# Command
2015-08-04 14:46:51 +00:00
kubectl create -f docs/admin/limitrange/valid-pod.yaml " ${ kube_flags [@] } "
2015-02-23 15:20:55 +00:00
# Post-condition: valid-pod POD is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " 'valid-pod:'
2015-02-23 15:20:55 +00:00
### Delete POD valid-pod with label
# Pre-condition: valid-pod POD is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert "pods -l'name in (valid-pod)'" '{{range.items}}{{$id_field}}:{{end}}' 'valid-pod:'
2015-02-23 15:20:55 +00:00
# Command
2015-08-20 02:09:57 +00:00
kubectl delete pods -l'name in (valid-pod)' " ${ kube_flags [@] } " --grace-period= 0
2015-02-23 15:20:55 +00:00
# Post-condition: no POD is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert "pods -l'name in (valid-pod)'" '{{range.items}}{{$id_field}}:{{end}}' ''
2015-02-23 15:20:55 +00:00
### Create POD valid-pod from JSON
# Pre-condition: no POD is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " ''
2015-02-23 15:20:55 +00:00
# Command
2015-08-04 14:46:51 +00:00
kubectl create -f docs/admin/limitrange/valid-pod.yaml " ${ kube_flags [@] } "
2015-02-23 15:20:55 +00:00
# Post-condition: valid-pod POD is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " 'valid-pod:'
2015-02-23 15:20:55 +00:00
### Delete PODs with no parameter mustn't kill everything
# Pre-condition: valid-pod POD is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " 'valid-pod:'
2015-02-23 15:20:55 +00:00
# Command
! kubectl delete pods " ${ kube_flags [@] } "
# Post-condition: valid-pod POD is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " 'valid-pod:'
2015-02-23 15:20:55 +00:00
### Delete PODs with --all and a label selector is not permitted
# Pre-condition: valid-pod POD is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " 'valid-pod:'
2015-02-23 15:20:55 +00:00
# Command
2015-02-25 16:19:10 +00:00
! kubectl delete --all pods -l'name in (valid-pod)' " ${ kube_flags [@] } "
2015-02-23 15:20:55 +00:00
# Post-condition: valid-pod POD is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " 'valid-pod:'
2015-02-23 15:20:55 +00:00
### Delete all PODs
# Pre-condition: valid-pod POD is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " 'valid-pod:'
2015-02-23 15:20:55 +00:00
# Command
2015-08-20 02:09:57 +00:00
kubectl delete --all pods " ${ kube_flags [@] } " --grace-period= 0 # --all remove all the pods
2015-02-23 15:20:55 +00:00
# Post-condition: no POD is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert "pods -l'name in (valid-pod)'" '{{range.items}}{{$id_field}}:{{end}}' ''
2015-02-23 15:20:55 +00:00
### Create two PODs
# Pre-condition: no POD is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " ''
2015-02-23 15:20:55 +00:00
# Command
2015-08-04 14:46:51 +00:00
kubectl create -f docs/admin/limitrange/valid-pod.yaml " ${ kube_flags [@] } "
2015-02-19 14:17:23 +00:00
kubectl create -f examples/redis/redis-proxy.yaml " ${ kube_flags [@] } "
2015-02-23 15:20:55 +00:00
# Post-condition: valid-pod and redis-proxy PODs are running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " 'redis-proxy:valid-pod:'
2015-02-23 15:20:55 +00:00
### Delete multiple PODs at once
# Pre-condition: valid-pod and redis-proxy PODs are running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " 'redis-proxy:valid-pod:'
2015-02-23 15:20:55 +00:00
# Command
2015-08-20 02:09:57 +00:00
kubectl delete pods valid-pod redis-proxy " ${ kube_flags [@] } " --grace-period= 0 # delete multiple pods at once
2015-02-23 15:20:55 +00:00
# Post-condition: no POD is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " ''
2015-02-23 15:20:55 +00:00
### Create two PODs
# Pre-condition: no POD is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " ''
2015-02-23 15:20:55 +00:00
# Command
2015-08-04 14:46:51 +00:00
kubectl create -f docs/admin/limitrange/valid-pod.yaml " ${ kube_flags [@] } "
2015-02-19 14:17:23 +00:00
kubectl create -f examples/redis/redis-proxy.yaml " ${ kube_flags [@] } "
2015-02-23 15:20:55 +00:00
# Post-condition: valid-pod and redis-proxy PODs are running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " 'redis-proxy:valid-pod:'
2015-02-23 15:20:55 +00:00
### Stop multiple PODs at once
# Pre-condition: valid-pod and redis-proxy PODs are running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " 'redis-proxy:valid-pod:'
2015-02-23 15:20:55 +00:00
# Command
2015-10-30 06:12:20 +00:00
kubectl delete pods valid-pod redis-proxy " ${ kube_flags [@] } " --grace-period= 0 # delete multiple pods at once
2015-02-23 15:20:55 +00:00
# Post-condition: no POD is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " ''
2015-02-23 15:20:55 +00:00
### Create valid-pod POD
# Pre-condition: no POD is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " ''
2015-02-23 15:20:55 +00:00
# Command
2015-08-04 14:46:51 +00:00
kubectl create -f docs/admin/limitrange/valid-pod.yaml " ${ kube_flags [@] } "
2015-02-23 15:20:55 +00:00
# Post-condition: valid-pod POD is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " 'valid-pod:'
2015-02-21 09:16:39 +00:00
2015-02-23 15:20:55 +00:00
### Label the valid-pod POD
# Pre-condition: valid-pod is not labelled
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert 'pod valid-pod' " {{range $labels_field }}{{.}}:{{end}} " 'valid-pod:'
2015-02-23 15:20:55 +00:00
# Command
2015-02-05 23:20:27 +00:00
kubectl label pods valid-pod new-name= new-valid-pod " ${ kube_flags [@] } "
2015-02-23 15:20:55 +00:00
# Post-conditon: valid-pod is labelled
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert 'pod valid-pod' " {{range $labels_field }}{{.}}:{{end}} " 'valid-pod:new-valid-pod:'
2015-02-23 15:20:55 +00:00
### Delete POD by label
# Pre-condition: valid-pod POD is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " 'valid-pod:'
2015-02-23 15:20:55 +00:00
# Command
2015-08-20 02:09:57 +00:00
kubectl delete pods -lnew-name= new-valid-pod --grace-period= 0 " ${ kube_flags [@] } "
2015-02-23 15:20:55 +00:00
# Post-condition: no POD is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " ''
2015-02-23 15:20:55 +00:00
### Create valid-pod POD
# Pre-condition: no POD is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " ''
2015-02-23 15:20:55 +00:00
# Command
2015-08-04 14:46:51 +00:00
kubectl create -f docs/admin/limitrange/valid-pod.yaml " ${ kube_flags [@] } "
2015-02-23 15:20:55 +00:00
# Post-condition: valid-pod POD is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " 'valid-pod:'
2015-06-30 02:30:14 +00:00
2015-06-25 22:56:30 +00:00
## Patch pod can change image
# Command
kubectl patch " ${ kube_flags [@] } " pod valid-pod -p= '{"spec":{"containers":[{"name": "kubernetes-serve-hostname", "image": "nginx"}]}}'
# Post-condition: valid-pod POD has image nginx
kube::test::get_object_assert pods " {{range.items}}{{ $image_field }}:{{end}} " 'nginx:'
2015-09-30 15:58:42 +00:00
# prove that yaml input works too
YAML_PATCH = $'spec:\n containers:\n - name: kubernetes-serve-hostname\n image: changed-with-yaml\n'
kubectl patch " ${ kube_flags [@] } " pod valid-pod -p= " ${ YAML_PATCH } "
# Post-condition: valid-pod POD has image nginx
kube::test::get_object_assert pods " {{range.items}}{{ $image_field }}:{{end}} " 'changed-with-yaml:'
2015-08-06 09:24:02 +00:00
## Patch pod from JSON can change image
# Command
kubectl patch " ${ kube_flags [@] } " -f docs/admin/limitrange/valid-pod.yaml -p= '{"spec":{"containers":[{"name": "kubernetes-serve-hostname", "image": "kubernetes/pause"}]}}'
# Post-condition: valid-pod POD has image kubernetes/pause
kube::test::get_object_assert pods " {{range.items}}{{ $image_field }}:{{end}} " 'kubernetes/pause:'
2015-06-25 22:56:30 +00:00
2015-10-10 01:07:30 +00:00
## If resourceVersion is specified in the patch, it will be treated as a precondition, i.e., if the resourceVersion is different from that is stored in the server, the Patch should be rejected
ERROR_FILE = " ${ KUBE_TEMP } /conflict-error "
## If the resourceVersion is the same as the one stored in the server, the patch will be applied.
# Command
# Needs to retry because other party may change the resource.
for count in $( seq 0 3) ; do
resourceVersion = $( kubectl get " ${ kube_flags [@] } " pod valid-pod -o go-template= '{{ .metadata.resourceVersion }}' )
kubectl patch " ${ kube_flags [@] } " pod valid-pod -p= '{"spec":{"containers":[{"name": "kubernetes-serve-hostname", "image": "nginx"}]},"metadata":{"resourceVersion":"' $resourceVersion '"}}' 2> " ${ ERROR_FILE } " || true
if grep -q "the object has been modified" " ${ ERROR_FILE } " ; then
kube::log::status " retry $1 , error: $( cat ${ ERROR_FILE } ) "
rm " ${ ERROR_FILE } "
sleep $(( 2 * * count))
else
rm " ${ ERROR_FILE } "
kube::test::get_object_assert pods " {{range.items}}{{ $image_field }}:{{end}} " 'nginx:'
break
fi
done
## If the resourceVersion is the different from the one stored in the server, the patch will be rejected.
resourceVersion = $( kubectl get " ${ kube_flags [@] } " pod valid-pod -o go-template= '{{ .metadata.resourceVersion }}' )
( ( resourceVersion += 100) )
# Command
kubectl patch " ${ kube_flags [@] } " pod valid-pod -p= '{"spec":{"containers":[{"name": "kubernetes-serve-hostname", "image": "nginx"}]},"metadata":{"resourceVersion":"' $resourceVersion '"}}' 2> " ${ ERROR_FILE } " || true
# Post-condition: should get an error reporting the conflict
if grep -q "please apply your changes to the latest version and try again" " ${ ERROR_FILE } " ; then
kube::log::status " \"kubectl patch with resourceVersion $resourceVersion \" returns error as expected: $( cat ${ ERROR_FILE } ) "
else
kube::log::status " \"kubectl patch with resourceVersion $resourceVersion \" returns unexpected error or non-error: $( cat ${ ERROR_FILE } ) "
exit 1
fi
rm " ${ ERROR_FILE } "
2015-06-27 04:25:08 +00:00
## --force replace pod can change other field, e.g., spec.container.name
2015-06-18 17:15:52 +00:00
# Command
2015-09-04 23:33:11 +00:00
kubectl get " ${ kube_flags [@] } " pod valid-pod -o json | sed 's/"kubernetes-serve-hostname"/"replaced-k8s-serve-hostname"/g' > /tmp/tmp-valid-pod.json
kubectl replace " ${ kube_flags [@] } " --force -f /tmp/tmp-valid-pod.json
2015-06-27 04:25:08 +00:00
# Post-condition: spec.container.name = "replaced-k8s-serve-hostname"
kube::test::get_object_assert 'pod valid-pod' "{{(index .spec.containers 0).name}}" 'replaced-k8s-serve-hostname'
2015-09-04 23:33:11 +00:00
#cleaning
rm /tmp/tmp-valid-pod.json
## kubectl edit can update the image field of a POD. tmp-editor.sh is a fake editor
2015-10-10 01:07:30 +00:00
echo -e '#!/bin/bash\nsed -i "s/nginx/gcr.io\/google_containers\/serve_hostname/g" $1' > /tmp/tmp-editor.sh
2015-09-04 23:33:11 +00:00
chmod +x /tmp/tmp-editor.sh
EDITOR = /tmp/tmp-editor.sh kubectl edit " ${ kube_flags [@] } " pods/valid-pod
# Post-condition: valid-pod POD has image gcr.io/google_containers/serve_hostname
kube::test::get_object_assert pods " {{range.items}}{{ $image_field }}:{{end}} " 'gcr.io/google_containers/serve_hostname:'
# cleaning
rm /tmp/tmp-editor.sh
2015-10-23 15:31:03 +00:00
[ " $( EDITOR = cat kubectl edit pod/valid-pod 2>& 1 | grep 'Edit cancelled' ) " ]
[ " $( EDITOR = cat kubectl edit pod/valid-pod | grep 'name: valid-pod' ) " ]
[ " $( EDITOR = cat kubectl edit --windows-line-endings pod/valid-pod | file - | grep CRLF) " ]
[ ! " $( EDITOR = cat kubectl edit --windows-line-endings= false pod/valid-pod | file - | grep CRLF) " ]
2015-06-25 00:33:46 +00:00
2015-02-23 15:20:55 +00:00
### Overwriting an existing label is not permitted
# Pre-condition: name is valid-pod
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert 'pod valid-pod' " {{ ${ labels_field } .name}} " 'valid-pod'
2015-02-23 15:20:55 +00:00
# Command
! kubectl label pods valid-pod name = valid-pod-super-sayan " ${ kube_flags [@] } "
# Post-condition: name is still valid-pod
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert 'pod valid-pod' " {{ ${ labels_field } .name}} " 'valid-pod'
2015-02-23 15:20:55 +00:00
2015-03-26 01:52:12 +00:00
### --overwrite must be used to overwrite existing label, can be applied to all resources
2015-02-23 15:20:55 +00:00
# Pre-condition: name is valid-pod
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert 'pod valid-pod' " {{ ${ labels_field } .name}} " 'valid-pod'
2015-02-23 15:20:55 +00:00
# Command
2015-03-26 01:52:12 +00:00
kubectl label --overwrite pods --all name = valid-pod-super-sayan " ${ kube_flags [@] } "
2015-02-23 15:20:55 +00:00
# Post-condition: name is valid-pod-super-sayan
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert 'pod valid-pod' " {{ ${ labels_field } .name}} " 'valid-pod-super-sayan'
2015-02-23 15:20:55 +00:00
### Delete POD by label
# Pre-condition: valid-pod POD is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " 'valid-pod:'
2015-02-23 15:20:55 +00:00
# Command
2015-08-20 02:09:57 +00:00
kubectl delete pods -l'name in (valid-pod-super-sayan)' --grace-period= 0 " ${ kube_flags [@] } "
2015-02-23 15:20:55 +00:00
# Post-condition: no POD is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " ''
2015-02-23 15:20:55 +00:00
2015-06-14 16:39:58 +00:00
### Create two PODs from 1 yaml file
# Pre-condition: no POD is running
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " ''
# Command
2015-07-15 00:59:59 +00:00
kubectl create -f docs/user-guide/multi-pod.yaml " ${ kube_flags [@] } "
2015-06-14 16:39:58 +00:00
# Post-condition: valid-pod and redis-proxy PODs are running
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " 'redis-master:redis-proxy:'
### Delete two PODs from 1 yaml file
# Pre-condition: redis-master and redis-proxy PODs are running
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " 'redis-master:redis-proxy:'
# Command
2015-07-15 00:59:59 +00:00
kubectl delete -f docs/user-guide/multi-pod.yaml " ${ kube_flags [@] } "
2015-06-14 16:39:58 +00:00
# Post-condition: no PODs are running
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " ''
2015-02-23 15:20:55 +00:00
2015-10-23 22:33:52 +00:00
## kubectl apply should update configuration annotations only if apply is already called
## 1. kubectl create doesn't set the annotation
# Pre-Condition: no POD is running
kube::test::get_object_assert pods " {{range.items}}{{ $id_field }}:{{end}} " ''
# Command: create a pod "test-pod"
kubectl create -f hack/testdata/pod.yaml " ${ kube_flags [@] } "
# Post-Condition: pod "test-pod" is running
kube::test::get_object_assert 'pods test-pod' " {{ ${ labels_field } .name}} " 'test-pod-label'
# Post-Condition: pod "test-pod" doesn't have configuration annotation
! [ [ " $( kubectl get pods test-pod -o yaml " ${ kube_flags [@] } " | grep kubectl.kubernetes.io/last-applied-configuration) " ] ]
## 2. kubectl replace doesn't set the annotation
kubectl get pods test-pod -o yaml " ${ kube_flags [@] } " | sed 's/test-pod-label/test-pod-replaced/g' > " ${ KUBE_TEMP } " /test-pod-replace.yaml
# Command: replace the pod "test-pod"
kubectl replace -f " ${ KUBE_TEMP } " /test-pod-replace.yaml " ${ kube_flags [@] } "
# Post-Condition: pod "test-pod" is replaced
kube::test::get_object_assert 'pods test-pod' " {{ ${ labels_field } .name}} " 'test-pod-replaced'
# Post-Condition: pod "test-pod" doesn't have configuration annotation
! [ [ " $( kubectl get pods test-pod -o yaml " ${ kube_flags [@] } " | grep kubectl.kubernetes.io/last-applied-configuration) " ] ]
## 3. kubectl apply does set the annotation
# Command: apply the pod "test-pod"
kubectl apply -f hack/testdata/pod-apply.yaml " ${ kube_flags [@] } "
# Post-Condition: pod "test-pod" is applied
kube::test::get_object_assert 'pods test-pod' " {{ ${ labels_field } .name}} " 'test-pod-applied'
# Post-Condition: pod "test-pod" has configuration annotation
[ [ " $( kubectl get pods test-pod -o yaml " ${ kube_flags [@] } " | grep kubectl.kubernetes.io/last-applied-configuration) " ] ]
kubectl get pods test-pod -o yaml " ${ kube_flags [@] } " | grep kubectl.kubernetes.io/last-applied-configuration > " ${ KUBE_TEMP } " /annotation-configuration
## 4. kubectl replace updates an existing annotation
kubectl get pods test-pod -o yaml " ${ kube_flags [@] } " | sed 's/test-pod-applied/test-pod-replaced/g' > " ${ KUBE_TEMP } " /test-pod-replace.yaml
# Command: replace the pod "test-pod"
kubectl replace -f " ${ KUBE_TEMP } " /test-pod-replace.yaml " ${ kube_flags [@] } "
# Post-Condition: pod "test-pod" is replaced
kube::test::get_object_assert 'pods test-pod' " {{ ${ labels_field } .name}} " 'test-pod-replaced'
# Post-Condition: pod "test-pod" has configuration annotation, and it's updated (different from the annotation when it's applied)
[ [ " $( kubectl get pods test-pod -o yaml " ${ kube_flags [@] } " | grep kubectl.kubernetes.io/last-applied-configuration) " ] ]
kubectl get pods test-pod -o yaml " ${ kube_flags [@] } " | grep kubectl.kubernetes.io/last-applied-configuration > " ${ KUBE_TEMP } " /annotation-configuration-replaced
! [ [ $( diff -q " ${ KUBE_TEMP } " /annotation-configuration " ${ KUBE_TEMP } " /annotation-configuration-replaced > /dev/null) ] ]
# Clean up
rm " ${ KUBE_TEMP } " /test-pod-replace.yaml " ${ KUBE_TEMP } " /annotation-configuration " ${ KUBE_TEMP } " /annotation-configuration-replaced
2015-02-23 15:20:55 +00:00
##############
# Namespaces #
##############
2014-12-12 01:24:54 +00:00
2015-02-23 15:20:55 +00:00
### Create POD valid-pod in specific namespace
# Pre-condition: no POD is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert 'pods --namespace=other' " {{range.items}}{{ $id_field }}:{{end}} " ''
2015-02-23 15:20:55 +00:00
# Command
2015-08-04 14:46:51 +00:00
kubectl create " ${ kube_flags [@] } " --namespace= other -f docs/admin/limitrange/valid-pod.yaml
2015-02-23 15:20:55 +00:00
# Post-condition: valid-pod POD is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert 'pods --namespace=other' " {{range.items}}{{ $id_field }}:{{end}} " 'valid-pod:'
2015-02-23 15:20:55 +00:00
### Delete POD valid-pod in specific namespace
# Pre-condition: valid-pod POD is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert 'pods --namespace=other' " {{range.items}}{{ $id_field }}:{{end}} " 'valid-pod:'
2015-02-23 15:20:55 +00:00
# Command
2015-08-20 02:09:57 +00:00
kubectl delete " ${ kube_flags [@] } " pod --namespace= other valid-pod --grace-period= 0
2015-02-23 15:20:55 +00:00
# Post-condition: no POD is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert 'pods --namespace=other' " {{range.items}}{{ $id_field }}:{{end}} " ''
2015-02-23 15:20:55 +00:00
2015-03-04 00:54:17 +00:00
#################
# Pod templates #
#################
### Create PODTEMPLATE
# Pre-condition: no PODTEMPLATE
kube::test::get_object_assert podtemplates "{{range.items}}{{.metadata.name}}:{{end}}" ''
# Command
2015-07-15 00:59:59 +00:00
kubectl create -f docs/user-guide/walkthrough/podtemplate.json " ${ kube_flags [@] } "
2015-03-04 00:54:17 +00:00
# Post-condition: nginx PODTEMPLATE is available
kube::test::get_object_assert podtemplates "{{range.items}}{{.metadata.name}}:{{end}}" 'nginx:'
### Printing pod templates works
kubectl get podtemplates " ${ kube_flags [@] } "
[ [ " $( kubectl get podtemplates -o yaml " ${ kube_flags [@] } " | grep nginx) " ] ]
### Delete nginx pod template by name
# Pre-condition: nginx pod template is available
kube::test::get_object_assert podtemplates "{{range.items}}{{.metadata.name}}:{{end}}" 'nginx:'
# Command
kubectl delete podtemplate nginx " ${ kube_flags [@] } "
# Post-condition: No templates exist
kube::test::get_object_assert podtemplate "{{range.items}}{{.metadata.name}}:{{end}}" ''
2015-02-23 15:20:55 +00:00
############
# Services #
############
2015-02-12 19:21:47 +00:00
2015-01-08 17:42:20 +00:00
kube::log::status " Testing kubectl( ${ version } :services) "
2015-02-23 15:20:55 +00:00
### Create redis-master service from JSON
# Pre-condition: Only the default kubernetes services are running
2015-05-06 21:54:54 +00:00
kube::test::get_object_assert services " {{range.items}}{{ $id_field }}:{{end}} " 'kubernetes:'
2015-02-23 15:20:55 +00:00
# Command
2015-06-22 23:27:44 +00:00
kubectl create -f examples/guestbook/redis-master-service.yaml " ${ kube_flags [@] } "
2015-02-23 15:20:55 +00:00
# Post-condition: redis-master service is running
2015-05-06 21:54:54 +00:00
kube::test::get_object_assert services " {{range.items}}{{ $id_field }}:{{end}} " 'kubernetes:redis-master:'
2015-03-23 16:23:15 +00:00
# Describe command should print detailed information
kube::test::describe_object_assert services 'redis-master' "Name:" "Labels:" "Selector:" "IP:" "Port:" "Endpoints:" "Session Affinity:"
2015-08-04 07:12:29 +00:00
# Describe command (resource only) should print detailed information
kube::test::describe_resource_assert services "Name:" "Labels:" "Selector:" "IP:" "Port:" "Endpoints:" "Session Affinity:"
2015-02-23 15:20:55 +00:00
### Dump current redis-master service
2015-07-23 04:52:05 +00:00
output_service = $( kubectl get service redis-master -o json --output-version= v1 " ${ kube_flags [@] } " )
2015-02-23 15:20:55 +00:00
### Delete redis-master-service by id
# Pre-condition: redis-master service is running
2015-05-06 21:54:54 +00:00
kube::test::get_object_assert services " {{range.items}}{{ $id_field }}:{{end}} " 'kubernetes:redis-master:'
2015-02-23 15:20:55 +00:00
# Command
2015-02-05 23:20:27 +00:00
kubectl delete service redis-master " ${ kube_flags [@] } "
2015-02-23 15:20:55 +00:00
# Post-condition: Only the default kubernetes services are running
2015-05-06 21:54:54 +00:00
kube::test::get_object_assert services " {{range.items}}{{ $id_field }}:{{end}} " 'kubernetes:'
2015-02-23 15:20:55 +00:00
### Create redis-master-service from dumped JSON
# Pre-condition: Only the default kubernetes services are running
2015-05-06 21:54:54 +00:00
kube::test::get_object_assert services " {{range.items}}{{ $id_field }}:{{end}} " 'kubernetes:'
2015-02-23 15:20:55 +00:00
# Command
2015-01-14 05:03:56 +00:00
echo " ${ output_service } " | kubectl create -f - " ${ kube_flags [@] } "
2015-02-23 15:20:55 +00:00
# Post-condition: redis-master service is running
2015-05-06 21:54:54 +00:00
kube::test::get_object_assert services " {{range.items}}{{ $id_field }}:{{end}} " 'kubernetes:redis-master:'
2015-02-23 15:20:55 +00:00
### Create redis-master-${version}-test service
# Pre-condition: redis-master-service service is running
2015-05-06 21:54:54 +00:00
kube::test::get_object_assert services " {{range.items}}{{ $id_field }}:{{end}} " 'kubernetes:redis-master:'
2015-02-23 15:20:55 +00:00
# Command
2015-01-14 17:38:36 +00:00
kubectl create -f - " ${ kube_flags [@] } " << __EOF__
2015-04-13 22:55:28 +00:00
{
"kind" : "Service" ,
2015-06-30 02:30:14 +00:00
"apiVersion" : "v1" ,
2015-04-13 22:55:28 +00:00
"metadata" : {
"name" : " service- ${ version } -test "
} ,
"spec" : {
"ports" : [
2015-01-14 17:38:36 +00:00
{
2015-04-13 22:55:28 +00:00
"protocol" : "TCP" ,
"port" : 80,
"targetPort" : 80
2015-01-14 17:38:36 +00:00
}
2015-04-13 22:55:28 +00:00
]
}
}
2015-01-14 17:38:36 +00:00
__EOF__
2015-02-23 15:20:55 +00:00
# Post-condition:redis-master-service service is running
2015-05-06 21:54:54 +00:00
kube::test::get_object_assert services " {{range.items}}{{ $id_field }}:{{end}} " 'kubernetes:redis-master:service-.*-test:'
2015-02-23 15:20:55 +00:00
### Identity
2015-06-27 04:25:08 +00:00
kubectl get service " ${ kube_flags [@] } " service-${ version } -test -o json | kubectl replace " ${ kube_flags [@] } " -f -
2015-02-23 15:20:55 +00:00
### Delete services by id
# Pre-condition: redis-master-service service is running
2015-05-06 21:54:54 +00:00
kube::test::get_object_assert services " {{range.items}}{{ $id_field }}:{{end}} " 'kubernetes:redis-master:service-.*-test:'
2015-02-23 15:20:55 +00:00
# Command
2015-02-05 23:20:27 +00:00
kubectl delete service redis-master " ${ kube_flags [@] } "
2015-02-23 15:20:55 +00:00
kubectl delete service " service- ${ version } -test " " ${ kube_flags [@] } "
# Post-condition: Only the default kubernetes services are running
2015-05-06 21:54:54 +00:00
kube::test::get_object_assert services " {{range.items}}{{ $id_field }}:{{end}} " 'kubernetes:'
2015-02-23 15:20:55 +00:00
### Create two services
# Pre-condition: Only the default kubernetes services are running
2015-05-06 21:54:54 +00:00
kube::test::get_object_assert services " {{range.items}}{{ $id_field }}:{{end}} " 'kubernetes:'
2015-02-23 15:20:55 +00:00
# Command
2015-06-22 23:27:44 +00:00
kubectl create -f examples/guestbook/redis-master-service.yaml " ${ kube_flags [@] } "
kubectl create -f examples/guestbook/redis-slave-service.yaml " ${ kube_flags [@] } "
2015-02-23 15:20:55 +00:00
# Post-condition: redis-master and redis-slave services are running
2015-05-06 21:54:54 +00:00
kube::test::get_object_assert services " {{range.items}}{{ $id_field }}:{{end}} " 'kubernetes:redis-master:redis-slave:'
2015-02-23 15:20:55 +00:00
### Delete multiple services at once
# Pre-condition: redis-master and redis-slave services are running
2015-05-06 21:54:54 +00:00
kube::test::get_object_assert services " {{range.items}}{{ $id_field }}:{{end}} " 'kubernetes:redis-master:redis-slave:'
2015-02-23 15:20:55 +00:00
# Command
2015-03-11 05:43:36 +00:00
kubectl delete services redis-master redis-slave " ${ kube_flags [@] } " # delete multiple services at once
2015-02-23 15:20:55 +00:00
# Post-condition: Only the default kubernetes services are running
2015-05-06 21:54:54 +00:00
kube::test::get_object_assert services " {{range.items}}{{ $id_field }}:{{end}} " 'kubernetes:'
2015-02-23 15:20:55 +00:00
###########################
# Replication controllers #
###########################
2014-12-12 01:24:54 +00:00
2015-01-08 17:42:20 +00:00
kube::log::status " Testing kubectl( ${ version } :replicationcontrollers) "
2015-02-23 15:20:55 +00:00
2015-06-18 19:00:19 +00:00
### Create and stop controller, make sure it doesn't leak pods
# Pre-condition: no replication controller is running
kube::test::get_object_assert rc " {{range.items}}{{ $id_field }}:{{end}} " ''
# Command
2015-06-22 23:27:44 +00:00
kubectl create -f examples/guestbook/frontend-controller.yaml " ${ kube_flags [@] } "
2015-10-30 06:12:20 +00:00
kubectl delete rc frontend " ${ kube_flags [@] } "
2015-06-18 19:00:19 +00:00
# Post-condition: no pods from frontend controller
kube::test::get_object_assert 'pods -l "name=frontend"' " {{range.items}}{{ $id_field }}:{{end}} " ''
2015-02-23 15:20:55 +00:00
### Create replication controller frontend from JSON
# Pre-condition: no replication controller is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert rc " {{range.items}}{{ $id_field }}:{{end}} " ''
2015-02-23 15:20:55 +00:00
# Command
2015-06-22 23:27:44 +00:00
kubectl create -f examples/guestbook/frontend-controller.yaml " ${ kube_flags [@] } "
2015-02-23 15:20:55 +00:00
# Post-condition: frontend replication controller is running
2015-04-22 21:37:46 +00:00
kube::test::get_object_assert rc " {{range.items}}{{ $id_field }}:{{end}} " 'frontend:'
2015-03-23 16:23:15 +00:00
# Describe command should print detailed information
2015-04-22 21:37:46 +00:00
kube::test::describe_object_assert rc 'frontend' "Name:" "Image(s):" "Labels:" "Selector:" "Replicas:" "Pods Status:"
2015-08-04 07:12:29 +00:00
# Describe command (resource only) should print detailed information
kube::test::describe_resource_assert rc "Name:" "Name:" "Image(s):" "Labels:" "Selector:" "Replicas:" "Pods Status:"
2015-02-23 15:20:55 +00:00
2015-05-21 21:10:25 +00:00
### Scale replication controller frontend with current-replicas and replicas
2015-02-23 15:20:55 +00:00
# Pre-condition: 3 replicas
2015-04-22 21:37:46 +00:00
kube::test::get_object_assert 'rc frontend' " {{ $rc_replicas_field }} " '3'
2015-02-23 15:20:55 +00:00
# Command
2015-05-21 21:10:25 +00:00
kubectl scale --current-replicas= 3 --replicas= 2 replicationcontrollers frontend " ${ kube_flags [@] } "
2015-02-23 15:20:55 +00:00
# Post-condition: 2 replicas
2015-04-22 21:37:46 +00:00
kube::test::get_object_assert 'rc frontend' " {{ $rc_replicas_field }} " '2'
2015-02-23 15:20:55 +00:00
2015-05-21 21:10:25 +00:00
### Scale replication controller frontend with (wrong) current-replicas and replicas
2015-02-23 15:20:55 +00:00
# Pre-condition: 2 replicas
2015-04-22 21:37:46 +00:00
kube::test::get_object_assert 'rc frontend' " {{ $rc_replicas_field }} " '2'
2015-02-23 15:20:55 +00:00
# Command
2015-05-21 21:10:25 +00:00
! kubectl scale --current-replicas= 3 --replicas= 2 replicationcontrollers frontend " ${ kube_flags [@] } "
2015-02-23 15:20:55 +00:00
# Post-condition: nothing changed
2015-04-22 21:37:46 +00:00
kube::test::get_object_assert 'rc frontend' " {{ $rc_replicas_field }} " '2'
2015-02-23 15:20:55 +00:00
2015-05-21 21:10:25 +00:00
### Scale replication controller frontend with replicas only
2015-02-23 15:20:55 +00:00
# Pre-condition: 2 replicas
2015-04-22 21:37:46 +00:00
kube::test::get_object_assert 'rc frontend' " {{ $rc_replicas_field }} " '2'
2015-02-23 15:20:55 +00:00
# Command
2015-05-21 21:10:25 +00:00
kubectl scale --replicas= 3 replicationcontrollers frontend " ${ kube_flags [@] } "
2015-02-23 15:20:55 +00:00
# Post-condition: 3 replicas
2015-04-22 21:37:46 +00:00
kube::test::get_object_assert 'rc frontend' " {{ $rc_replicas_field }} " '3'
2015-02-23 15:20:55 +00:00
2015-08-11 09:05:28 +00:00
### Scale replication controller from JSON with replicas only
# Pre-condition: 3 replicas
kube::test::get_object_assert 'rc frontend' " {{ $rc_replicas_field }} " '3'
# Command
kubectl scale --replicas= 2 -f examples/guestbook/frontend-controller.yaml " ${ kube_flags [@] } "
# Post-condition: 2 replicas
kube::test::get_object_assert 'rc frontend' " {{ $rc_replicas_field }} " '2'
2015-06-29 09:37:11 +00:00
### Scale multiple replication controllers
kubectl create -f examples/guestbook/redis-master-controller.yaml " ${ kube_flags [@] } "
kubectl create -f examples/guestbook/redis-slave-controller.yaml " ${ kube_flags [@] } "
# Command
kubectl scale rc/redis-master rc/redis-slave --replicas= 4
# Post-condition: 4 replicas each
kube::test::get_object_assert 'rc redis-master' " {{ $rc_replicas_field }} " '4'
kube::test::get_object_assert 'rc redis-slave' " {{ $rc_replicas_field }} " '4'
# Clean-up
kubectl delete rc redis-{ master,slave} " ${ kube_flags [@] } "
2015-03-26 02:35:26 +00:00
### Expose replication controller as service
2015-08-11 09:05:28 +00:00
# Pre-condition: 2 replicas
kube::test::get_object_assert 'rc frontend' " {{ $rc_replicas_field }} " '2'
2015-03-26 02:35:26 +00:00
# Command
2015-04-22 21:37:46 +00:00
kubectl expose rc frontend --port= 80 " ${ kube_flags [@] } "
2015-07-16 21:18:17 +00:00
# Post-condition: service exists and the port is unnamed
kube::test::get_object_assert 'service frontend' " {{ $port_name }} {{ $port_field }} " '<no value> 80'
2015-03-26 02:35:26 +00:00
# Command
2015-05-13 12:14:44 +00:00
kubectl expose service frontend --port= 443 --name= frontend-2 " ${ kube_flags [@] } "
2015-07-16 21:18:17 +00:00
# Post-condition: service exists and the port is unnamed
kube::test::get_object_assert 'service frontend-2' " {{ $port_name }} {{ $port_field }} " '<no value> 443'
2015-03-26 02:35:26 +00:00
# Command
2015-08-04 14:46:51 +00:00
kubectl create -f docs/admin/limitrange/valid-pod.yaml " ${ kube_flags [@] } "
2015-05-13 12:14:44 +00:00
kubectl expose pod valid-pod --port= 444 --name= frontend-3 " ${ kube_flags [@] } "
2015-07-16 21:18:17 +00:00
# Post-condition: service exists and the port is unnamed
kube::test::get_object_assert 'service frontend-3' " {{ $port_name }} {{ $port_field }} " '<no value> 444'
# Create a service using service/v1 generator
kubectl expose rc frontend --port= 80 --name= frontend-4 --generator= service/v1 " ${ kube_flags [@] } "
# Post-condition: service exists and the port is named default.
kube::test::get_object_assert 'service frontend-4' " {{ $port_name }} {{ $port_field }} " 'default 80'
2015-07-17 01:02:36 +00:00
# Verify that expose service works without specifying a port.
kubectl expose service frontend --name= frontend-5 " ${ kube_flags [@] } "
# Post-condition: service exists with the same port as the original service.
kube::test::get_object_assert 'service frontend-5' " {{ $port_field }} " '80'
2015-03-26 02:35:26 +00:00
# Cleanup services
kubectl delete pod valid-pod " ${ kube_flags [@] } "
2015-07-17 01:02:36 +00:00
kubectl delete service frontend{ ,-2,-3,-4,-5} " ${ kube_flags [@] } "
2015-03-26 02:35:26 +00:00
2015-08-26 08:06:40 +00:00
### Expose negative invalid resource test
# Pre-condition: don't need
# Command
output_message = $( ! kubectl expose nodes 127.0.0.1 2>& 1 " ${ kube_flags [@] } " )
2015-10-20 15:50:20 +00:00
# Post-condition: the error message has "cannot expose" string
kube::test::if_has_string " ${ output_message } " 'cannot expose'
2015-08-26 08:06:40 +00:00
2015-09-29 11:39:10 +00:00
### Try to generate a service with invalid name (exceeding maximum valid size)
# Pre-condition: use --name flag
output_message = $( ! kubectl expose -f hack/testdata/pod-with-large-name.yaml --name= invalid-large-service-name --port= 8081 2>& 1 " ${ kube_flags [@] } " )
# Post-condition: should fail due to invalid name
kube::test::if_has_string " ${ output_message } " 'metadata.name: invalid value'
# Pre-condition: default run without --name flag; should succeed by truncating the inherited name
output_message = $( kubectl expose -f hack/testdata/pod-with-large-name.yaml --port= 8081 2>& 1 " ${ kube_flags [@] } " )
# Post-condition: inherited name from pod has been truncated
kube::test::if_has_string " ${ output_message } " '\"kubernetes-serve-hostnam\" exposed'
# Clean-up
kubectl delete svc kubernetes-serve-hostnam " ${ kube_flags [@] } "
2015-10-12 09:12:36 +00:00
### Expose multiport object as a new service
# Pre-condition: don't use --port flag
output_message = $( kubectl expose -f docs/admin/high-availability/etcd.yaml --selector= test = etcd 2>& 1 " ${ kube_flags [@] } " )
# Post-condition: expose succeeded
kube::test::if_has_string " ${ output_message } " '\"etcd-server\" exposed'
# Post-condition: generated service has both ports from the exposed pod
kube::test::get_object_assert 'service etcd-server' " {{ $port_name }} {{ $port_field }} " 'port-1 2380'
kube::test::get_object_assert 'service etcd-server' " {{ $second_port_name }} {{ $second_port_field }} " 'port-2 4001'
# Clean-up
kubectl delete svc etcd-server " ${ kube_flags [@] } "
2015-02-23 15:20:55 +00:00
### Delete replication controller with id
# Pre-condition: frontend replication controller is running
2015-04-22 21:37:46 +00:00
kube::test::get_object_assert rc " {{range.items}}{{ $id_field }}:{{end}} " 'frontend:'
2015-02-23 15:20:55 +00:00
# Command
2015-10-30 06:12:20 +00:00
kubectl delete rc frontend " ${ kube_flags [@] } "
2015-02-23 15:20:55 +00:00
# Post-condition: no replication controller is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert rc " {{range.items}}{{ $id_field }}:{{end}} " ''
2015-02-23 15:20:55 +00:00
### Create two replication controllers
# Pre-condition: no replication controller is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert rc " {{range.items}}{{ $id_field }}:{{end}} " ''
2015-02-23 15:20:55 +00:00
# Command
2015-06-22 23:27:44 +00:00
kubectl create -f examples/guestbook/frontend-controller.yaml " ${ kube_flags [@] } "
kubectl create -f examples/guestbook/redis-slave-controller.yaml " ${ kube_flags [@] } "
2015-02-23 15:20:55 +00:00
# Post-condition: frontend and redis-slave
2015-04-22 21:37:46 +00:00
kube::test::get_object_assert rc " {{range.items}}{{ $id_field }}:{{end}} " 'frontend:redis-slave:'
2015-02-23 15:20:55 +00:00
### Delete multiple controllers at once
# Pre-condition: frontend and redis-slave
2015-04-22 21:37:46 +00:00
kube::test::get_object_assert rc " {{range.items}}{{ $id_field }}:{{end}} " 'frontend:redis-slave:'
2015-02-23 15:20:55 +00:00
# Command
2015-10-30 06:12:20 +00:00
kubectl delete rc frontend redis-slave " ${ kube_flags [@] } " # delete multiple controllers at once
2015-02-23 15:20:55 +00:00
# Post-condition: no replication controller is running
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert rc " {{range.items}}{{ $id_field }}:{{end}} " ''
2015-02-23 15:20:55 +00:00
2015-10-15 22:15:13 +00:00
### Auto scale replication controller
# Pre-condition: no replication controller is running
kube::test::get_object_assert rc " {{range.items}}{{ $id_field }}:{{end}} " ''
# Command
kubectl create -f examples/guestbook/frontend-controller.yaml " ${ kube_flags [@] } "
kube::test::get_object_assert rc " {{range.items}}{{ $id_field }}:{{end}} " 'frontend:'
# autoscale 1~2 pods, CPU utilization 70%, rc specified by file
kubectl autoscale -f examples/guestbook/frontend-controller.yaml " ${ kube_flags [@] } " --max= 2 --cpu-percent= 70
kube::test::get_object_assert 'hpa frontend' " {{ $hpa_min_field }} {{ $hpa_max_field }} {{ $hpa_cpu_field }} " '1 2 70'
kubectl delete hpa frontend " ${ kube_flags [@] } "
# autoscale 2~3 pods, default CPU utilization (80%), rc specified by name
kubectl autoscale rc frontend " ${ kube_flags [@] } " --min= 2 --max= 3
kube::test::get_object_assert 'hpa frontend' " {{ $hpa_min_field }} {{ $hpa_max_field }} {{ $hpa_cpu_field }} " '2 3 80'
kubectl delete hpa frontend " ${ kube_flags [@] } "
# autoscale without specifying --max should fail
! kubectl autoscale rc frontend " ${ kube_flags [@] } "
# Clean up
kubectl delete rc frontend " ${ kube_flags [@] } "
2015-09-30 01:50:05 +00:00
######################
# Multiple Resources #
######################
kube::log::status " Testing kubectl( ${ version } :multiple resources) "
2015-10-02 20:23:00 +00:00
FILES = " hack/testdata/multi-resource-yaml
hack/testdata/multi-resource-list
2015-10-03 00:47:05 +00:00
hack/testdata/multi-resource-json
hack/testdata/multi-resource-rclist
hack/testdata/multi-resource-svclist"
2015-10-02 20:23:00 +00:00
YAML = ".yaml"
JSON = ".json"
for file in $FILES ; do
if [ -f $file $YAML ]
then
file = $file $YAML
replace_file = " ${ file %.yaml } -modify.yaml "
else
file = $file $JSON
replace_file = " ${ file %.json } -modify.json "
fi
2015-10-03 00:47:05 +00:00
has_svc = true
has_rc = true
two_rcs = false
two_svcs = false
if [ [ " ${ file } " = = *rclist* ] ] ; then
has_svc = false
two_rcs = true
fi
if [ [ " ${ file } " = = *svclist* ] ] ; then
has_rc = false
two_svcs = true
fi
### Create, get, describe, replace, label, annotate, and then delete service nginxsvc and replication controller my-nginx from 5 types of files:
2015-10-02 20:23:00 +00:00
### 1) YAML, separated by ---; 2) JSON, with a List type; 3) JSON, with JSON object concatenation
2015-10-03 00:47:05 +00:00
### 4) JSON, with a ReplicationControllerList type; 5) JSON, with a ServiceList type
echo " Testing with file ${ file } and replace with file ${ replace_file } "
2015-10-02 20:23:00 +00:00
# Pre-condition: no service (other than default kubernetes services) or replication controller is running
kube::test::get_object_assert services " {{range.items}}{{ $id_field }}:{{end}} " 'kubernetes:'
kube::test::get_object_assert rc " {{range.items}}{{ $id_field }}:{{end}} " ''
# Command
2015-10-09 07:12:19 +00:00
kubectl create -f " ${ file } " " ${ kube_flags [@] } "
2015-10-03 00:47:05 +00:00
# Post-condition: mock service (and mock2) is running
if [ " $has_svc " = true ] ; then
if [ " $two_svcs " = true ] ; then
kube::test::get_object_assert services " {{range.items}}{{ $id_field }}:{{end}} " 'kubernetes:mock:mock2:'
else
kube::test::get_object_assert services " {{range.items}}{{ $id_field }}:{{end}} " 'kubernetes:mock:'
fi
fi
# Post-condition: mock rc (and mock2) is running
if [ " $has_rc " = true ] ; then
if [ " $two_rcs " = true ] ; then
kube::test::get_object_assert rc " {{range.items}}{{ $id_field }}:{{end}} " 'mock:mock2:'
else
kube::test::get_object_assert rc " {{range.items}}{{ $id_field }}:{{end}} " 'mock:'
fi
fi
2015-10-02 20:23:00 +00:00
# Command
2015-10-03 00:47:05 +00:00
kubectl get -f " ${ file } " " ${ kube_flags [@] } "
2015-10-14 22:06:06 +00:00
# Command: watching multiple resources should return "not supported" error
WATCH_ERROR_FILE = " ${ KUBE_TEMP } /kubectl-watch-error "
kubectl get -f " ${ file } " " ${ kube_flags [@] } " "--watch" 2> ${ WATCH_ERROR_FILE } || true
if ! grep -q "watch is only supported on individual resources and resource collections" " ${ WATCH_ERROR_FILE } " ; then
kube::log::error_exit " kubectl watch multiple resource returns unexpected error or non-error: $( cat ${ WATCH_ERROR_FILE } ) " "1"
fi
2015-10-03 00:47:05 +00:00
kubectl describe -f " ${ file } " " ${ kube_flags [@] } "
2015-10-02 20:23:00 +00:00
# Command
2015-10-09 07:12:19 +00:00
kubectl replace -f $replace_file --force " ${ kube_flags [@] } "
2015-10-03 00:47:05 +00:00
# Post-condition: mock service (and mock2) and mock rc (and mock2) are replaced
if [ " $has_svc " = true ] ; then
kube::test::get_object_assert 'services mock' " {{ ${ labels_field } .status}} " 'replaced'
if [ " $two_svcs " = true ] ; then
kube::test::get_object_assert 'services mock2' " {{ ${ labels_field } .status}} " 'replaced'
fi
fi
if [ " $has_rc " = true ] ; then
kube::test::get_object_assert 'rc mock' " {{ ${ labels_field } .status}} " 'replaced'
if [ " $two_rcs " = true ] ; then
kube::test::get_object_assert 'rc mock2' " {{ ${ labels_field } .status}} " 'replaced'
fi
fi
2015-10-20 22:22:54 +00:00
# Command: kubectl edit multiple resources
temp_editor = " ${ KUBE_TEMP } /tmp-editor.sh "
echo -e '#!/bin/bash\nsed -i "s/status\:\ replaced/status\:\ edited/g" $@' > " ${ temp_editor } "
chmod +x " ${ temp_editor } "
EDITOR = " ${ temp_editor } " kubectl edit " ${ kube_flags [@] } " -f " ${ file } "
# Post-condition: mock service (and mock2) and mock rc (and mock2) are edited
if [ " $has_svc " = true ] ; then
kube::test::get_object_assert 'services mock' " {{ ${ labels_field } .status}} " 'edited'
if [ " $two_svcs " = true ] ; then
kube::test::get_object_assert 'services mock2' " {{ ${ labels_field } .status}} " 'edited'
fi
fi
if [ " $has_rc " = true ] ; then
kube::test::get_object_assert 'rc mock' " {{ ${ labels_field } .status}} " 'edited'
if [ " $two_rcs " = true ] ; then
kube::test::get_object_assert 'rc mock2' " {{ ${ labels_field } .status}} " 'edited'
fi
fi
# cleaning
rm " ${ temp_editor } "
2015-10-02 20:23:00 +00:00
# Command
2015-10-08 20:08:33 +00:00
# We need to set --overwrite, because otherwise, if the first attempt to run "kubectl label"
# fails on some, but not all, of the resources, retries will fail because it tries to modify
# existing labels.
kubectl-with-retry label -f $file labeled = true --overwrite " ${ kube_flags [@] } "
2015-10-03 00:47:05 +00:00
# Post-condition: mock service and mock rc (and mock2) are labeled
if [ " $has_svc " = true ] ; then
kube::test::get_object_assert 'services mock' " {{ ${ labels_field } .labeled}} " 'true'
if [ " $two_svcs " = true ] ; then
kube::test::get_object_assert 'services mock2' " {{ ${ labels_field } .labeled}} " 'true'
fi
fi
if [ " $has_rc " = true ] ; then
kube::test::get_object_assert 'rc mock' " {{ ${ labels_field } .labeled}} " 'true'
if [ " $two_rcs " = true ] ; then
kube::test::get_object_assert 'rc mock2' " {{ ${ labels_field } .labeled}} " 'true'
fi
fi
2015-10-02 20:23:00 +00:00
# Command
2015-10-08 20:08:33 +00:00
# Command
# We need to set --overwrite, because otherwise, if the first attempt to run "kubectl annotate"
# fails on some, but not all, of the resources, retries will fail because it tries to modify
# existing annotations.
kubectl-with-retry annotate -f $file annotated = true --overwrite " ${ kube_flags [@] } "
2015-10-03 00:47:05 +00:00
# Post-condition: mock service (and mock2) and mock rc (and mock2) are annotated
if [ " $has_svc " = true ] ; then
kube::test::get_object_assert 'services mock' " {{ ${ annotations_field } .annotated}} " 'true'
if [ " $two_svcs " = true ] ; then
kube::test::get_object_assert 'services mock2' " {{ ${ annotations_field } .annotated}} " 'true'
fi
fi
if [ " $has_rc " = true ] ; then
kube::test::get_object_assert 'rc mock' " {{ ${ annotations_field } .annotated}} " 'true'
if [ " $two_rcs " = true ] ; then
kube::test::get_object_assert 'rc mock2' " {{ ${ annotations_field } .annotated}} " 'true'
fi
fi
# Cleanup resources created
kubectl delete -f " ${ file } " " ${ kube_flags [@] } "
2015-10-02 20:23:00 +00:00
done
2015-09-30 01:50:05 +00:00
2015-03-26 19:50:36 +00:00
######################
# Persistent Volumes #
######################
### Create and delete persistent volume examples
# Pre-condition: no persistent volumes currently exist
2015-08-22 06:34:17 +00:00
kube::test::get_object_assert pv " {{range.items}}{{ $id_field }}:{{end}} " ''
2015-03-26 19:50:36 +00:00
# Command
2015-07-15 00:59:59 +00:00
kubectl create -f docs/user-guide/persistent-volumes/volumes/local-01.yaml " ${ kube_flags [@] } "
2015-08-22 06:34:17 +00:00
kube::test::get_object_assert pv " {{range.items}}{{ $id_field }}:{{end}} " 'pv0001:'
2015-03-26 19:50:36 +00:00
kubectl delete pv pv0001 " ${ kube_flags [@] } "
2015-07-15 00:59:59 +00:00
kubectl create -f docs/user-guide/persistent-volumes/volumes/local-02.yaml " ${ kube_flags [@] } "
2015-08-22 06:34:17 +00:00
kube::test::get_object_assert pv " {{range.items}}{{ $id_field }}:{{end}} " 'pv0002:'
2015-03-26 19:50:36 +00:00
kubectl delete pv pv0002 " ${ kube_flags [@] } "
2015-07-15 00:59:59 +00:00
kubectl create -f docs/user-guide/persistent-volumes/volumes/gce.yaml " ${ kube_flags [@] } "
2015-08-22 06:34:17 +00:00
kube::test::get_object_assert pv " {{range.items}}{{ $id_field }}:{{end}} " 'pv0003:'
2015-03-26 19:50:36 +00:00
kubectl delete pv pv0003 " ${ kube_flags [@] } "
# Post-condition: no PVs
2015-08-22 06:34:17 +00:00
kube::test::get_object_assert pv " {{range.items}}{{ $id_field }}:{{end}} " ''
2015-03-26 19:50:36 +00:00
############################
# Persistent Volume Claims #
############################
### Create and delete persistent volume claim examples
# Pre-condition: no persistent volume claims currently exist
2015-08-22 06:34:17 +00:00
kube::test::get_object_assert pvc " {{range.items}}{{ $id_field }}:{{end}} " ''
2015-03-26 19:50:36 +00:00
# Command
2015-07-15 00:59:59 +00:00
kubectl create -f docs/user-guide/persistent-volumes/claims/claim-01.yaml " ${ kube_flags [@] } "
2015-08-22 06:34:17 +00:00
kube::test::get_object_assert pvc " {{range.items}}{{ $id_field }}:{{end}} " 'myclaim-1:'
2015-03-26 19:50:36 +00:00
kubectl delete pvc myclaim-1 " ${ kube_flags [@] } "
2015-07-15 00:59:59 +00:00
kubectl create -f docs/user-guide/persistent-volumes/claims/claim-02.yaml " ${ kube_flags [@] } "
2015-08-22 06:34:17 +00:00
kube::test::get_object_assert pvc " {{range.items}}{{ $id_field }}:{{end}} " 'myclaim-2:'
2015-03-26 19:50:36 +00:00
kubectl delete pvc myclaim-2 " ${ kube_flags [@] } "
2015-07-15 00:59:59 +00:00
kubectl create -f docs/user-guide/persistent-volumes/claims/claim-03.json " ${ kube_flags [@] } "
2015-08-22 06:34:17 +00:00
kube::test::get_object_assert pvc " {{range.items}}{{ $id_field }}:{{end}} " 'myclaim-3:'
2015-03-26 19:50:36 +00:00
kubectl delete pvc myclaim-3 " ${ kube_flags [@] } "
# Post-condition: no PVCs
2015-08-22 06:34:17 +00:00
kube::test::get_object_assert pvc " {{range.items}}{{ $id_field }}:{{end}} " ''
2015-03-26 19:50:36 +00:00
2015-02-23 15:20:55 +00:00
#########
# Nodes #
#########
2014-12-12 01:24:54 +00:00
2015-01-08 17:42:20 +00:00
kube::log::status " Testing kubectl( ${ version } :nodes) "
2015-02-23 15:20:55 +00:00
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert nodes " {{range.items}}{{ $id_field }}:{{end}} " '127.0.0.1:'
2015-02-23 15:20:55 +00:00
2015-03-23 16:14:18 +00:00
kube::test::describe_object_assert nodes "127.0.0.1" "Name:" "Labels:" "CreationTimestamp:" "Conditions:" "Addresses:" "Capacity:" "Pods:"
2015-08-04 07:12:29 +00:00
# Describe command (resource only) should print detailed information
kube::test::describe_resource_assert nodes "Name:" "Labels:" "CreationTimestamp:" "Conditions:" "Addresses:" "Capacity:" "Pods:"
2015-03-06 18:04:52 +00:00
2015-06-25 22:56:30 +00:00
### kubectl patch update can mark node unschedulable
# Pre-condition: node is schedulable
kube::test::get_object_assert "nodes 127.0.0.1" "{{.spec.unschedulable}}" '<no value>'
kubectl patch " ${ kube_flags [@] } " nodes "127.0.0.1" -p= '{"spec":{"unschedulable":true}}'
# Post-condition: node is unschedulable
kube::test::get_object_assert "nodes 127.0.0.1" "{{.spec.unschedulable}}" 'true'
kubectl patch " ${ kube_flags [@] } " nodes "127.0.0.1" -p= '{"spec":{"unschedulable":null}}'
# Post-condition: node is schedulable
kube::test::get_object_assert "nodes 127.0.0.1" "{{.spec.unschedulable}}" '<no value>'
2015-03-22 21:43:00 +00:00
2015-03-25 05:01:07 +00:00
#####################
# Retrieve multiple #
#####################
kube::log::status " Testing kubectl( ${ version } :multiget) "
2015-03-30 21:01:46 +00:00
kube::test::get_object_assert 'nodes/127.0.0.1 service/kubernetes' " {{range.items}}{{ $id_field }}:{{end}} " '127.0.0.1:kubernetes:'
2015-03-25 05:01:07 +00:00
2015-03-22 21:43:00 +00:00
2015-04-08 15:05:41 +00:00
#####################
# Resource aliasing #
2015-04-29 22:06:42 +00:00
#####################
2015-04-08 15:05:41 +00:00
kube::log::status "Testing resource aliasing"
2015-04-19 08:40:08 +00:00
kubectl create -f examples/cassandra/cassandra-controller.yaml " ${ kube_flags [@] } "
2015-07-24 18:15:38 +00:00
kubectl scale rc cassandra --replicas= 1 " ${ kube_flags [@] } "
2015-04-19 08:40:08 +00:00
kubectl create -f examples/cassandra/cassandra-service.yaml " ${ kube_flags [@] } "
2015-07-24 18:15:38 +00:00
kube::test::get_object_assert "all -l'name=cassandra'" "{{range.items}}{{range .metadata.labels}}{{.}}:{{end}}{{end}}" 'cassandra:cassandra:cassandra:'
2015-04-19 08:40:08 +00:00
kubectl delete all -l name = cassandra " ${ kube_flags [@] } "
2015-04-08 15:05:41 +00:00
2015-03-22 21:43:00 +00:00
###########
# Swagger #
###########
if [ [ -n " ${ version } " ] ] ; then
# Verify schema
file = " ${ KUBE_TEMP } /schema- ${ version } .json "
curl -s " http://127.0.0.1: ${ API_PORT } /swaggerapi/api/ ${ version } " > " ${ file } "
[ [ " $( grep "list of returned" " ${ file } " ) " ] ]
2015-07-10 18:19:53 +00:00
[ [ " $( grep "List of pods" " ${ file } " ) " ] ]
[ [ " $( grep "Watch for changes to the described resources" " ${ file } " ) " ] ]
2015-03-22 21:43:00 +00:00
fi
2015-02-23 15:20:55 +00:00
kube::test::clear_all
2015-06-30 02:30:14 +00:00
}
kube_api_versions = (
""
v1
)
for version in " ${ kube_api_versions [@] } " ; do
2015-10-09 22:19:13 +00:00
KUBE_API_VERSIONS = "v1,extensions/v1beta1" runTests " ${ version } "
2014-12-12 01:24:54 +00:00
done
2014-12-08 05:56:43 +00:00
2014-10-22 23:26:59 +00:00
kube::log::status "TEST PASSED"