|
|
|
@@ -246,14 +246,7 @@ setup() {
|
|
|
|
|
kube::etcd::start
|
|
|
|
|
|
|
|
|
|
# Find a standard sed instance for use with edit scripts
|
|
|
|
|
SED=sed
|
|
|
|
|
if which gsed &>/dev/null; then
|
|
|
|
|
SED=gsed
|
|
|
|
|
fi
|
|
|
|
|
if ! ($SED --version 2>&1 | grep -q GNU); then
|
|
|
|
|
echo "!!! GNU sed is required. If on OS X, use 'brew install gnu-sed'."
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
kube::util::ensure-gnu-sed
|
|
|
|
|
|
|
|
|
|
kube::log::status "Building kubectl"
|
|
|
|
|
make -C "${KUBE_ROOT}" WHAT="cmd/kubectl"
|
|
|
|
@@ -400,7 +393,7 @@ run_pod_tests() {
|
|
|
|
|
create_and_use_new_namespace
|
|
|
|
|
kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" ''
|
|
|
|
|
# Command
|
|
|
|
|
echo "${output_pod}" | $SED '/namespace:/d' | kubectl create -f - "${kube_flags[@]}"
|
|
|
|
|
echo "${output_pod}" | ${SED} '/namespace:/d' | kubectl create -f - "${kube_flags[@]}"
|
|
|
|
|
# Post-condition: valid-pod POD is created
|
|
|
|
|
kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" 'valid-pod:'
|
|
|
|
|
|
|
|
|
@@ -655,7 +648,7 @@ run_pod_tests() {
|
|
|
|
|
kube::test::get_object_assert rc "{{range.items}}{{$id_field}}:{{end}}" ''
|
|
|
|
|
## kubectl create --edit can update the label filed of multiple resources. tmp-editor.sh is a fake editor
|
|
|
|
|
TEMP=$(mktemp /tmp/tmp-editor-XXXXXXXX.sh)
|
|
|
|
|
echo -e "#!/bin/bash\n$SED -i \"s/mock/modified/g\" \$1" > ${TEMP}
|
|
|
|
|
echo -e "#!/bin/bash\n${SED} -i \"s/mock/modified/g\" \$1" > ${TEMP}
|
|
|
|
|
chmod +x ${TEMP}
|
|
|
|
|
# Command
|
|
|
|
|
EDITOR=${TEMP} kubectl create --edit -f hack/testdata/multi-resource-json.json "${kube_flags[@]}"
|
|
|
|
@@ -758,7 +751,7 @@ run_pod_tests() {
|
|
|
|
|
|
|
|
|
|
## --force replace pod can change other field, e.g., spec.container.name
|
|
|
|
|
# Command
|
|
|
|
|
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 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
|
|
|
|
|
# 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'
|
|
|
|
@@ -802,7 +795,7 @@ __EOF__
|
|
|
|
|
kubectl delete node node-v1-test "${kube_flags[@]}"
|
|
|
|
|
|
|
|
|
|
## kubectl edit can update the image field of a POD. tmp-editor.sh is a fake editor
|
|
|
|
|
echo -e "#!/bin/bash\n$SED -i \"s/nginx/gcr.io\/google_containers\/serve_hostname/g\" \$1" > /tmp/tmp-editor.sh
|
|
|
|
|
echo -e "#!/bin/bash\n${SED} -i \"s/nginx/gcr.io\/google_containers\/serve_hostname/g\" \$1" > /tmp/tmp-editor.sh
|
|
|
|
|
chmod +x /tmp/tmp-editor.sh
|
|
|
|
|
# Pre-condition: valid-pod POD has image nginx
|
|
|
|
|
kube::test::get_object_assert pods "{{range.items}}{{$image_field}}:{{end}}" 'nginx:'
|
|
|
|
@@ -882,7 +875,7 @@ __EOF__
|
|
|
|
|
# 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
|
|
|
|
|
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
|
|
|
|
@@ -898,7 +891,7 @@ __EOF__
|
|
|
|
|
[[ "$(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
|
|
|
|
|
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
|
|
|
|
@@ -1178,7 +1171,7 @@ run_save_config_tests() {
|
|
|
|
|
! [[ "$(kubectl get pods test-pod -o yaml "${kube_flags[@]}" | grep kubectl.kubernetes.io/last-applied-configuration)" ]]
|
|
|
|
|
# Command: edit the pod "test-pod"
|
|
|
|
|
temp_editor="${KUBE_TEMP}/tmp-editor.sh"
|
|
|
|
|
echo -e "#!/bin/bash\n$SED -i \"s/test-pod-label/test-pod-label-edited/g\" \$@" > "${temp_editor}"
|
|
|
|
|
echo -e "#!/bin/bash\n${SED} -i \"s/test-pod-label/test-pod-label-edited/g\" \$@" > "${temp_editor}"
|
|
|
|
|
chmod +x "${temp_editor}"
|
|
|
|
|
EDITOR=${temp_editor} kubectl edit pod test-pod --save-config "${kube_flags[@]}"
|
|
|
|
|
# Post-Condition: pod "test-pod" has configuration annotation
|
|
|
|
@@ -2857,7 +2850,7 @@ run_deployment_tests() {
|
|
|
|
|
kubectl get rs "${newrs}" -o yaml | grep "deployment.kubernetes.io/revision-history: 1,3"
|
|
|
|
|
# Check that trying to watch the status of a superseded revision returns an error
|
|
|
|
|
! kubectl rollout status deployment/nginx --revision=3
|
|
|
|
|
cat hack/testdata/deployment-revision1.yaml | $SED "s/name: nginx$/name: nginx2/" | kubectl create -f - "${kube_flags[@]}"
|
|
|
|
|
cat hack/testdata/deployment-revision1.yaml | ${SED} "s/name: nginx$/name: nginx2/" | kubectl create -f - "${kube_flags[@]}"
|
|
|
|
|
# Deletion of both deployments should not be blocked
|
|
|
|
|
kubectl delete deployment nginx2 "${kube_flags[@]}"
|
|
|
|
|
# Clean up
|
|
|
|
@@ -3337,7 +3330,7 @@ run_multi_resources_tests() {
|
|
|
|
|
fi
|
|
|
|
|
# Command: kubectl edit multiple resources
|
|
|
|
|
temp_editor="${KUBE_TEMP}/tmp-editor.sh"
|
|
|
|
|
echo -e "#!/bin/bash\n$SED -i \"s/status\:\ replaced/status\:\ edited/g\" \$@" > "${temp_editor}"
|
|
|
|
|
echo -e "#!/bin/bash\n${SED} -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
|
|
|
|
@@ -3562,7 +3555,7 @@ run_clusterroles_tests() {
|
|
|
|
|
kubectl set subject "${kube_flags[@]}" clusterrolebinding super-sa --serviceaccount=otherfoo:foo
|
|
|
|
|
kube::test::get_object_assert clusterrolebinding/super-sa "{{range.subjects}}{{.namespace}}:{{end}}" 'otherns:otherfoo:'
|
|
|
|
|
kube::test::get_object_assert clusterrolebinding/super-sa "{{range.subjects}}{{.name}}:{{end}}" 'sa-name:foo:'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# test `kubectl create rolebinding`
|
|
|
|
|
# test `kubectl set subject rolebinding`
|
|
|
|
|
kubectl create "${kube_flags[@]}" rolebinding admin --clusterrole=admin --user=default-admin
|
|
|
|
|