Skip to content

Commit d22a285

Browse files
Merge pull request openshift#8691 from bfournie/capg-user-tags
CORS-3209: Set UserTags on CAPG resources
2 parents 27d6efa + 09bd624 commit d22a285

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

pkg/asset/machines/gcp/gcpmachines.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
"github.com/openshift/installer/pkg/asset"
1616
"github.com/openshift/installer/pkg/asset/installconfig"
17+
gcpmanifests "github.com/openshift/installer/pkg/asset/manifests/gcp"
1718
gcpconsts "github.com/openshift/installer/pkg/constants/gcp"
1819
"github.com/openshift/installer/pkg/types"
1920
gcptypes "github.com/openshift/installer/pkg/types/gcp"
@@ -141,6 +142,7 @@ func createGCPMachine(name string, installConfig *installconfig.InstallConfig, i
141142
RootDeviceType: ptr.To(capg.DiskType(mpool.OSDisk.DiskType)),
142143
RootDeviceSize: mpool.OSDisk.DiskSizeGB,
143144
AdditionalNetworkTags: mpool.Tags,
145+
ResourceManagerTags: gcpmanifests.GetTagsFromInstallConfig(installConfig),
144146
},
145147
}
146148
gcpMachine.SetGroupVersionKind(capg.GroupVersion.WithKind("GCPMachine"))

pkg/asset/machines/gcp/gcpmachines_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ func Test_GenerateMachines(t *testing.T) {
6565
installConfig: getICWithServiceAccountControlPlaneMachine(),
6666
expectedGCPConfig: getGCPMachineWithServiceAccountControlPlaneMachine(),
6767
},
68+
{
69+
name: "usertags",
70+
installConfig: getICWithUserTags(),
71+
expectedGCPConfig: getGCPMachineWithTags(),
72+
},
6873
}
6974
for _, tc := range cases {
7075
t.Run(tc.name, func(t *testing.T) {
@@ -179,6 +184,13 @@ func getICWithServiceAccountControlPlaneMachine() *installconfig.InstallConfig {
179184
return ic
180185
}
181186

187+
func getICWithUserTags() *installconfig.InstallConfig {
188+
ic := getBaseInstallConfig()
189+
ic.Config.Platform.GCP.UserTags = []gcptypes.UserTag{{ParentID: "my-project", Key: "foo", Value: "bar"},
190+
{ParentID: "other-project", Key: "id", Value: "1234"}}
191+
return ic
192+
}
193+
182194
func getBaseGCPMachine() *capg.GCPMachine {
183195
subnet := "012345678-master-subnet"
184196
image := "rhcos-415-92-202311241643-0-gcp-x86-64"
@@ -203,6 +215,7 @@ func getBaseGCPMachine() *capg.GCPMachine {
203215
204216
Scopes: []string{compute.CloudPlatformScope},
205217
},
218+
ResourceManagerTags: []capg.ResourceManagerTag{},
206219
},
207220
}
208221
gcpMachine.SetGroupVersionKind(capg.GroupVersion.WithKind("GCPMachine"))
@@ -282,3 +295,15 @@ func getBaseCapiMachine() *capi.Machine {
282295
capiMachine.SetGroupVersionKind(capi.GroupVersion.WithKind("Machine"))
283296
return capiMachine
284297
}
298+
299+
func getGCPMachineWithTags() *capg.GCPMachine {
300+
gcpMachine := getBaseGCPMachine()
301+
gcpMachine.Spec.ResourceManagerTags = []capg.ResourceManagerTag{
302+
{ParentID: "my-project",
303+
Key: "foo",
304+
Value: "bar"},
305+
{ParentID: "other-project",
306+
Key: "id",
307+
Value: "1234"}}
308+
return gcpMachine
309+
}

pkg/asset/manifests/gcp/cluster.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ func GenerateClusterAssets(installConfig *installconfig.InstallConfig, clusterID
155155
APIServerInstanceGroupTagOverride: ptr.To(InstanceGroupRoleTag),
156156
LoadBalancerType: ptr.To(capgLoadBalancerType),
157157
},
158+
ResourceManagerTags: GetTagsFromInstallConfig(installConfig),
158159
},
159160
}
160161
gcpCluster.SetGroupVersionKind(capg.GroupVersion.WithKind("GCPCluster"))
@@ -247,3 +248,17 @@ func getSubnet(ctx context.Context, project, region, subnetName string) (*comput
247248

248249
return subnet, nil
249250
}
251+
252+
// GetTagsFromInstallConfig will return a slice of ResourceManagerTags from UserTags in install-config.
253+
func GetTagsFromInstallConfig(installConfig *installconfig.InstallConfig) []capg.ResourceManagerTag {
254+
tags := make([]capg.ResourceManagerTag, len(installConfig.Config.Platform.GCP.UserTags))
255+
for i, tag := range installConfig.Config.Platform.GCP.UserTags {
256+
tags[i] = capg.ResourceManagerTag{
257+
ParentID: tag.ParentID,
258+
Key: tag.Key,
259+
Value: tag.Value,
260+
}
261+
}
262+
263+
return tags
264+
}

0 commit comments

Comments
 (0)