2018-04-16 16:31:44 +00:00
#!/usr/bin/env bash
2016-12-11 16:45:45 +00:00
# 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.
# This contains util code for testing kubectl.
set -o errexit
set -o nounset
set -o pipefail
2017-05-26 05:18:35 +00:00
# Set locale to ensure english responses from kubectl commands
export LANG = C
2016-12-11 16:45:45 +00:00
KUBE_ROOT = $( dirname " ${ BASH_SOURCE } " ) /../..
2017-01-25 16:23:19 +00:00
# Expects the following has already been done by whatever sources this script
# source "${KUBE_ROOT}/hack/lib/init.sh"
# source "${KUBE_ROOT}/hack/lib/test.sh"
2018-07-05 13:47:07 +00:00
source " ${ KUBE_ROOT } /test/cmd/apply.sh "
source " ${ KUBE_ROOT } /test/cmd/apps.sh "
source " ${ KUBE_ROOT } /test/cmd/authorization.sh "
source " ${ KUBE_ROOT } /test/cmd/batch.sh "
source " ${ KUBE_ROOT } /test/cmd/certificate.sh "
source " ${ KUBE_ROOT } /test/cmd/core.sh "
source " ${ KUBE_ROOT } /test/cmd/crd.sh "
source " ${ KUBE_ROOT } /test/cmd/create.sh "
2019-02-04 20:25:16 +00:00
source " ${ KUBE_ROOT } /test/cmd/delete.sh "
2018-07-05 13:47:07 +00:00
source " ${ KUBE_ROOT } /test/cmd/diff.sh "
source " ${ KUBE_ROOT } /test/cmd/discovery.sh "
source " ${ KUBE_ROOT } /test/cmd/generic-resources.sh "
source " ${ KUBE_ROOT } /test/cmd/get.sh "
2019-01-15 21:16:26 +00:00
source " ${ KUBE_ROOT } /test/cmd/kubeadm.sh "
2018-07-05 13:47:07 +00:00
source " ${ KUBE_ROOT } /test/cmd/kubeconfig.sh "
source " ${ KUBE_ROOT } /test/cmd/node-management.sh "
source " ${ KUBE_ROOT } /test/cmd/old-print.sh "
source " ${ KUBE_ROOT } /test/cmd/plugins.sh "
source " ${ KUBE_ROOT } /test/cmd/proxy.sh "
source " ${ KUBE_ROOT } /test/cmd/rbac.sh "
source " ${ KUBE_ROOT } /test/cmd/request-timeout.sh "
source " ${ KUBE_ROOT } /test/cmd/run.sh "
source " ${ KUBE_ROOT } /test/cmd/save-config.sh "
source " ${ KUBE_ROOT } /test/cmd/storage.sh "
source " ${ KUBE_ROOT } /test/cmd/template-output.sh "
source " ${ KUBE_ROOT } /test/cmd/version.sh "
2018-12-05 11:24:50 +00:00
source " ${ KUBE_ROOT } /test/cmd/wait.sh "
2018-07-05 13:47:07 +00:00
2016-12-11 16:45:45 +00:00
ETCD_HOST = ${ ETCD_HOST :- 127 .0.0.1 }
ETCD_PORT = ${ ETCD_PORT :- 2379 }
API_PORT = ${ API_PORT :- 8080 }
2017-03-24 03:18:53 +00:00
SECURE_API_PORT = ${ SECURE_API_PORT :- 6443 }
2016-12-11 16:45:45 +00:00
API_HOST = ${ API_HOST :- 127 .0.0.1 }
KUBELET_HEALTHZ_PORT = ${ KUBELET_HEALTHZ_PORT :- 10248 }
CTLRMGR_PORT = ${ CTLRMGR_PORT :- 10252 }
PROXY_HOST = 127.0.0.1 # kubectl only serves on localhost.
Switch to k8s.gcr.io vanity domain
This is the 2nd attempt. The previous was reverted while we figured out
the regional mirrors (oops).
New plan: k8s.gcr.io is a read-only facade that auto-detects your source
region (us, eu, or asia for now) and pulls from the closest. To publish
an image, push k8s-staging.gcr.io and it will be synced to the regionals
automatically (similar to today). For now the staging is an alias to
gcr.io/google_containers (the legacy URL).
When we move off of google-owned projects (working on it), then we just
do a one-time sync, and change the google-internal config, and nobody
outside should notice.
We can, in parallel, change the auto-sync into a manual sync - send a PR
to "promote" something from staging, and a bot activates it. Nice and
visible, easy to keep track of.
2018-01-17 19:36:53 +00:00
IMAGE_NGINX = "k8s.gcr.io/nginx:1.7.9"
IMAGE_DEPLOYMENT_R1 = "k8s.gcr.io/nginx:test-cmd" # deployment-revision1.yaml
2016-12-11 16:45:45 +00:00
IMAGE_DEPLOYMENT_R2 = " $IMAGE_NGINX " # deployment-revision2.yaml
Switch to k8s.gcr.io vanity domain
This is the 2nd attempt. The previous was reverted while we figured out
the regional mirrors (oops).
New plan: k8s.gcr.io is a read-only facade that auto-detects your source
region (us, eu, or asia for now) and pulls from the closest. To publish
an image, push k8s-staging.gcr.io and it will be synced to the regionals
automatically (similar to today). For now the staging is an alias to
gcr.io/google_containers (the legacy URL).
When we move off of google-owned projects (working on it), then we just
do a one-time sync, and change the google-internal config, and nobody
outside should notice.
We can, in parallel, change the auto-sync into a manual sync - send a PR
to "promote" something from staging, and a bot activates it. Nice and
visible, easy to keep track of.
2018-01-17 19:36:53 +00:00
IMAGE_PERL = "k8s.gcr.io/perl"
IMAGE_PAUSE_V2 = "k8s.gcr.io/pause:2.0"
IMAGE_DAEMONSET_R2 = "k8s.gcr.io/pause:latest"
IMAGE_DAEMONSET_R2_2 = "k8s.gcr.io/nginx:test-cmd" # rollingupdate-daemonset-rv2.yaml
IMAGE_STATEFULSET_R1 = "k8s.gcr.io/nginx-slim:0.7"
IMAGE_STATEFULSET_R2 = "k8s.gcr.io/nginx-slim:0.8"
2016-12-11 16:45:45 +00:00
# Expose kubectl directly for readability
PATH = " ${ KUBE_OUTPUT_HOSTBIN } " :$PATH
# Define variables for resource types to prevent typos.
clusterroles = "clusterroles"
configmaps = "configmaps"
csr = "csr"
deployments = "deployments"
horizontalpodautoscalers = "horizontalpodautoscalers"
metrics = "metrics"
namespaces = "namespaces"
nodes = "nodes"
persistentvolumeclaims = "persistentvolumeclaims"
persistentvolumes = "persistentvolumes"
pods = "pods"
podtemplates = "podtemplates"
replicasets = "replicasets"
replicationcontrollers = "replicationcontrollers"
2017-01-13 02:15:50 +00:00
roles = "roles"
2016-12-11 16:45:45 +00:00
secrets = "secrets"
serviceaccounts = "serviceaccounts"
services = "services"
statefulsets = "statefulsets"
static = "static"
storageclass = "storageclass"
subjectaccessreviews = "subjectaccessreviews"
2017-06-01 05:56:49 +00:00
selfsubjectaccessreviews = "selfsubjectaccessreviews"
2017-05-18 20:55:35 +00:00
customresourcedefinitions = "customresourcedefinitions"
2017-03-20 19:07:17 +00:00
daemonsets = "daemonsets"
2017-05-18 22:46:20 +00:00
controllerrevisions = "controllerrevisions"
2018-03-06 05:50:17 +00:00
job = "jobs"
2016-12-11 16:45:45 +00:00
2017-06-12 21:08:52 +00:00
# include shell2junit library
sh2ju = " ${ KUBE_ROOT } /third_party/forked/shell2junit/sh2ju.sh "
if [ [ -f " ${ sh2ju } " ] ] ; then
source " ${ sh2ju } "
else
echo "failed to find third_party/forked/shell2junit/sh2ju.sh"
exit 1
fi
# record_command runs the command and records its output/error messages in junit format
# it expects the first to be the name of the command
# Example:
# record_command run_kubectl_tests
#
# WARNING: Variable changes in the command will NOT be effective after record_command returns.
# This is because the command runs in subshell.
function record_command( ) {
set +o nounset
set +o errexit
local name = " $1 "
local output = " ${ KUBE_JUNIT_REPORT_DIR :- /tmp/junit-results } "
echo " Recording: ${ name } "
echo " Running command: $@ "
juLog -output= " ${ output } " -class= "test-cmd" -name= " ${ name } " " $@ "
if [ [ $? -ne 0 ] ] ; then
echo " Error when running ${ name } "
2018-02-07 14:21:46 +00:00
foundError = " ${ foundError } " " ${ name } " ", "
2017-06-12 21:08:52 +00:00
fi
set -o nounset
set -o errexit
}
2016-12-11 16:45:45 +00:00
# Stops the running kubectl proxy, if there is one.
function stop-proxy( )
{
[ [ -n " ${ PROXY_PORT - } " ] ] && kube::log::status " Stopping proxy on port ${ PROXY_PORT } "
[ [ -n " ${ PROXY_PID - } " ] ] && kill " ${ PROXY_PID } " 1>& 2 2>/dev/null
[ [ -n " ${ PROXY_PORT_FILE - } " ] ] && rm -f ${ PROXY_PORT_FILE }
PROXY_PID =
PROXY_PORT =
PROXY_PORT_FILE =
}
# Starts "kubect proxy" to test the client proxy. $1: api_prefix
function start-proxy( )
{
stop-proxy
PROXY_PORT_FILE = $( mktemp proxy-port.out.XXXXX)
kube::log::status " Starting kubectl proxy on random port; output file in ${ PROXY_PORT_FILE } ; args: ${ 1 - } "
if [ $# -eq 0 ] ; then
kubectl proxy --port= 0 --www= . 1>${ PROXY_PORT_FILE } 2>& 1 &
else
kubectl proxy --port= 0 --www= . --api-prefix= " $1 " 1>${ PROXY_PORT_FILE } 2>& 1 &
fi
PROXY_PID = $!
PROXY_PORT =
local attempts = 0
while [ [ -z ${ PROXY_PORT } ] ] ; do
if ( ( ${ attempts } > 9 ) ) ; then
kill " ${ PROXY_PID } "
kube::log::error_exit " Couldn't start proxy. Failed to read port after ${ attempts } tries. Got: $( cat ${ PROXY_PORT_FILE } ) "
fi
sleep .5
kube::log::status " Attempt ${ attempts } to read ${ PROXY_PORT_FILE } ... "
PROXY_PORT = $( sed 's/.*Starting to serve on 127.0.0.1:\([0-9]*\)$/\1/' < ${ PROXY_PORT_FILE } )
attempts = $(( attempts+1))
done
kube::log::status " kubectl proxy running on port ${ PROXY_PORT } "
# We try checking kubectl proxy 30 times with 1s delays to avoid occasional
# failures.
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
}
function cleanup( )
{
[ [ -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
kube::etcd::cleanup
rm -rf " ${ KUBE_TEMP } "
2017-08-19 01:33:32 +00:00
local junit_dir = " ${ KUBE_JUNIT_REPORT_DIR :- /tmp/junit-results } "
echo "junit report dir:" ${ junit_dir }
2016-12-11 16:45:45 +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
}
# 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 "
preserve_err_file = ${ PRESERVE_ERR_FILE -false }
for count in { 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
if [ " $preserve_err_file " != true ] ; then
rm " ${ ERROR_FILE } "
fi
break
fi
done
}
# Waits for the pods with the given label to match the list of names. Don't call
# this function unless you know the exact pod names, or expect no pods.
# $1: label to match
# $2: list of pod names sorted by name
# Example invocation:
# wait-for-pods-with-label "app=foo" "nginx-0nginx-1"
function wait-for-pods-with-label( )
{
2017-05-31 03:24:12 +00:00
local i
2016-12-11 16:45:45 +00:00
for i in $( seq 1 10) ; do
2018-04-19 21:57:09 +00:00
kubeout = ` kubectl get po -l $1 --output= go-template --template= '{{range.items}}{{.metadata.name}}{{end}}' --sort-by metadata.name " ${ kube_flags [@] } " `
2016-12-11 16:45:45 +00:00
if [ [ $kubeout = $2 ] ] ; then
return
fi
echo Waiting for pods: $2 , found $kubeout
sleep $i
done
kube::log::error_exit " Timeout waiting for pods with label $1 "
}
# Code to be run before running the tests.
setup( ) {
kube::util::trap_add cleanup EXIT SIGINT
kube::util::ensure-temp-dir
# ensure ~/.kube/config isn't loaded by tests
HOME = " ${ KUBE_TEMP } "
kube::etcd::start
# Find a standard sed instance for use with edit scripts
2017-10-16 20:21:09 +00:00
kube::util::ensure-gnu-sed
2016-12-11 16:45:45 +00:00
kube::log::status "Building kubectl"
make -C " ${ KUBE_ROOT } " WHAT = "cmd/kubectl"
# Check kubectl
kube::log::status "Running kubectl with no options"
" ${ KUBE_OUTPUT_HOSTBIN } /kubectl "
# TODO: we need to note down the current default namespace and set back to this
# namespace after the tests are done.
kubectl config view
CONTEXT = "test"
kubectl config set-context " ${ CONTEXT } "
kubectl config use-context " ${ CONTEXT } "
kube::log::status "Setup complete"
}
2017-06-13 06:13:39 +00:00
# Runs all kubectl tests.
# Requires an env var SUPPORTED_RESOURCES which is a comma separated list of
# resources for which tests should be run.
runTests( ) {
2018-02-07 14:21:46 +00:00
foundError = ""
2017-06-13 06:13:39 +00:00
if [ -z " ${ SUPPORTED_RESOURCES :- } " ] ; then
echo "Need to set SUPPORTED_RESOURCES env var. It is a list of resources that are supported and hence should be tested. Set it to (*) to test all resources"
exit 1
fi
kube::log::status "Checking kubectl version"
kubectl version
2018-03-19 18:52:27 +00:00
# Generate a random namespace name, based on the current time (to make
# debugging slightly easier) and a random number. Don't use `date +%N`
# because that doesn't work on OSX.
2017-06-13 06:13:39 +00:00
create_and_use_new_namespace( ) {
2018-03-19 18:52:27 +00:00
local ns_name
ns_name = " namespace- $( date +%s) - ${ RANDOM } "
kube::log::status " Creating namespace ${ ns_name } "
2018-03-21 09:30:57 +00:00
kubectl create namespace " ${ ns_name } "
kubectl config set-context " ${ CONTEXT } " --namespace= " ${ ns_name } "
2017-06-13 06:13:39 +00:00
}
kube_flags = (
-s " http://127.0.0.1: ${ API_PORT } "
)
2017-07-17 22:59:15 +00:00
# token defined in hack/testdata/auth-tokens.csv
2017-06-13 06:13:39 +00:00
kube_flags_with_token = (
2017-07-17 22:59:15 +00:00
-s " https://127.0.0.1: ${ SECURE_API_PORT } " --token= admin-token --insecure-skip-tls-verify= true
2017-06-13 06:13:39 +00:00
)
if [ [ -z " ${ ALLOW_SKEW :- } " ] ] ; then
kube_flags += ( "--match-server-version" )
kube_flags_with_token += ( "--match-server-version" )
fi
if kube::test::if_supports_resource " ${ nodes } " ; then
[ " $( kubectl get nodes -o go-template= '{{ .apiVersion }}' " ${ kube_flags [@] } " ) " = = "v1" ]
fi
id_field = ".metadata.name"
labels_field = ".metadata.labels"
annotations_field = ".metadata.annotations"
service_selector_field = ".spec.selector"
rc_replicas_field = ".spec.replicas"
rc_status_replicas_field = ".status.replicas"
rc_container_image_field = ".spec.template.spec.containers"
rs_replicas_field = ".spec.replicas"
port_field = "(index .spec.ports 0).port"
port_name = "(index .spec.ports 0).name"
second_port_field = "(index .spec.ports 1).port"
second_port_name = "(index .spec.ports 1).name"
image_field = "(index .spec.containers 0).image"
pod_container_name_field = "(index .spec.containers 0).name"
container_name_field = "(index .spec.template.spec.containers 0).name"
hpa_min_field = ".spec.minReplicas"
hpa_max_field = ".spec.maxReplicas"
hpa_cpu_field = ".spec.targetCPUUtilizationPercentage"
2018-01-29 22:28:15 +00:00
template_labels = ".spec.template.metadata.labels.name"
2017-06-13 06:13:39 +00:00
statefulset_replicas_field = ".spec.replicas"
statefulset_observed_generation = ".status.observedGeneration"
job_parallelism_field = ".spec.parallelism"
deployment_replicas = ".spec.replicas"
secret_data = ".data"
secret_type = ".type"
change_cause_annotation = '.*kubernetes.io/change-cause.*'
pdb_min_available = ".spec.minAvailable"
pdb_max_unavailable = ".spec.maxUnavailable"
2017-09-27 20:49:49 +00:00
generation_field = ".metadata.generation"
2017-06-13 06:13:39 +00:00
template_generation_field = ".spec.templateGeneration"
container_len = "(len .spec.template.spec.containers)"
2017-08-07 21:49:46 +00:00
image_field0 = "(index .spec.template.spec.containers 0).image"
image_field1 = "(index .spec.template.spec.containers 1).image"
2017-06-13 06:13:39 +00:00
# Make sure "default" namespace exists.
if kube::test::if_supports_resource " ${ namespaces } " ; then
output_message = $( kubectl get " ${ kube_flags [@] } " namespaces)
if [ [ ! $( echo " ${ output_message } " | grep "default" ) ] ] ; then
# Create default namespace
kubectl create " ${ kube_flags [@] } " ns default
fi
fi
# Make sure "kubernetes" service exists.
if kube::test::if_supports_resource " ${ services } " ; then
# Attempt to create the kubernetes service, tolerating failure (since it might already exist)
kubectl create " ${ kube_flags [@] } " -f hack/testdata/kubernetes-service.yaml || true
# Require the service to exist (either we created it or the API server did)
kubectl get " ${ kube_flags [@] } " -f hack/testdata/kubernetes-service.yaml
fi
2019-02-23 02:23:53 +00:00
cleanup_tests( ) {
kube::test::clear_all
2019-02-21 11:15:13 +00:00
if [ [ -n " ${ foundError } " ] ] ; then
echo "FAILED TESTS: " " ${ foundError } "
exit 1
fi
}
2019-02-01 18:53:23 +00:00
if [ [ -n " ${ WHAT - } " ] ] ; then
2019-01-15 21:16:26 +00:00
for pkg in ${ WHAT }
do
2019-03-01 11:46:41 +00:00
# running of kubeadm is captured in hack/make-targets/test-cmd.sh
2019-03-03 01:41:42 +00:00
if [ [ " ${ pkg } " != "kubeadm" ] ] ; then
2019-03-01 11:46:41 +00:00
record_command run_${ pkg } _tests
fi
2019-01-15 21:16:26 +00:00
done
2019-02-23 02:23:53 +00:00
cleanup_tests
2019-02-21 11:15:13 +00:00
return
fi
2017-06-13 06:13:39 +00:00
2019-02-21 11:15:13 +00:00
#########################
# Kubectl version #
#########################
2017-06-13 06:13:39 +00:00
2019-02-21 11:15:13 +00:00
record_command run_kubectl_version_tests
2017-06-13 06:13:39 +00:00
2019-02-21 11:15:13 +00:00
#######################
# kubectl config set #
#######################
2017-06-13 06:13:39 +00:00
2019-02-21 11:15:13 +00:00
record_command run_kubectl_config_set_tests
2017-06-13 06:13:39 +00:00
2019-02-21 11:15:13 +00:00
#######################
# kubectl local proxy #
#######################
2017-06-13 06:13:39 +00:00
2019-02-21 11:15:13 +00:00
record_command run_kubectl_local_proxy_tests
2017-06-13 06:13:39 +00:00
2019-02-21 11:15:13 +00:00
#########################
# RESTMapper evaluation #
#########################
2018-04-27 16:36:28 +00:00
2019-02-21 11:15:13 +00:00
record_command run_RESTMapper_evaluation_tests
2017-06-13 06:13:39 +00:00
2019-02-21 11:15:13 +00:00
# find all resources
kubectl " ${ kube_flags [@] } " api-resources
# find all namespaced resources that support list by name and get them
kubectl " ${ kube_flags [@] } " api-resources --verbs= list --namespaced -o name | xargs -n 1 kubectl " ${ kube_flags [@] } " get -o name
2017-06-13 06:13:39 +00:00
2019-02-21 11:15:13 +00:00
################
# Cluster Role #
################
2017-06-13 06:13:39 +00:00
2019-02-21 11:15:13 +00:00
if kube::test::if_supports_resource " ${ clusterroles } " ; then
record_command run_clusterroles_tests
fi
2017-06-13 06:13:39 +00:00
2019-02-21 11:15:13 +00:00
########
# Role #
########
if kube::test::if_supports_resource " ${ roles } " ; then
record_command run_role_tests
fi
2017-06-13 06:13:39 +00:00
2019-02-21 11:15:13 +00:00
#########################
# Assert short name #
#########################
2017-06-13 06:13:39 +00:00
2019-02-21 11:15:13 +00:00
record_command run_assert_short_name_tests
2017-06-13 06:13:39 +00:00
2019-02-21 11:15:13 +00:00
#########################
# Assert categories #
#########################
2017-06-13 06:13:39 +00:00
2019-02-21 11:15:13 +00:00
## test if a category is exported during discovery
if kube::test::if_supports_resource " ${ pods } " ; then
record_command run_assert_categories_tests
fi
2017-06-13 06:13:39 +00:00
2019-02-21 11:15:13 +00:00
###########################
# POD creation / deletion #
###########################
2017-06-13 06:13:39 +00:00
2019-02-21 11:15:13 +00:00
if kube::test::if_supports_resource " ${ pods } " ; then
record_command run_pod_tests
fi
2017-06-13 06:13:39 +00:00
2019-02-21 11:15:13 +00:00
if kube::test::if_supports_resource " ${ pods } " ; then
record_command run_save_config_tests
fi
2017-06-13 06:13:39 +00:00
2019-02-21 11:15:13 +00:00
if kube::test::if_supports_resource " ${ pods } " ; then
record_command run_kubectl_create_error_tests
fi
2017-06-13 06:13:39 +00:00
2019-02-21 11:15:13 +00:00
if kube::test::if_supports_resource " ${ pods } " ; then
record_command run_kubectl_apply_tests
record_command run_kubectl_run_tests
record_command run_kubectl_create_filter_tests
fi
2018-03-15 17:06:51 +00:00
2019-02-21 11:15:13 +00:00
if kube::test::if_supports_resource " ${ deployments } " ; then
record_command run_kubectl_apply_deployments_tests
fi
2017-06-13 06:13:39 +00:00
2019-02-21 11:15:13 +00:00
################
# Kubectl diff #
################
record_command run_kubectl_diff_tests
record_command run_kubectl_diff_same_names
2017-06-13 06:13:39 +00:00
2019-02-21 11:15:13 +00:00
###############
# Kubectl get #
###############
2017-10-10 18:01:44 +00:00
2019-02-21 11:15:13 +00:00
if kube::test::if_supports_resource " ${ pods } " ; then
record_command run_kubectl_get_tests
record_command run_kubectl_old_print_tests
fi
2017-10-10 18:01:44 +00:00
2017-06-13 06:13:39 +00:00
2019-02-21 11:15:13 +00:00
######################
# Create #
######################
if kube::test::if_supports_resource " ${ secrets } " ; then
record_command run_create_secret_tests
fi
2019-02-26 00:31:03 +00:00
if kube::test::if_supports_resource " ${ deployments } " ; then
record_command run_kubectl_create_kustomization_directory_tests
fi
2019-02-04 20:25:16 +00:00
2019-02-21 11:15:13 +00:00
######################
# Delete #
######################
if kube::test::if_supports_resource " ${ configmaps } " ; then
record_command run_kubectl_delete_allnamespaces_tests
fi
2017-06-13 06:13:39 +00:00
2019-02-21 11:15:13 +00:00
##################
# Global timeout #
##################
2017-06-13 06:13:39 +00:00
2019-02-21 11:15:13 +00:00
if kube::test::if_supports_resource " ${ pods } " ; then
record_command run_kubectl_request_timeout_tests
fi
2017-06-13 06:13:39 +00:00
2019-02-21 11:15:13 +00:00
#####################################
# CustomResourceDefinitions #
#####################################
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
# customresourcedefinitions cleanup after themselves.
if kube::test::if_supports_resource " ${ customresourcedefinitions } " ; then
record_command run_crd_tests
fi
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
#################
# Run cmd w img #
#################
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
if kube::test::if_supports_resource " ${ deployments } " ; then
record_command run_cmd_with_img_tests
fi
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
#####################################
# Recursive Resources via directory #
#####################################
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
if kube::test::if_supports_resource " ${ pods } " ; then
run_recursive_resources_tests
fi
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
##############
# Namespaces #
##############
if kube::test::if_supports_resource " ${ namespaces } " ; then
record_command run_namespace_tests
fi
2019-01-15 21:16:26 +00:00
2019-02-21 11:15:13 +00:00
###########
# Secrets #
###########
if kube::test::if_supports_resource " ${ namespaces } " ; then
if kube::test::if_supports_resource " ${ secrets } " ; then
record_command run_secrets_test
2016-12-11 16:45:45 +00:00
fi
2019-02-21 11:15:13 +00:00
fi
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
######################
# ConfigMap #
######################
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
if kube::test::if_supports_resource " ${ namespaces } " ; then
if kube::test::if_supports_resource " ${ configmaps } " ; then
record_command run_configmap_tests
2016-12-11 16:45:45 +00:00
fi
2019-02-21 11:15:13 +00:00
fi
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
####################
# Client Config #
####################
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
record_command run_client_config_tests
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
####################
# Service Accounts #
####################
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
if kube::test::if_supports_resource " ${ namespaces } " && kube::test::if_supports_resource " ${ serviceaccounts } " ; then
record_command run_service_accounts_tests
fi
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
####################
# Job #
####################
2018-03-06 05:50:17 +00:00
2019-02-21 11:15:13 +00:00
if kube::test::if_supports_resource " ${ job } " ; then
record_command run_job_tests
record_command run_create_job_tests
fi
2018-03-06 05:50:17 +00:00
2019-02-21 11:15:13 +00:00
#################
# Pod templates #
#################
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
if kube::test::if_supports_resource " ${ podtemplates } " ; then
record_command run_pod_templates_tests
fi
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
############
# Services #
############
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
if kube::test::if_supports_resource " ${ services } " ; then
record_command run_service_tests
fi
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
##################
# DaemonSets #
##################
2017-03-20 19:07:17 +00:00
2019-02-21 11:15:13 +00:00
if kube::test::if_supports_resource " ${ daemonsets } " ; then
record_command run_daemonset_tests
if kube::test::if_supports_resource " ${ controllerrevisions } " ; then
record_command run_daemonset_history_tests
2017-05-18 22:46:20 +00:00
fi
2019-02-21 11:15:13 +00:00
fi
2017-03-20 19:07:17 +00:00
2019-02-21 11:15:13 +00:00
###########################
# Replication controllers #
###########################
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
if kube::test::if_supports_resource " ${ namespaces } " ; then
if kube::test::if_supports_resource " ${ replicationcontrollers } " ; then
record_command run_rc_tests
2016-12-11 16:45:45 +00:00
fi
2019-02-21 11:15:13 +00:00
fi
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
######################
# Deployments #
######################
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
if kube::test::if_supports_resource " ${ deployments } " ; then
record_command run_deployment_tests
fi
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
######################
# Replica Sets #
######################
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
if kube::test::if_supports_resource " ${ replicasets } " ; then
record_command run_rs_tests
fi
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
#################
# Stateful Sets #
#################
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
if kube::test::if_supports_resource " ${ statefulsets } " ; then
record_command run_stateful_set_tests
if kube::test::if_supports_resource " ${ controllerrevisions } " ; then
record_command run_statefulset_history_tests
2017-08-07 21:49:46 +00:00
fi
2019-02-21 11:15:13 +00:00
fi
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
######################
# Lists #
######################
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
if kube::test::if_supports_resource " ${ services } " ; then
if kube::test::if_supports_resource " ${ deployments } " ; then
record_command run_lists_tests
2016-12-11 16:45:45 +00:00
fi
2019-02-21 11:15:13 +00:00
fi
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
######################
# Multiple Resources #
######################
if kube::test::if_supports_resource " ${ services } " ; then
if kube::test::if_supports_resource " ${ replicationcontrollers } " ; then
record_command run_multi_resources_tests
2016-12-11 16:45:45 +00:00
fi
2019-02-21 11:15:13 +00:00
fi
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
######################
# Persistent Volumes #
######################
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
if kube::test::if_supports_resource " ${ persistentvolumes } " ; then
record_command run_persistent_volumes_tests
fi
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
############################
# Persistent Volume Claims #
############################
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
if kube::test::if_supports_resource " ${ persistentvolumeclaims } " ; then
record_command run_persistent_volume_claims_tests
fi
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
############################
# Storage Classes #
############################
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
if kube::test::if_supports_resource " ${ storageclass } " ; then
record_command run_storage_class_tests
fi
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
#########
# Nodes #
#########
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
if kube::test::if_supports_resource " ${ nodes } " ; then
record_command run_nodes_tests
fi
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
########################
# authorization.k8s.io #
########################
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
if kube::test::if_supports_resource " ${ subjectaccessreviews } " ; then
record_command run_authorization_tests
fi
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
# kubectl auth can-i
# kube-apiserver is started with authorization mode AlwaysAllow, so kubectl can-i always returns yes
if kube::test::if_supports_resource " ${ subjectaccessreviews } " ; then
output_message = $( kubectl auth can-i '*' '*' 2>& 1 " ${ kube_flags [@] } " )
kube::test::if_has_string " ${ output_message } " "yes"
2017-06-01 05:56:49 +00:00
2019-02-21 11:15:13 +00:00
output_message = $( kubectl auth can-i get pods --subresource= log 2>& 1 " ${ kube_flags [@] } " )
kube::test::if_has_string " ${ output_message } " "yes"
2017-06-01 05:56:49 +00:00
2019-02-21 11:15:13 +00:00
output_message = $( kubectl auth can-i get invalid_resource 2>& 1 " ${ kube_flags [@] } " )
kube::test::if_has_string " ${ output_message } " "the server doesn't have a resource type"
2017-06-01 05:56:49 +00:00
2019-02-21 11:15:13 +00:00
output_message = $( kubectl auth can-i get /logs/ 2>& 1 " ${ kube_flags [@] } " )
kube::test::if_has_string " ${ output_message } " "yes"
2017-06-01 05:56:49 +00:00
2019-02-21 11:15:13 +00:00
output_message = $( ! kubectl auth can-i get /logs/ --subresource= log 2>& 1 " ${ kube_flags [@] } " )
kube::test::if_has_string " ${ output_message } " "subresource can not be used with NonResourceURL"
2017-06-01 05:56:49 +00:00
2019-02-21 11:15:13 +00:00
output_message = $( kubectl auth can-i list jobs.batch/bar -n foo --quiet 2>& 1 " ${ kube_flags [@] } " )
kube::test::if_empty_string " ${ output_message } "
2018-08-01 13:03:46 +00:00
2019-02-21 11:15:13 +00:00
output_message = $( kubectl auth can-i get pods --subresource= log 2>& 1 " ${ kube_flags [@] } " ; echo $? )
kube::test::if_has_string " ${ output_message } " '0'
2018-02-08 15:46:11 +00:00
2019-02-21 11:15:13 +00:00
output_message = $( kubectl auth can-i get pods --subresource= log --quiet 2>& 1 " ${ kube_flags [@] } " ; echo $? )
kube::test::if_has_string " ${ output_message } " '0'
fi
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
# kubectl auth reconcile
if kube::test::if_supports_resource " ${ clusterroles } " ; then
kubectl auth reconcile " ${ kube_flags [@] } " -f test/fixtures/pkg/kubectl/cmd/auth/rbac-resource-plus.yaml
kube::test::get_object_assert 'rolebindings -n some-other-random -l test-cmd=auth' " {{range.items}}{{ $id_field }}:{{end}} " 'testing-RB:'
kube::test::get_object_assert 'roles -n some-other-random -l test-cmd=auth' " {{range.items}}{{ $id_field }}:{{end}} " 'testing-R:'
kube::test::get_object_assert 'clusterrolebindings -l test-cmd=auth' " {{range.items}}{{ $id_field }}:{{end}} " 'testing-CRB:'
kube::test::get_object_assert 'clusterroles -l test-cmd=auth' " {{range.items}}{{ $id_field }}:{{end}} " 'testing-CR:'
2017-08-30 14:32:41 +00:00
2019-02-21 11:15:13 +00:00
failure_message = $( ! kubectl auth reconcile " ${ kube_flags [@] } " -f test/fixtures/pkg/kubectl/cmd/auth/rbac-v1beta1.yaml 2>& 1 )
kube::test::if_has_string " ${ failure_message } " 'only rbac.authorization.k8s.io/v1 is supported'
2018-07-02 15:33:39 +00:00
2019-02-21 11:15:13 +00:00
kubectl delete " ${ kube_flags [@] } " rolebindings,role,clusterroles,clusterrolebindings -n some-other-random -l test-cmd= auth
fi
2017-08-30 14:32:41 +00:00
2019-02-21 11:15:13 +00:00
#####################
# Retrieve multiple #
#####################
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
if kube::test::if_supports_resource " ${ nodes } " ; then
if kube::test::if_supports_resource " ${ services } " ; then
record_command run_retrieve_multiple_tests
2016-12-11 16:45:45 +00:00
fi
2019-02-21 11:15:13 +00:00
fi
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
#####################
# Resource aliasing #
#####################
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
if kube::test::if_supports_resource " ${ services } " ; then
if kube::test::if_supports_resource " ${ replicationcontrollers } " ; then
record_command run_resource_aliasing_tests
2016-12-11 16:45:45 +00:00
fi
2019-02-21 11:15:13 +00:00
fi
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
###########
# Explain #
###########
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
if kube::test::if_supports_resource " ${ pods } " ; then
record_command run_kubectl_explain_tests
fi
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
###########
# Swagger #
###########
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
record_command run_swagger_tests
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
#####################
# Kubectl --sort-by #
#####################
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
if kube::test::if_supports_resource " ${ pods } " ; then
record_command run_kubectl_sort_by_tests
fi
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
############################
# Kubectl --all-namespaces #
############################
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
if kube::test::if_supports_resource " ${ pods } " ; then
if kube::test::if_supports_resource " ${ nodes } " ; then
record_command run_kubectl_all_namespace_tests
2017-10-13 06:24:02 +00:00
fi
2019-02-21 11:15:13 +00:00
fi
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
######################
# kubectl --template #
######################
2018-07-02 18:16:20 +00:00
2019-02-21 11:15:13 +00:00
if kube::test::if_supports_resource " ${ pods } " ; then
record_command run_template_output_tests
fi
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
################
# Certificates #
################
2016-12-11 16:45:45 +00:00
2019-02-21 11:15:13 +00:00
if kube::test::if_supports_resource " ${ csr } " ; then
record_command run_certificates_tests
fi
2017-09-22 17:55:54 +00:00
2019-02-21 11:15:13 +00:00
######################
# Cluster Management #
######################
if kube::test::if_supports_resource " ${ nodes } " ; then
record_command run_cluster_management_tests
fi
2017-05-05 22:22:24 +00:00
2019-02-21 11:15:13 +00:00
###########
# Plugins #
###########
2017-05-05 22:22:10 +00:00
2019-02-21 11:15:13 +00:00
record_command run_plugins_tests
2017-03-24 03:18:53 +00:00
2018-12-05 11:24:50 +00:00
2019-02-21 11:15:13 +00:00
#################
# Impersonation #
#################
record_command run_impersonation_tests
2018-12-05 11:24:50 +00:00
2019-02-21 11:15:13 +00:00
####################
# kubectl wait #
####################
2017-03-24 03:18:53 +00:00
2019-02-21 11:15:13 +00:00
record_command run_wait_tests
2019-02-23 02:23:53 +00:00
cleanup_tests
2016-12-11 16:45:45 +00:00
}