Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for semantically equal DaemonSet updates #43406

Merged
merged 2 commits into from Apr 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions hack/make-rules/test-cmd-util.sh
Expand Up @@ -66,6 +66,7 @@ static="static"
storageclass="storageclass"
subjectaccessreviews="subjectaccessreviews"
thirdpartyresources="thirdpartyresources"
daemonsets="daemonsets"


# Stops the running kubectl proxy, if there is one.
Expand Down Expand Up @@ -2574,6 +2575,22 @@ run_rs_tests() {
fi
}

run_daemonset_tests() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this tested here? Shouldn't this be a unit test? Is this to test that kubectl doesn't introduce some sort of change? If so please add a comment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to catch the original issue #43218. Test it here because [] specified in yaml config will be converted to null.

I have a unit test in validation. Is that not enough?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just wondering if this test adds anything over the unit test you've already put in.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. The validation unit test only tests the validation part. I still want to test that after updating a DaemonSet with a semantically equal change, templateGeneration won't change. It can't be done in DaemonSet controller unit test, because templateGeneration is updated by API server but not DaemonSet controller.

kube::log::status "Testing kubectl(v1:daemonsets)"

### Create a rolling update DaemonSet
# Pre-condition: no DaemonSet exists
kube::test::get_object_assert daemonsets "{{range.items}}{{$id_field}}:{{end}}" ''
# Command
kubectl apply -f hack/testdata/rollingupdate-daemonset.yaml "${kube_flags[@]}"
# Template Generation should be 1
kube::test::get_object_assert 'daemonsets bind' "{{${template_generation_field}}}" '1'
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'
kubectl delete -f hack/testdata/rollingupdate-daemonset.yaml "${kube_flags[@]}"
}

run_multi_resources_tests() {
kube::log::status "Testing kubectl(v1:multiple resources)"

Expand Down Expand Up @@ -2798,6 +2815,7 @@ runTests() {
deployment_second_image_field="(index .spec.template.spec.containers 1).image"
change_cause_annotation='.*kubernetes.io/change-cause.*'
pdb_min_available=".spec.minAvailable"
template_generation_field=".spec.templateGeneration"

# Make sure "default" namespace exists.
if kube::test::if_supports_resource "${namespaces}" ; then
Expand Down Expand Up @@ -3180,6 +3198,14 @@ runTests() {
fi


##################
# DaemonSets #
##################

if kube::test::if_supports_resource "${daemonsets}" ; then
run_daemonset_tests
fi

###########################
# Replication controllers #
###########################
Expand Down
27 changes: 27 additions & 0 deletions hack/testdata/rollingupdate-daemonset.yaml
@@ -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:2.0
36 changes: 36 additions & 0 deletions pkg/apis/extensions/validation/validation_test.go
Expand Up @@ -444,6 +444,15 @@ func TestValidateDaemonSetUpdate(t *testing.T) {
Spec: validPodSpecAbc,
},
}
validPodTemplateAbcSemanticallyEqual := api.PodTemplate{
Template: api.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: validSelector,
},
Spec: validPodSpecAbc,
},
}
validPodTemplateAbcSemanticallyEqual.Template.Spec.ImagePullSecrets = []api.LocalObjectReference{}
validPodTemplateNodeSelector := api.PodTemplate{
Template: api.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -618,6 +627,33 @@ func TestValidateDaemonSetUpdate(t *testing.T) {
},
},
},
"unchanged templateGeneration upon semantically equal template update": {
old: extensions.DaemonSet{
ObjectMeta: metav1.ObjectMeta{Name: "abc", Namespace: metav1.NamespaceDefault},
Spec: extensions.DaemonSetSpec{
Selector: &metav1.LabelSelector{MatchLabels: validSelector},
TemplateGeneration: 4,
Template: validPodTemplateAbc.Template,
UpdateStrategy: extensions.DaemonSetUpdateStrategy{
Type: extensions.OnDeleteDaemonSetStrategyType,
},
},
},
update: extensions.DaemonSet{
ObjectMeta: metav1.ObjectMeta{Name: "abc", Namespace: metav1.NamespaceDefault},
Spec: extensions.DaemonSetSpec{
Selector: &metav1.LabelSelector{MatchLabels: validSelector},
TemplateGeneration: 4,
Template: validPodTemplateAbcSemanticallyEqual.Template,
UpdateStrategy: extensions.DaemonSetUpdateStrategy{
Type: extensions.RollingUpdateDaemonSetStrategyType,
RollingUpdate: &extensions.RollingUpdateDaemonSet{
MaxUnavailable: intstr.FromInt(1),
},
},
},
},
},
}
for testName, successCase := range successCases {
// ResourceVersion is required for updates.
Expand Down