Skip to content

Commit 0ca8f52

Browse files
committed
fix cluster-name-suffix to take precedence over name annotations
1 parent 06427cc commit 0ca8f52

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

pkg/homer/config.go

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,20 @@ func createIngressItems(ingress networkingv1.Ingress, domainFilters []string) []
11311131
item := createIngressItem(ingress, host, validRuleCount)
11321132
processItemAnnotations(&item, ingress.ObjectMeta.Annotations)
11331133

1134+
// Append cluster name suffix from label AFTER processing annotations
1135+
// so that it takes precedence over any name annotations
1136+
if clusterName, ok := ingress.ObjectMeta.Annotations["homer.rajsingh.info/cluster"]; ok && clusterName != "" && clusterName != "local" {
1137+
fmt.Fprintf(os.Stderr, "DEBUG: Ingress %s from cluster %s, labels: %v\n", ingress.ObjectMeta.Name, clusterName, ingress.ObjectMeta.Labels)
1138+
if suffix, hasSuffix := ingress.ObjectMeta.Labels["cluster-name-suffix"]; hasSuffix && suffix != "" {
1139+
if currentName, hasName := item.Parameters["name"]; hasName && currentName != "" {
1140+
fmt.Fprintf(os.Stderr, "DEBUG: Appending suffix %q to name %q\n", suffix, currentName)
1141+
setItemParameter(&item, "name", currentName+suffix)
1142+
}
1143+
} else {
1144+
fmt.Fprintf(os.Stderr, "DEBUG: No cluster-name-suffix label found for %s\n", ingress.ObjectMeta.Name)
1145+
}
1146+
}
1147+
11341148
// Skip items that are marked as hidden
11351149
if isItemHidden(&item) {
11361150
continue
@@ -1169,17 +1183,6 @@ func createIngressItem(ingress networkingv1.Ingress, host string, validRuleCount
11691183
name = ingress.ObjectMeta.Name + "-" + host
11701184
}
11711185

1172-
// Append cluster name suffix from label if set (only for remote clusters)
1173-
if clusterName, ok := ingress.ObjectMeta.Annotations["homer.rajsingh.info/cluster"]; ok && clusterName != "" && clusterName != "local" {
1174-
fmt.Fprintf(os.Stderr, "DEBUG: Ingress %s from cluster %s, labels: %v\n", ingress.ObjectMeta.Name, clusterName, ingress.ObjectMeta.Labels)
1175-
if suffix, hasSuffix := ingress.ObjectMeta.Labels["cluster-name-suffix"]; hasSuffix && suffix != "" {
1176-
fmt.Fprintf(os.Stderr, "DEBUG: Appending suffix %q to name %q\n", suffix, name)
1177-
name = name + suffix
1178-
} else {
1179-
fmt.Fprintf(os.Stderr, "DEBUG: No cluster-name-suffix label found for %s\n", ingress.ObjectMeta.Name)
1180-
}
1181-
}
1182-
11831186
setItemParameter(&item, "name", name)
11841187
setItemParameter(&item, "logo", IngressIconURL)
11851188
setItemParameter(&item, "subtitle", host)
@@ -1296,17 +1299,6 @@ func updateHomerConfigWithHTTPRoutes(
12961299
name = httproute.ObjectMeta.Name + "-" + hostStr
12971300
}
12981301

1299-
// Append cluster name suffix from label if set (only for remote clusters)
1300-
if clusterName, ok := httproute.ObjectMeta.Annotations["homer.rajsingh.info/cluster"]; ok && clusterName != "" && clusterName != "local" {
1301-
fmt.Fprintf(os.Stderr, "DEBUG: HTTPRoute %s from cluster %s, labels: %v\n", httproute.ObjectMeta.Name, clusterName, httproute.ObjectMeta.Labels)
1302-
if suffix, hasSuffix := httproute.ObjectMeta.Labels["cluster-name-suffix"]; hasSuffix && suffix != "" {
1303-
fmt.Fprintf(os.Stderr, "DEBUG: Appending suffix %q to name %q\n", suffix, name)
1304-
name = name + suffix
1305-
} else {
1306-
fmt.Fprintf(os.Stderr, "DEBUG: No cluster-name-suffix label found for %s\n", httproute.ObjectMeta.Name)
1307-
}
1308-
}
1309-
13101302
setItemParameter(&item, "name", name)
13111303

13121304
// Set metadata for conflict detection
@@ -1316,6 +1308,20 @@ func updateHomerConfigWithHTTPRoutes(
13161308

13171309
processItemAnnotations(&item, httproute.ObjectMeta.Annotations)
13181310

1311+
// Append cluster name suffix from label AFTER processing annotations
1312+
// so that it takes precedence over any name annotations
1313+
if clusterName, ok := httproute.ObjectMeta.Annotations["homer.rajsingh.info/cluster"]; ok && clusterName != "" && clusterName != "local" {
1314+
fmt.Fprintf(os.Stderr, "DEBUG: HTTPRoute %s from cluster %s, labels: %v\n", httproute.ObjectMeta.Name, clusterName, httproute.ObjectMeta.Labels)
1315+
if suffix, hasSuffix := httproute.ObjectMeta.Labels["cluster-name-suffix"]; hasSuffix && suffix != "" {
1316+
if currentName, hasName := item.Parameters["name"]; hasName && currentName != "" {
1317+
fmt.Fprintf(os.Stderr, "DEBUG: Appending suffix %q to name %q\n", suffix, currentName)
1318+
setItemParameter(&item, "name", currentName+suffix)
1319+
}
1320+
} else {
1321+
fmt.Fprintf(os.Stderr, "DEBUG: No cluster-name-suffix label found for %s\n", httproute.ObjectMeta.Name)
1322+
}
1323+
}
1324+
13191325
// Skip items that are marked as hidden
13201326
if isItemHidden(&item) {
13211327
continue

0 commit comments

Comments
 (0)