Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions internal/dataplane/util/ansible_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package util //nolint:revive // util is an acceptable package name in this conte

import (
"context"
"crypto/sha256"
"encoding/hex"
"encoding/json"
"fmt"
"sort"
Expand Down Expand Up @@ -167,29 +169,23 @@ func GetAnsibleExecution(ctx context.Context,
return ansibleEE, nil
}

// getAnsibleExecutionNamePrefix compute the name of the AnsibleEE
func getAnsibleExecutionNamePrefix(serviceName string) string {
AnsibleExecutionServiceNameLen := apimachineryvalidation.DNS1123LabelMaxLength - 10

if len(serviceName) > AnsibleExecutionServiceNameLen {
return serviceName[:AnsibleExecutionServiceNameLen]
}

return serviceName
}

// GetAnsibleExecutionNameAndLabels Name and Labels of AnsibleEE
func GetAnsibleExecutionNameAndLabels(service *dataplanev1.OpenStackDataPlaneService,
deploymentName string,
nodeSetName string,
) (string, map[string]string) {
executionName := fmt.Sprintf("%s-%s", getAnsibleExecutionNamePrefix(service.Name), deploymentName)
executionName := fmt.Sprintf("%s-%s", service.Name, deploymentName)
if !service.Spec.DeployOnAllNodeSets {
executionName = fmt.Sprintf("%s-%s", executionName, nodeSetName)
}

if len(executionName) > apimachineryvalidation.DNS1123LabelMaxLength {
executionName = strings.TrimRight(executionName[:apimachineryvalidation.DNS1123LabelMaxLength], "-.")
hash := sha256.Sum256([]byte(executionName))
hashSuffix := hex.EncodeToString(hash[:])[:8]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not guranteed to be unique either, but the conflict probability is much less.

// 9 = "-" + 8 char hash suffix
maxPrefix := apimachineryvalidation.DNS1123LabelMaxLength - 9
prefix := strings.TrimRight(executionName[:maxPrefix], "-.")
executionName = fmt.Sprintf("%s-%s", prefix, hashSuffix)
}

labels := map[string]string{
Expand Down