Skip to content

Commit eba4d82

Browse files
Merge pull request #1211 from olliewalsh/openstackclient-pod-template-hash
[openstackclient] Store hash to determine when pod spec changes
2 parents 81df93f + eaa330c commit eba4d82

11 files changed

Lines changed: 42 additions & 14 deletions

apis/bases/client.openstack.org_openstackclients.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ spec:
8282
- type
8383
type: object
8484
type: array
85+
hash:
86+
additionalProperties:
87+
type: string
88+
type: object
8589
observedGeneration:
8690
format: int64
8791
type: integer

apis/client/v1beta1/openstackclient_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ type OpenStackClientStatus struct {
6868

6969
//ObservedGeneration - the most recent generation observed for this object.
7070
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
71+
72+
// Map of hashes to track e.g. pod spec
73+
Hash map[string]string `json:"hash,omitempty"`
7174
}
7275

7376
// +kubebuilder:object:root=true

apis/client/v1beta1/zz_generated.deepcopy.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/client.openstack.org_openstackclients.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ spec:
8282
- type
8383
type: object
8484
type: array
85+
hash:
86+
additionalProperties:
87+
type: string
88+
type: object
8589
observedGeneration:
8690
format: int64
8791
type: integer

controllers/client/openstackclient_controller.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -307,16 +307,19 @@ func (r *OpenStackClientReconciler) Reconcile(ctx context.Context, req ctrl.Requ
307307

308308
spec := openstackclient.ClientPodSpec(ctx, instance, helper, configVarsHash)
309309

310+
podSpecHash, err := util.ObjectHash(spec)
311+
if err != nil {
312+
return ctrl.Result{}, err
313+
}
314+
315+
podSpecHashName := "podSpec"
316+
310317
op, err := controllerutil.CreateOrPatch(ctx, r.Client, osclient, func() error {
311318
isPodUpdate := !osclient.ObjectMeta.CreationTimestamp.IsZero()
312-
if !isPodUpdate {
319+
currentPodSpecHash := instance.Status.Hash[podSpecHashName]
320+
if !isPodUpdate || currentPodSpecHash != podSpecHash {
313321
osclient.Spec = spec
314-
} else {
315-
osclient.Spec.Containers[0].Env = spec.Containers[0].Env
316-
osclient.Spec.NodeSelector = spec.NodeSelector
317-
osclient.Spec.Containers[0].Image = instance.Spec.ContainerImage
318322
}
319-
320323
osclient.Labels = util.MergeStringMaps(osclient.Labels, clientLabels)
321324

322325
err = controllerutil.SetControllerReference(instance, osclient, r.Scheme)
@@ -360,6 +363,8 @@ func (r *OpenStackClientReconciler) Reconcile(ctx context.Context, req ctrl.Requ
360363
return ctrl.Result{}, err
361364
}
362365

366+
instance.Status.Hash, _ = util.SetHash(instance.Status.Hash, podSpecHashName, podSpecHash)
367+
363368
if op != controllerutil.OperationResultNone {
364369
util.LogForObject(
365370
helper,

hack/crd-schema-checker.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ set -euxo pipefail
33

44
CHECKER=$INSTALL_DIR/crd-schema-checker
55

6+
DISABLED_VALIDATORS=NoMaps # TODO: https://issues.redhat.com/browse/OSPRH-12254
7+
8+
CHECKER_ARGS=""
9+
if [[ ${DISABLED_VALIDATORS:+x} ]]; then
10+
CHECKER_ARGS="$CHECKER_ARGS --disabled-validators $DISABLED_VALIDATORS"
11+
fi
12+
613
TMP_DIR=$(mktemp -d)
714

815
function cleanup {
@@ -16,6 +23,7 @@ for crd in config/crd/bases/*.yaml; do
1623
mkdir -p "$(dirname "$TMP_DIR/$crd")"
1724
if git show "$BASE_REF:$crd" > "$TMP_DIR/$crd"; then
1825
$CHECKER check-manifests \
26+
$CHECKER_ARGS \
1927
--existing-crd-filename="$TMP_DIR/$crd" \
2028
--new-crd-filename="$crd"
2129
fi
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
apiVersion: kuttl.dev/v1beta1
22
kind: TestStep
33
commands:
4+
- script: |
5+
oc annotate namespace $NAMESPACE openshift.io/node-selector="beta.kubernetes.io/os=linux"
46
- script: |
57
oc kustomize ../../../../config/samples/nodeselectors/global | oc apply -n $NAMESPACE -f -

tests/kuttl/tests/ctlplane-nodeselectors/02-assert-nodeselector.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kind: TestAssert
33
commands:
44
- script: |
55
echo "Checking all pods have expected nodeselector"
6-
EXPECTED_NODE_SELECTOR="node-role.kubernetes.io/worker:"
6+
EXPECTED_NODE_SELECTOR="beta.kubernetes.io/os:linux node-role.kubernetes.io/worker:"
77
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')
88
BAD_OR_MISSING_NODE_SELECTOR_COUNT=$(echo -n "$BAD_OR_MISSING_NODE_SELECTOR" | wc -l)
99
if [ $BAD_OR_MISSING_NODE_SELECTOR_COUNT -ne 0 ]; then

tests/kuttl/tests/ctlplane-nodeselectors/03-update-nodeselector.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@ apiVersion: kuttl.dev/v1beta1
22
kind: TestStep
33
timeout: 60
44
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-
}]'
115
- script: |
126
oc patch openstackcontrolplane -n $NAMESPACE openstack --type='json' -p='[{
137
"op": "replace",

tests/kuttl/tests/ctlplane-nodeselectors/04-assert-nodeselector.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kind: TestAssert
33
commands:
44
- script: |
55
echo "Checking all running pods have new nodeselector"
6-
EXPECTED_NODE_SELECTOR="kubernetes.io/os:linux"
6+
EXPECTED_NODE_SELECTOR="beta.kubernetes.io/os:linux kubernetes.io/os:linux"
77
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')
88
BAD_OR_MISSING_NODE_SELECTOR_COUNT=$(echo -n "$BAD_OR_MISSING_NODE_SELECTOR" | wc -l)
99
if [ $BAD_OR_MISSING_NODE_SELECTOR_COUNT -ne 0 ]; then

0 commit comments

Comments
 (0)