add tests

This commit is contained in:
HirazawaUi 2024-06-23 19:23:30 +08:00
parent e4aff1b2eb
commit c29a19610a
3 changed files with 57 additions and 0 deletions

View File

@ -0,0 +1,21 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-dep-null
spec:
selector:
matchLabels:
l1: l1
template:
metadata:
labels:
l1: l1
spec:
containers:
- name: nginx
image: registry.k8s.io/nginx:1.7.9
resources:
requests:
memory: "64Mi"
cpu: null
terminationMessagePolicy: null

View File

@ -0,0 +1,8 @@
kind: ResourceQuota
apiVersion: v1
metadata:
name: my-rq
spec:
hard:
limits.cpu: null
limits.memory: null

View File

@ -96,6 +96,34 @@ run_kubectl_apply_tests() {
# cleanup
kubectl delete pods selector-test-pod
# Create a deployment
kubectl apply -f hack/testdata/null-propagation/deployment-null.yml "${kube_flags[@]:?}"
# resources.limits.cpu should be nil.
kube::test::get_object_jsonpath_assert "deployment/my-dep-null" "{.spec.template.spec.containers[0].resources.requests.cpu}" ''
kube::test::get_object_jsonpath_assert "deployment/my-dep-null" "{.spec.template.spec.containers[0].resources.requests.memory}" '64Mi'
# The default value of the terminationMessagePolicy field is `File`, so the result will not be changed.
kube::test::get_object_jsonpath_assert "deployment/my-dep-null" "{.spec.template.spec.containers[0].terminationMessagePolicy}" 'File'
# kubectl apply on create should do what kubectl apply on update will accomplish.
kubectl apply -f hack/testdata/null-propagation/deployment-null.yml "${kube_flags[@]}"
kube::test::get_object_jsonpath_assert "deployment/my-dep-null" "{.spec.template.spec.containers[0].resources.requests.cpu}" ''
kube::test::get_object_jsonpath_assert "deployment/my-dep-null" "{.spec.template.spec.containers[0].resources.requests.memory}" '64Mi'
kube::test::get_object_jsonpath_assert "deployment/my-dep-null" "{.spec.template.spec.containers[0].terminationMessagePolicy}" 'File'
# hard.limits.cpu should be nil.
kubectl apply -f hack/testdata/null-propagation/resourcesquota-null.yml "${kube_flags[@]}"
kube::test::get_object_jsonpath_assert "resourcequota/my-rq" "{.spec.hard['limits\.cpu']}" ''
kube::test::get_object_jsonpath_assert "resourcequota/my-rq" "{.spec.hard['limits\.memory']}" ''
# kubectl apply on create should do what kubectl apply on update will accomplish.
kubectl apply -f hack/testdata/null-propagation/resourcesquota-null.yml "${kube_flags[@]}"
kube::test::get_object_jsonpath_assert "resourcequota/my-rq" "{.spec.hard['limits\.cpu']}" ''
kube::test::get_object_jsonpath_assert "resourcequota/my-rq" "{.spec.hard['limits\.memory']}" ''
# cleanup
kubectl delete deployment my-dep-null
kubectl delete resourcequota my-rq
## kubectl apply --dry-run=server
# Pre-Condition: no POD exists
kube::test::get_object_assert pods "{{range.items}}{{${id_field:?}}}:{{end}}" ''