Skip to content
Snippets Groups Projects
Commit b8a0785c authored by Alex de Cock Buning's avatar Alex de Cock Buning
Browse files

operator: bug fix where dots in the node name broke the app

parent 40f62891
No related branches found
No related tags found
No related merge requests found
......@@ -199,7 +199,7 @@ func (r *OverlayReconciler) createExternalResources(ctx context.Context, overlay
for _, nodeName := range overlay.Spec.Topology.Nodes {
node := switchv1.Node{
Name: nodeName,
NodeIP: fmt.Sprintf("l2sm-switch-%s-%s", overlayName, nodeName),
NodeIP: utils.GenerateServiceName(overlayName, nodeName),
}
topologySwitch.Nodes = append(topologySwitch.Nodes, node)
}
......@@ -371,7 +371,7 @@ func (r *OverlayReconciler) createExternalResources(ctx context.Context, overlay
// Create a headless service for the ReplicaSet
service := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("l2sm-switch-%s-%s", overlay.Name, node),
Name: utils.GenerateServiceName(overlay.Name, node),
Namespace: overlay.Namespace,
Labels: map[string]string{"app": name},
},
......
......@@ -20,6 +20,7 @@ import (
"crypto/sha256"
"encoding/hex"
"fmt"
"hash/fnv"
"strings"
"k8s.io/apimachinery/pkg/runtime"
......@@ -133,3 +134,11 @@ func GetBridgeName(params BridgeParams) string {
dpid := hex.EncodeToString(dpidBytes)
return fmt.Sprintf("br-%s", dpid)
}
func GenerateServiceName(overlayName, nodeName string) string {
hash := fnv.New32() // Using FNV hash for a compact hash, but still 32 bits
hash.Write([]byte(fmt.Sprintf("%s%s", overlayName, nodeName)))
sum := hash.Sum32()
// Encode the hash as a base32 string and take the first 4 characters
return fmt.Sprintf("l2sm-switch-%04x", sum) // H
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment