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 basic server-side apply test to test-cmd #73866

Merged
merged 1 commit into from
Feb 20, 2019
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
2 changes: 1 addition & 1 deletion hack/make-rules/test-cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function run_kube_apiserver() {
AUTHORIZATION_MODE="RBAC,AlwaysAllow"

# Enable features
ENABLE_FEATURE_GATES="DryRun=true"
ENABLE_FEATURE_GATES="ServerSideApply=true"
Copy link
Member

@spiffxp spiffxp Feb 23, 2019

Choose a reason for hiding this comment

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

I think this is causing run_kubectl_run_tests to flake (ref: #74431) EDIT: after rollback, I've been unable to repro

Copy link
Member

Choose a reason for hiding this comment

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

disregard, it works fine, I'm off to bisect beyond this PR


"${KUBE_OUTPUT_HOSTBIN}/kube-apiserver" \
--insecure-bind-address="127.0.0.1" \
Expand Down
71 changes: 71 additions & 0 deletions test/cmd/apply.sh
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,77 @@ __EOF__
kubectl delete -f hack/testdata/service-revision2.yaml "${kube_flags[@]}"


set +o nounset
set +o errexit
}

# Runs tests related to kubectl apply (server-side)
run_kubectl_apply_tests() {
set -o nounset
set -o errexit
set -x

create_and_use_new_namespace
kube::log::status "Testing kubectl apply --server-side"
## kubectl apply should create the resource that doesn't exist yet
# Pre-Condition: no POD exists
kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" ''
# Command: apply a pod "test-pod" (doesn't exist) should create this pod
kubectl apply --server-side -f hack/testdata/pod.yaml "${kube_flags[@]}"
# Post-Condition: pod "test-pod" is created
kube::test::get_object_assert 'pods test-pod' "{{${labels_field}.name}}" 'test-pod-label'
# Clean up
kubectl delete pods test-pod "${kube_flags[@]}"

## kubectl apply --server-dry-run
# Pre-Condition: no POD exists
kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" ''

# apply dry-run
kubectl apply --server-side --server-dry-run -f hack/testdata/pod.yaml "${kube_flags[@]}"
# No pod exists
kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" ''
# apply non dry-run creates the pod
kubectl apply --server-side -f hack/testdata/pod.yaml "${kube_flags[@]}"
# apply changes
kubectl apply --server-side --server-dry-run -f hack/testdata/pod-apply.yaml "${kube_flags[@]}"
# Post-Condition: label still has initial value
kube::test::get_object_assert 'pods test-pod' "{{${labels_field}.name}}" 'test-pod-label'

# clean-up
kubectl delete -f hack/testdata/pod.yaml "${kube_flags[@]}"

## kubectl apply dry-run on CR
# Create CRD
kubectl "${kube_flags_with_token[@]}" create -f - << __EOF__
{
"kind": "CustomResourceDefinition",
"apiVersion": "apiextensions.k8s.io/v1beta1",
"metadata": {
"name": "resources.mygroup.example.com"
},
"spec": {
"group": "mygroup.example.com",
"version": "v1alpha1",
"scope": "Namespaced",
"names": {
"plural": "resources",
"singular": "resource",
"kind": "Kind",
"listKind": "KindList"
}
}
}
__EOF__

# Dry-run create the CR
kubectl "${kube_flags[@]}" apply --server-side --server-dry-run -f hack/testdata/CRD/resource.yaml "${kube_flags[@]}"
# Make sure that the CR doesn't exist
! kubectl "${kube_flags[@]}" get resource/myobj

# clean-up
kubectl "${kube_flags[@]}" delete customresourcedefinition resources.mygroup.example.com

set +o nounset
set +o errexit
}