Skip to content

Commit 74a9615

Browse files
authored
ROX-21884: add ability to override tenant resources values by clusterIDs (#2401)
* add ability to override tenant resources values by clusterIDs * fix gotag
1 parent 14476c3 commit 74a9615

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

internal/central/pkg/gitops/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ type TenantResourceConfig struct {
9292
// will be applied on top of the default tenant resource values configuration.
9393
type TenantResourceOverride struct {
9494
InstanceIDs []string `json:"instanceIds"`
95+
ClusterIDs []string `json:"clusterIds"`
9596
Values string `json:"values"`
9697
}
9798

internal/central/pkg/gitops/service.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func RenderTenantResourceValues(params CentralParams, config Config) (map[string
2424
}
2525

2626
for _, override := range config.TenantResources.Overrides {
27-
if !shouldApplyOverride(override.InstanceIDs, params) {
27+
if !shouldApplyOverride(override, params) {
2828
continue
2929
}
3030
rendered, err := renderPatchTemplate(override.Values, params)
@@ -77,15 +77,26 @@ type CentralParams struct {
7777
}
7878

7979
// shouldApplyOverride returns true if the given Central override should be applied to the given Central instance.
80-
func shouldApplyOverride(instanceIDs []string, ctx CentralParams) bool {
81-
for _, d := range instanceIDs {
80+
func shouldApplyOverride(override TenantResourceOverride, ctx CentralParams) bool {
81+
for _, d := range override.InstanceIDs {
8282
if d == "*" {
8383
return true
8484
}
8585
if d == ctx.ID {
8686
return true
8787
}
8888
}
89+
90+
for _, d := range override.ClusterIDs {
91+
if d == "*" {
92+
return true
93+
}
94+
95+
if d == ctx.ClusterID {
96+
return true
97+
}
98+
}
99+
89100
return false
90101
}
91102

internal/central/pkg/gitops/service_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,27 @@ func TestRenderTenantResourceValues(t *testing.T) {
137137
require.NoError(t, err)
138138
assert.Equal(t, map[string]interface{}{"foo": "central-1"}, got)
139139
},
140+
}, {
141+
name: "overrides with clusterID",
142+
params: CentralParams{
143+
ID: "central-1",
144+
ClusterID: "test-cluster-id",
145+
},
146+
config: Config{
147+
TenantResources: TenantResourceConfig{
148+
Default: `{"foo": "bar"}`,
149+
Overrides: []TenantResourceOverride{
150+
{
151+
ClusterIDs: []string{"test-cluster-id"},
152+
Values: `{"foo": "override"}`,
153+
},
154+
},
155+
},
156+
},
157+
assert: func(t *testing.T, got map[string]interface{}, err error) {
158+
require.NoError(t, err)
159+
assert.Equal(t, map[string]interface{}{"foo": "override"}, got)
160+
},
140161
},
141162
}
142163
for _, tt := range tests {

0 commit comments

Comments
 (0)