Skip to content

Commit ab2a01f

Browse files
committed
Add kuttl test to catch any missing nodeSelectors
dnsmasq that is created by the kuttl tests and ovn-controller-*-config is the only exception (sets a specific nodeName)
1 parent 9fc5731 commit ab2a01f

10 files changed

Lines changed: 104 additions & 0 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
resources:
2+
- ../../base/openstackcontrolplane
3+
4+
patches:
5+
- target:
6+
kind: OpenStackControlPlane
7+
name: .*
8+
patch: |-
9+
- op: replace
10+
path: /metadata/name
11+
value: openstack
12+
- target:
13+
kind: OpenStackControlPlane
14+
path: patch.yaml
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: core.openstack.org/v1beta1
2+
kind: OpenStackControlPlane
3+
metadata:
4+
name: openstack
5+
spec:
6+
nodeSelector:
7+
node-role.kubernetes.io/worker: ""
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../common/assert-sample-deployment.yaml
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestStep
3+
commands:
4+
- script: |
5+
oc kustomize ../../../../config/samples/nodeselectors/global | oc apply -n $NAMESPACE -f -
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestAssert
3+
commands:
4+
- script: |
5+
echo "Checking all pods have expected nodeselector"
6+
EXPECTED_NODE_SELECTOR="node-role.kubernetes.io/worker:"
7+
BAD_OR_MISSING_NODE_SELECTOR=$(oc get pods -n $NAMESPACE -l service!=dnsmasq -o=go-template --template='{{ range .items }}{{ .metadata.name}}: {{ .spec.nodeSelector }}{{"\n"}}{{ end }}' | grep -v 'ovn-controller-.*-config' | sed -e '\!map\['"$EXPECTED_NODE_SELECTOR"'\]$!d')
8+
BAD_OR_MISSING_NODE_SELECTOR_COUNT=$(echo -n "$BAD_OR_MISSING_NODE_SELECTOR" | wc -l)
9+
if [ $BAD_OR_MISSING_NODE_SELECTOR_COUNT -ne 0 ]; then
10+
echo "Found $BAD_OR_MISSING_NODE_SELECTOR_COUNT pods with bad or missing nodeselector:"
11+
echo "$BAD_OR_MISSING_NODE_SELECTOR"
12+
exit 1
13+
fi
14+
- script: |
15+
echo "Checking all cronjobs have expected nodeselector"
16+
EXPECTED_NODE_SELECTOR="node-role.kubernetes.io/worker:"
17+
BAD_OR_MISSING_NODE_SELECTOR=$(oc get cronjobs -n $NAMESPACE -o=go-template --template='{{ range .items }}{{ .metadata.name}}: {{ .spec.jobTemplate.spec.template.spec.nodeSelector }}{{"\n"}}{{ end }}' | grep -v 'ovn-controller-.*-config' | sed -e '\!map\['"$EXPECTED_NODE_SELECTOR"'\]$!d')
18+
BAD_OR_MISSING_NODE_SELECTOR_COUNT=$(echo -n "$BAD_OR_MISSING_NODE_SELECTOR" | wc -l)
19+
if [ $BAD_OR_MISSING_NODE_SELECTOR_COUNT -ne 0 ]; then
20+
echo "Found $BAD_OR_MISSING_NODE_SELECTOR_COUNT cronjobs with bad or missing nodeselector:"
21+
echo "$BAD_OR_MISSING_NODE_SELECTOR"
22+
exit 1
23+
fi
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../common/assert-sample-deployment.yaml
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestStep
3+
timeout: 60
4+
commands:
5+
- script: |
6+
oc patch dnsmasq -n $NAMESPACE dnsmasq --type='json' -p='[{
7+
"op": "replace",
8+
"path": "/spec/nodeSelector",
9+
"value": {"kubernetes.io/os":"linux"}
10+
}]'
11+
- script: |
12+
oc patch openstackcontrolplane -n $NAMESPACE openstack --type='json' -p='[{
13+
"op": "replace",
14+
"path": "/spec/nodeSelector",
15+
"value": {"kubernetes.io/os":"linux"}
16+
}]'
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestAssert
3+
commands:
4+
- script: |
5+
echo "Checking all running pods have new nodeselector"
6+
EXPECTED_NODE_SELECTOR="kubernetes.io/os:linux"
7+
BAD_OR_MISSING_NODE_SELECTOR=$(oc get pods -n $NAMESPACE -l service!=dnsmasq --field-selector=status.phase=Running -o=go-template --template='{{ range .items }}{{ .metadata.name}}: {{ .spec.nodeSelector }}{{"\n"}}{{ end }}' | grep -v 'ovn-controller-.*-config' | sed -e '\!map\['"$EXPECTED_NODE_SELECTOR"'\]$!d')
8+
BAD_OR_MISSING_NODE_SELECTOR_COUNT=$(echo -n "$BAD_OR_MISSING_NODE_SELECTOR" | wc -l)
9+
if [ $BAD_OR_MISSING_NODE_SELECTOR_COUNT -ne 0 ]; then
10+
echo "Found $BAD_OR_MISSING_NODE_SELECTOR_COUNT pods with bad or missing nodeselector:"
11+
echo "$BAD_OR_MISSING_NODE_SELECTOR"
12+
exit 1
13+
fi
14+
- script: |
15+
echo "Checking all cronjobs have expected nodeselector"
16+
EXPECTED_NODE_SELECTOR="kubernetes.io/os:linux"
17+
BAD_OR_MISSING_NODE_SELECTOR=$(oc get cronjobs -n $NAMESPACE -o=go-template --template='{{ range .items }}{{ .metadata.name}}: {{ .spec.jobTemplate.spec.template.spec.nodeSelector }}{{"\n"}}{{ end }}' | grep -v 'ovn-controller-.*-config' | sed -e '\!map\['"$EXPECTED_NODE_SELECTOR"'\]$!d')
18+
BAD_OR_MISSING_NODE_SELECTOR_COUNT=$(echo -n "$BAD_OR_MISSING_NODE_SELECTOR" | wc -l)
19+
if [ $BAD_OR_MISSING_NODE_SELECTOR_COUNT -ne 0 ]; then
20+
echo "Found $BAD_OR_MISSING_NODE_SELECTOR_COUNT cronjobs with bad or missing nodeselector:"
21+
echo "$BAD_OR_MISSING_NODE_SELECTOR"
22+
exit 1
23+
fi
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestStep
3+
delete:
4+
- apiVersion: core.openstack.org/v1beta1
5+
kind: OpenStackControlPlane
6+
name: openstack
7+
commands:
8+
- script: |
9+
oc delete --ignore-not-found=true -n $NAMESPACE pvc \
10+
srv-swift-storage-0
11+
oc delete secret --ignore-not-found=true combined-ca-bundle -n $NAMESPACE
12+
oc delete secret -l service-cert -n $NAMESPACE
13+
oc delete secret -l ca-cert -n $NAMESPACE
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../common/errors_cleanup_openstack.yaml

0 commit comments

Comments
 (0)