Skip to content

Commit c51b0bc

Browse files
authored
Merge pull request #200 from datum-cloud/fix/legacy-cluster-name-decode-2
fix(gateway,iroh-dns): tolerate legacy slash-encoded cluster names in remaining decoders
2 parents b368a26 + 7e77bfd commit c51b0bc

5 files changed

Lines changed: 25 additions & 15 deletions

internal/controller/gateway_resource_replicator_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ func typedEnqueueDownstreamGVKRequest(gvk schema.GroupVersionKind) mchandler.Typ
800800
return nil
801801
}
802802

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

805805
request := GVKRequest{
806806
GVK: gvk,

internal/controller/httpproxy_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ func (r *HTTPProxyReconciler) enqueueHTTPProxyForDownstreamCertificate() func(cl
632632
if upstreamNs == "" || upstreamName == "" || upstreamCluster == "" {
633633
return nil
634634
}
635-
clusterName := multicluster.ClusterName(strings.TrimPrefix(strings.ReplaceAll(upstreamCluster, "_", "/"), "cluster-"))
635+
clusterName := multicluster.ClusterName(downstreamclient.UpstreamClusterNameFromLabel(upstreamCluster))
636636
return []mcreconcile.Request{{
637637
ClusterName: clusterName,
638638
Request: ctrl.Request{NamespacedName: types.NamespacedName{Namespace: upstreamNs, Name: upstreamName}},

internal/controller/iroh_dns_controller.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,11 @@ func encodeIrohClusterLabel(clusterName string) string {
264264
}
265265

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

270274
func connectorEndpointZ32(connector *networkingv1alpha1.Connector) (string, error) {

internal/controller/iroh_dns_controller_test.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -202,21 +202,27 @@ func TestBuildDesiredRecordSet_RecordContents(t *testing.T) {
202202
}
203203

204204
func TestEncodeDecodeIrohClusterLabel(t *testing.T) {
205-
tests := []string{
206-
"",
207-
"/test-project-staging",
208-
"/zachs-project-z5pegw",
209-
"plain-no-slashes",
210-
"/with/multiple/slashes",
211-
}
212-
for _, want := range tests {
213-
t.Run(want, func(t *testing.T) {
214-
got := decodeIrohClusterLabel(encodeIrohClusterLabel(want))
215-
if got != want {
205+
// Modern (slash-less) cluster names round-trip exactly.
206+
for _, want := range []string{"", "test-project-staging", "zachs-project-z5pegw", "plain-no-slashes"} {
207+
t.Run("roundtrip/"+want, func(t *testing.T) {
208+
if got := decodeIrohClusterLabel(encodeIrohClusterLabel(want)); got != want {
216209
t.Errorf("round-trip mismatch: encode(%q) -> decode = %q", want, got)
217210
}
218211
})
219212
}
213+
214+
// Labels written before #196 carried a leading slash; decode strips it so
215+
// they resolve to the slash-less name the provider now engages.
216+
for label, want := range map[string]string{
217+
"cluster-_test-project-staging": "test-project-staging",
218+
"cluster-_zachs-project-z5pegw": "zachs-project-z5pegw",
219+
} {
220+
t.Run("legacy/"+label, func(t *testing.T) {
221+
if got := decodeIrohClusterLabel(label); got != want {
222+
t.Errorf("decodeIrohClusterLabel(%q) = %q, want %q", label, got, want)
223+
}
224+
})
225+
}
220226
}
221227

222228
func TestBuildDesiredRecordSet_RelayOnlyOmitsAddrEntry(t *testing.T) {

internal/controller/trafficprotectionpolicy_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,7 @@ func (r *TrafficProtectionPolicyReconciler) enqueuePoliciesForCertificate() hand
13371337
// cluster via mcsingle.Get (which requires clusterName == "single").
13381338
// The label value is "cluster-<name>" with "/" replaced by "_".
13391339
clusterLabel := downstreamNamespace.Labels[downstreamclient.UpstreamOwnerClusterNameLabel]
1340-
upstreamClusterName := multicluster.ClusterName(strings.TrimPrefix(strings.ReplaceAll(clusterLabel, "_", "/"), "cluster-"))
1340+
upstreamClusterName := multicluster.ClusterName(downstreamclient.UpstreamClusterNameFromLabel(clusterLabel))
13411341

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

0 commit comments

Comments
 (0)