Skip to content

Commit ddcd63f

Browse files
committed
Only add cluster tags when cluster-tagstyle is explicitly set
Previously, remote cluster resources were auto-tagged with a default blue color. Now tags are only added when the cluster-tagstyle label is explicitly configured in the cluster's clusterLabels. Updated tests to verify: - No tag added when cluster-tagstyle is not set - Tag added with correct style when cluster-tagstyle is set
1 parent a201c5d commit ddcd63f

File tree

2 files changed

+34
-42
lines changed

2 files changed

+34
-42
lines changed

pkg/homer/cluster_tag_test.go

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,33 @@ func TestIngressClusterAutoTag(t *testing.T) {
1919
expectedTagStyle string
2020
}{
2121
{
22-
name: "Remote cluster ottawa - default blue",
23-
clusterAnnot: "ottawa",
24-
expectTag: true,
25-
expectedTagName: "ottawa",
26-
expectedTagStyle: "is-info", // Default blue
22+
name: "Remote cluster without tagstyle - no tag",
23+
clusterAnnot: "ottawa",
24+
expectTag: false,
2725
},
2826
{
29-
name: "Remote cluster robbinsdale - default blue",
30-
clusterAnnot: "robbinsdale",
27+
name: "Remote cluster with blue tag",
28+
clusterAnnot: "ottawa",
29+
tagStyleLabel: "is-info",
3130
expectTag: true,
32-
expectedTagName: "robbinsdale",
33-
expectedTagStyle: "is-info", // Default blue
31+
expectedTagName: "ottawa",
32+
expectedTagStyle: "is-info",
3433
},
3534
{
36-
name: "Remote cluster with custom red color",
37-
clusterAnnot: "ottawa",
35+
name: "Remote cluster with red tag",
36+
clusterAnnot: "production",
3837
tagStyleLabel: "is-danger",
3938
expectTag: true,
40-
expectedTagName: "ottawa",
41-
expectedTagStyle: "is-danger", // Custom red
39+
expectedTagName: "production",
40+
expectedTagStyle: "is-danger",
4241
},
4342
{
44-
name: "Remote cluster with custom yellow color",
43+
name: "Remote cluster with yellow tag",
4544
clusterAnnot: "staging",
4645
tagStyleLabel: "is-warning",
4746
expectTag: true,
4847
expectedTagName: "staging",
49-
expectedTagStyle: "is-warning", // Custom yellow
48+
expectedTagStyle: "is-warning",
5049
},
5150
{
5251
name: "Local cluster",
@@ -137,26 +136,25 @@ func TestHTTPRouteClusterAutoTag(t *testing.T) {
137136
expectedTagStyle string
138137
}{
139138
{
140-
name: "Remote cluster ottawa - default blue",
141-
clusterAnnot: "ottawa",
142-
expectTag: true,
143-
expectedTagName: "ottawa",
144-
expectedTagStyle: "is-info", // Default blue
139+
name: "Remote cluster without tagstyle - no tag",
140+
clusterAnnot: "ottawa",
141+
expectTag: false,
145142
},
146143
{
147-
name: "Remote cluster robbinsdale - default blue",
148-
clusterAnnot: "robbinsdale",
144+
name: "Remote cluster with blue tag",
145+
clusterAnnot: "ottawa",
146+
tagStyleLabel: "is-info",
149147
expectTag: true,
150-
expectedTagName: "robbinsdale",
151-
expectedTagStyle: "is-info", // Default blue
148+
expectedTagName: "ottawa",
149+
expectedTagStyle: "is-info",
152150
},
153151
{
154-
name: "Remote cluster with custom red color",
152+
name: "Remote cluster with red tag",
155153
clusterAnnot: "production",
156154
tagStyleLabel: "is-danger",
157155
expectTag: true,
158156
expectedTagName: "production",
159-
expectedTagStyle: "is-danger", // Custom red
157+
expectedTagStyle: "is-danger",
160158
},
161159
{
162160
name: "Local cluster",

pkg/homer/config.go

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,16 +1177,13 @@ func createIngressItem(ingress networkingv1.Ingress, host string, validRuleCount
11771177
item.Namespace = ingress.ObjectMeta.Namespace
11781178
item.LastUpdate = ingress.ObjectMeta.CreationTimestamp.Time.Format("2006-01-02T15:04:05Z")
11791179

1180-
// Auto-tag with cluster name if present
1180+
// Auto-tag with cluster name if cluster-tagstyle label is set
11811181
if clusterName, ok := ingress.ObjectMeta.Annotations["homer.rajsingh.info/cluster"]; ok && clusterName != "" && clusterName != "local" {
1182-
setItemParameter(&item, "tag", clusterName)
1183-
1184-
// Check if cluster-tagstyle label is set, otherwise use default blue
1185-
tagStyle := "is-info" // Default blue
1186-
if customStyle, hasStyle := ingress.ObjectMeta.Labels["cluster-tagstyle"]; hasStyle && customStyle != "" {
1187-
tagStyle = customStyle
1182+
// Only add tag if cluster-tagstyle is explicitly set
1183+
if tagStyle, hasStyle := ingress.ObjectMeta.Labels["cluster-tagstyle"]; hasStyle && tagStyle != "" {
1184+
setItemParameter(&item, "tag", clusterName)
1185+
setItemParameter(&item, "tagstyle", tagStyle)
11881186
}
1189-
setItemParameter(&item, "tagstyle", tagStyle)
11901187
}
11911188

11921189
return item
@@ -1322,16 +1319,13 @@ func createHTTPRouteItem(httproute *gatewayv1.HTTPRoute, hostname, protocol stri
13221319
setItemParameter(&item, "subtitle", "")
13231320
}
13241321

1325-
// Auto-tag with cluster name if present
1322+
// Auto-tag with cluster name if cluster-tagstyle label is set
13261323
if clusterName, ok := httproute.ObjectMeta.Annotations["homer.rajsingh.info/cluster"]; ok && clusterName != "" && clusterName != "local" {
1327-
setItemParameter(&item, "tag", clusterName)
1328-
1329-
// Check if cluster-tagstyle label is set, otherwise use default blue
1330-
tagStyle := "is-info" // Default blue
1331-
if customStyle, hasStyle := httproute.ObjectMeta.Labels["cluster-tagstyle"]; hasStyle && customStyle != "" {
1332-
tagStyle = customStyle
1324+
// Only add tag if cluster-tagstyle is explicitly set
1325+
if tagStyle, hasStyle := httproute.ObjectMeta.Labels["cluster-tagstyle"]; hasStyle && tagStyle != "" {
1326+
setItemParameter(&item, "tag", clusterName)
1327+
setItemParameter(&item, "tagstyle", tagStyle)
13331328
}
1334-
setItemParameter(&item, "tagstyle", tagStyle)
13351329
}
13361330

13371331
return item

0 commit comments

Comments
 (0)