Implement kubectl rollout history and undo for DaemonSet
This commit is contained in:
@@ -41,6 +41,8 @@ IMAGE_NGINX="gcr.io/google-containers/nginx:1.7.9"
|
||||
IMAGE_DEPLOYMENT_R1="gcr.io/google-containers/nginx:test-cmd" # deployment-revision1.yaml
|
||||
IMAGE_DEPLOYMENT_R2="$IMAGE_NGINX" # deployment-revision2.yaml
|
||||
IMAGE_PERL="gcr.io/google-containers/perl"
|
||||
IMAGE_DAEMONSET_R1="gcr.io/google-containers/pause:2.0"
|
||||
IMAGE_DAEMONSET_R2="gcr.io/google-containers/pause:latest"
|
||||
|
||||
# Expose kubectl directly for readability
|
||||
PATH="${KUBE_OUTPUT_HOSTBIN}":$PATH
|
||||
@@ -71,6 +73,7 @@ subjectaccessreviews="subjectaccessreviews"
|
||||
thirdpartyresources="thirdpartyresources"
|
||||
customresourcedefinitions="customresourcedefinitions"
|
||||
daemonsets="daemonsets"
|
||||
controllerrevisions="controllerrevisions"
|
||||
|
||||
|
||||
# Stops the running kubectl proxy, if there is one.
|
||||
@@ -2868,6 +2871,39 @@ run_daemonset_tests() {
|
||||
kubectl apply -f hack/testdata/rollingupdate-daemonset.yaml "${kube_flags[@]}"
|
||||
# Template Generation should stay 1
|
||||
kube::test::get_object_assert 'daemonsets bind' "{{${template_generation_field}}}" '1'
|
||||
# Clean up
|
||||
kubectl delete -f hack/testdata/rollingupdate-daemonset.yaml "${kube_flags[@]}"
|
||||
}
|
||||
|
||||
run_daemonset_history_tests() {
|
||||
kube::log::status "Testing kubectl(v1:daemonsets, v1:controllerrevisions)"
|
||||
|
||||
### Test rolling back a DaemonSet
|
||||
# Pre-condition: no DaemonSet or its pods exists
|
||||
kube::test::get_object_assert daemonsets "{{range.items}}{{$id_field}}:{{end}}" ''
|
||||
# Command
|
||||
# Create a DaemonSet (revision 1)
|
||||
kubectl apply -f hack/testdata/rollingupdate-daemonset.yaml "${kube_flags[@]}"
|
||||
# Rollback to revision 1 - should be no-op
|
||||
kubectl rollout undo daemonset --to-revision=1 "${kube_flags[@]}"
|
||||
kube::test::get_object_assert daemonset "{{range.items}}{{$daemonset_image_field}}:{{end}}" "${IMAGE_DAEMONSET_R1}:"
|
||||
# Update the DaemonSet (revision 2)
|
||||
kubectl apply -f hack/testdata/rollingupdate-daemonset-rv2.yaml "${kube_flags[@]}"
|
||||
kube::test::wait_object_assert daemonset "{{range.items}}{{$daemonset_image_field}}:{{end}}" "${IMAGE_DAEMONSET_R2}:"
|
||||
# Rollback to revision 1 with dry-run - should be no-op
|
||||
kubectl rollout undo daemonset --dry-run=true "${kube_flags[@]}"
|
||||
kube::test::get_object_assert daemonset "{{range.items}}{{$daemonset_image_field}}:{{end}}" "${IMAGE_DAEMONSET_R2}:"
|
||||
# Rollback to revision 1
|
||||
kubectl rollout undo daemonset --to-revision=1 "${kube_flags[@]}"
|
||||
kube::test::wait_object_assert daemonset "{{range.items}}{{$daemonset_image_field}}:{{end}}" "${IMAGE_DAEMONSET_R1}:"
|
||||
# Rollback to revision 1000000 - should fail
|
||||
output_message=$(! kubectl rollout undo daemonset --to-revision=1000000 "${kube_flags[@]}" 2>&1)
|
||||
kube::test::if_has_string "${output_message}" "unable to find specified revision"
|
||||
kube::test::get_object_assert daemonset "{{range.items}}{{$daemonset_image_field}}:{{end}}" "${IMAGE_DAEMONSET_R1}:"
|
||||
# Rollback to last revision
|
||||
kubectl rollout undo daemonset "${kube_flags[@]}"
|
||||
kube::test::wait_object_assert daemonset "{{range.items}}{{$daemonset_image_field}}:{{end}}" "${IMAGE_DAEMONSET_R2}:"
|
||||
# Clean up
|
||||
kubectl delete -f hack/testdata/rollingupdate-daemonset.yaml "${kube_flags[@]}"
|
||||
}
|
||||
|
||||
@@ -3103,6 +3139,7 @@ runTests() {
|
||||
pdb_min_available=".spec.minAvailable"
|
||||
pdb_max_unavailable=".spec.maxUnavailable"
|
||||
template_generation_field=".spec.templateGeneration"
|
||||
daemonset_image_field="(index .spec.template.spec.containers 0).image"
|
||||
|
||||
# Make sure "default" namespace exists.
|
||||
if kube::test::if_supports_resource "${namespaces}" ; then
|
||||
@@ -3555,6 +3592,9 @@ runTests() {
|
||||
|
||||
if kube::test::if_supports_resource "${daemonsets}" ; then
|
||||
run_daemonset_tests
|
||||
if kube::test::if_supports_resource "${controllerrevisions}"; then
|
||||
run_daemonset_history_tests
|
||||
fi
|
||||
fi
|
||||
|
||||
###########################
|
||||
|
27
hack/testdata/rollingupdate-daemonset-rv2.yaml
vendored
Normal file
27
hack/testdata/rollingupdate-daemonset-rv2.yaml
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
apiVersion: extensions/v1beta1
|
||||
kind: DaemonSet
|
||||
metadata:
|
||||
name: bind
|
||||
spec:
|
||||
updateStrategy:
|
||||
type: RollingUpdate
|
||||
rollingUpdate:
|
||||
maxUnavailable: 10%
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
service: bind
|
||||
spec:
|
||||
affinity:
|
||||
podAntiAffinity:
|
||||
requiredDuringSchedulingIgnoredDuringExecution:
|
||||
- labelSelector:
|
||||
matchExpressions:
|
||||
- key: "service"
|
||||
operator: "In"
|
||||
values: ["bind"]
|
||||
topologyKey: "kubernetes.io/hostname"
|
||||
namespaces: []
|
||||
containers:
|
||||
- name: kubernetes-pause
|
||||
image: gcr.io/google-containers/pause:latest
|
Reference in New Issue
Block a user