Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ func typedEnqueueDownstreamGVKRequest(gvk schema.GroupVersionKind) mchandler.Typ
return nil
}

clusterName := multicluster.ClusterName(strings.TrimPrefix(strings.ReplaceAll(clusterLabel, "_", "/"), "cluster-"))
clusterName := multicluster.ClusterName(downstreamclient.UpstreamClusterNameFromLabel(clusterLabel))

request := GVKRequest{
GVK: gvk,
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/httpproxy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ func (r *HTTPProxyReconciler) enqueueHTTPProxyForDownstreamCertificate() func(cl
if upstreamNs == "" || upstreamName == "" || upstreamCluster == "" {
return nil
}
clusterName := multicluster.ClusterName(strings.TrimPrefix(strings.ReplaceAll(upstreamCluster, "_", "/"), "cluster-"))
clusterName := multicluster.ClusterName(downstreamclient.UpstreamClusterNameFromLabel(upstreamCluster))
return []mcreconcile.Request{{
ClusterName: clusterName,
Request: ctrl.Request{NamespacedName: types.NamespacedName{Namespace: upstreamNs, Name: upstreamName}},
Expand Down
6 changes: 5 additions & 1 deletion internal/controller/iroh_dns_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,11 @@ func encodeIrohClusterLabel(clusterName string) string {
}

func decodeIrohClusterLabel(label string) string {
return strings.TrimPrefix(strings.ReplaceAll(label, "_", "/"), "cluster-")
// Tolerate labels written before #196, when cluster names carried a leading
// slash (encoded as "_"): strip it so the result matches the slash-less name
// the provider now engages. Mirrors downstreamclient.UpstreamClusterNameFromLabel.
name := strings.TrimPrefix(strings.ReplaceAll(label, "_", "/"), "cluster-")
return strings.TrimPrefix(name, "/")
}

func connectorEndpointZ32(connector *networkingv1alpha1.Connector) (string, error) {
Expand Down
28 changes: 17 additions & 11 deletions internal/controller/iroh_dns_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,21 +202,27 @@ func TestBuildDesiredRecordSet_RecordContents(t *testing.T) {
}

func TestEncodeDecodeIrohClusterLabel(t *testing.T) {
tests := []string{
"",
"/test-project-staging",
"/zachs-project-z5pegw",
"plain-no-slashes",
"/with/multiple/slashes",
}
for _, want := range tests {
t.Run(want, func(t *testing.T) {
got := decodeIrohClusterLabel(encodeIrohClusterLabel(want))
if got != want {
// Modern (slash-less) cluster names round-trip exactly.
for _, want := range []string{"", "test-project-staging", "zachs-project-z5pegw", "plain-no-slashes"} {
t.Run("roundtrip/"+want, func(t *testing.T) {
if got := decodeIrohClusterLabel(encodeIrohClusterLabel(want)); got != want {
t.Errorf("round-trip mismatch: encode(%q) -> decode = %q", want, got)
}
})
}

// Labels written before #196 carried a leading slash; decode strips it so
// they resolve to the slash-less name the provider now engages.
for label, want := range map[string]string{
"cluster-_test-project-staging": "test-project-staging",
"cluster-_zachs-project-z5pegw": "zachs-project-z5pegw",
} {
t.Run("legacy/"+label, func(t *testing.T) {
if got := decodeIrohClusterLabel(label); got != want {
t.Errorf("decodeIrohClusterLabel(%q) = %q, want %q", label, got, want)
}
})
}
}

func TestBuildDesiredRecordSet_RelayOnlyOmitsAddrEntry(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/trafficprotectionpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1337,7 +1337,7 @@ func (r *TrafficProtectionPolicyReconciler) enqueuePoliciesForCertificate() hand
// cluster via mcsingle.Get (which requires clusterName == "single").
// The label value is "cluster-<name>" with "/" replaced by "_".
clusterLabel := downstreamNamespace.Labels[downstreamclient.UpstreamOwnerClusterNameLabel]
upstreamClusterName := multicluster.ClusterName(strings.TrimPrefix(strings.ReplaceAll(clusterLabel, "_", "/"), "cluster-"))
upstreamClusterName := multicluster.ClusterName(downstreamclient.UpstreamClusterNameFromLabel(clusterLabel))

logger.Info("certificate became ready, enqueueing reconcile", "certificate", cert.GetName(), "upstreamNamespace", upstreamNamespace)

Expand Down
Loading