Skip to content

Commit e2e44bc

Browse files
committed
Fix AnsibleEE job name collisions for long names
Previously, when the combined service + deployment + nodeset name exceeded 63 characters (DNS1123 max), simple truncation could cause different jobs to end up with identical names, leading to collisions. Replace the arbitrary -10 prefix truncation with a hash-based approach: - Build the full execution name without premature truncation - If the name exceeds 63 characters, truncate to 54 characters and append an 8-character SHA256 hash suffix - This guarantees unique names even when truncation is required Closes: OSPRH-26041 Signed-off-by: Sergii Golovatiuk <sgolovat@redhat.com>
1 parent aa980a9 commit e2e44bc

1 file changed

Lines changed: 9 additions & 13 deletions

File tree

internal/dataplane/util/ansible_execution.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ package util //nolint:revive // util is an acceptable package name in this conte
1919

2020
import (
2121
"context"
22+
"crypto/sha256"
23+
"encoding/hex"
2224
"encoding/json"
2325
"fmt"
2426
"sort"
@@ -167,29 +169,23 @@ func GetAnsibleExecution(ctx context.Context,
167169
return ansibleEE, nil
168170
}
169171

170-
// getAnsibleExecutionNamePrefix compute the name of the AnsibleEE
171-
func getAnsibleExecutionNamePrefix(serviceName string) string {
172-
AnsibleExecutionServiceNameLen := apimachineryvalidation.DNS1123LabelMaxLength - 10
173-
174-
if len(serviceName) > AnsibleExecutionServiceNameLen {
175-
return serviceName[:AnsibleExecutionServiceNameLen]
176-
}
177-
178-
return serviceName
179-
}
180-
181172
// GetAnsibleExecutionNameAndLabels Name and Labels of AnsibleEE
182173
func GetAnsibleExecutionNameAndLabels(service *dataplanev1.OpenStackDataPlaneService,
183174
deploymentName string,
184175
nodeSetName string,
185176
) (string, map[string]string) {
186-
executionName := fmt.Sprintf("%s-%s", getAnsibleExecutionNamePrefix(service.Name), deploymentName)
177+
executionName := fmt.Sprintf("%s-%s", service.Name, deploymentName)
187178
if !service.Spec.DeployOnAllNodeSets {
188179
executionName = fmt.Sprintf("%s-%s", executionName, nodeSetName)
189180
}
190181

191182
if len(executionName) > apimachineryvalidation.DNS1123LabelMaxLength {
192-
executionName = strings.TrimRight(executionName[:apimachineryvalidation.DNS1123LabelMaxLength], "-.")
183+
hash := sha256.Sum256([]byte(executionName))
184+
hashSuffix := hex.EncodeToString(hash[:])[:8]
185+
// 9 = "-" + 8 char hash suffix
186+
maxPrefix := apimachineryvalidation.DNS1123LabelMaxLength - 9
187+
prefix := strings.TrimRight(executionName[:maxPrefix], "-.")
188+
executionName = fmt.Sprintf("%s-%s", prefix, hashSuffix)
193189
}
194190

195191
labels := map[string]string{

0 commit comments

Comments
 (0)