Skip to content

Commit 777fe8a

Browse files
committed
Fix: Trigger nodeSet reconciler with ansibleVarsFrom changes
The NodeSet reconciler would not triggered on changes to ConfigMaps and Secrets from ansibleVarsFrom as we never check than and it won't update the nodeset status and message to mark it ready to changes Jira: OSPRH-17961
1 parent 6b57234 commit 777fe8a

2 files changed

Lines changed: 108 additions & 0 deletions

File tree

‎internal/controller/dataplane/openstackdataplanenodeset_controller.go‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,17 @@ func checkDeployment(ctx context.Context, helper *helper.Helper,
576576
deployment.Status.BmhRefHashes[instance.Name] != instance.Status.BmhRefHash) {
577577
continue
578578
}
579+
580+
hasAnsibleVarsFromChanged, err := checkAnsibleVarsFromChanged(ctx, helper, instance, deployment.Status.ConfigMapHashes, deployment.Status.SecretHashes)
581+
582+
if err != nil {
583+
return isNodeSetDeploymentReady, isNodeSetDeploymentRunning, isNodeSetDeploymentFailed, failedDeploymentName, err
584+
}
585+
586+
if hasAnsibleVarsFromChanged {
587+
continue
588+
}
589+
579590
isNodeSetDeploymentReady = true
580591
for k, v := range deployment.Status.ConfigMapHashes {
581592
instance.Status.ConfigMapHashes[k] = v
@@ -911,3 +922,43 @@ func (r *OpenStackDataPlaneNodeSetReconciler) GetSpecConfigHash(instance *datapl
911922
}
912923
return configHash, nil
913924
}
925+
926+
// checkAnsibleVarsFromChanged computes current hashes for ConfigMaps/Secrets
927+
// referenced in AnsibleVarsFrom and compares them with deployed hashes.
928+
// Returns true if any content has changed, false otherwise.
929+
func checkAnsibleVarsFromChanged(
930+
ctx context.Context,
931+
helper *helper.Helper,
932+
instance *dataplanev1.OpenStackDataPlaneNodeSet,
933+
deployedConfigMapHashes map[string]string,
934+
deployedSecretHashes map[string]string,
935+
) (bool, error) {
936+
// Compute current hashes for AnsibleVarsFrom ConfigMaps/Secrets
937+
currentConfigMapHashes := make(map[string]string)
938+
currentSecretHashes := make(map[string]string)
939+
940+
err := deployment.GetNodeSetAnsibleVarsFromHashes(
941+
ctx, helper, instance, currentConfigMapHashes, currentSecretHashes)
942+
if err != nil {
943+
helper.GetLogger().Error(err, "Unable to compute AnsibleVarsFrom hashes")
944+
return false, err
945+
}
946+
947+
// Compare current ConfigMap hashes with deployed hashes
948+
for name, currentHash := range currentConfigMapHashes {
949+
if deployedHash, exists := deployedConfigMapHashes[name]; !exists || deployedHash != currentHash {
950+
helper.GetLogger().Info("ConfigMap content changed", "configMap", name)
951+
return true, nil
952+
}
953+
}
954+
955+
// Compare current Secret hashes with deployed hashes
956+
for name, currentHash := range currentSecretHashes {
957+
if deployedHash, exists := deployedSecretHashes[name]; !exists || deployedHash != currentHash {
958+
helper.GetLogger().Info("Secret content changed", "secret", name)
959+
return true, nil
960+
}
961+
}
962+
963+
return false, nil
964+
}

‎internal/dataplane/hashes.go‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,60 @@ func GetDeploymentHashesForService(
100100

101101
return nil
102102
}
103+
104+
// GetNodeSetAnsibleVarsFromHashes computes hashes for ConfigMaps and Secrets
105+
// referenced in the NModeSet's AnsibleVarsFrom field (both NodeTemplate and
106+
// individual Nodes)
107+
func GetNodeSetAnsibleVarsFromHashes(
108+
ctx context.Context,
109+
helper *helper.Helper,
110+
instance *dataplanev1.OpenStackDataPlaneNodeSet,
111+
configMapHashes map[string]string,
112+
secretHashes map[string]string,
113+
) error {
114+
namespace := instance.Namespace
115+
116+
// helper function to process AnsibleVarsFrom data source
117+
processAnsibleVarsFrom := func(varsFrom []dataplanev1.DataSource) error {
118+
for _, dataSource := range varsFrom {
119+
cm, sec, err := dataplaneutil.GetDataSourceCmSecret(ctx, helper, namespace, dataSource)
120+
121+
if err != nil {
122+
return err
123+
}
124+
125+
if cm != nil {
126+
hash, err := configmap.Hash(cm)
127+
if err != nil {
128+
helper.GetLogger().Error(err, "Unable to hash ConfigMap", "configMap", cm.Name)
129+
return err
130+
}
131+
configMapHashes[cm.Name] = hash
132+
}
133+
134+
if sec != nil {
135+
hash, err := secret.Hash(sec)
136+
if err != nil {
137+
helper.GetLogger().Error(err, "Unable to hash Secret", "secret", sec.Name)
138+
return err
139+
}
140+
secretHashes[sec.Name] = hash
141+
}
142+
}
143+
return nil
144+
}
145+
146+
// Process NodeTemplate level AnsibleVarsFrom
147+
if err := processAnsibleVarsFrom(instance.Spec.NodeTemplate.Ansible.AnsibleVarsFrom); err != nil {
148+
return err
149+
}
150+
151+
// Process individual Node leve AnsibleVarsFrom
152+
for _, node := range instance.Spec.Nodes {
153+
if err := processAnsibleVarsFrom(node.Ansible.AnsibleVarsFrom); err != nil {
154+
return nil
155+
}
156+
}
157+
158+
return nil
159+
}

0 commit comments

Comments
 (0)