Skip to content

Commit b9c61f2

Browse files
committed
CORS-3254: Use a constant for the cluster ID gcp label format
1 parent 4d09657 commit b9c61f2

File tree

7 files changed

+17
-14
lines changed

7 files changed

+17
-14
lines changed

pkg/asset/ignition/bootstrap/gcp/storage.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/openshift/installer/pkg/asset/installconfig"
1212
gcpic "github.com/openshift/installer/pkg/asset/installconfig/gcp"
13+
gcpconsts "github.com/openshift/installer/pkg/constants/gcp"
1314
)
1415

1516
const (
@@ -53,7 +54,7 @@ func CreateBucketHandle(ctx context.Context, bucketName string) (*storage.Bucket
5354
// the data stored inside the object can be set at a later time.
5455
func CreateStorage(ctx context.Context, ic *installconfig.InstallConfig, bucketHandle *storage.BucketHandle, clusterID string) error {
5556
labels := map[string]string{}
56-
labels[fmt.Sprintf("kubernetes-io-cluster-%s", clusterID)] = "owned"
57+
labels[fmt.Sprintf(gcpconsts.ClusterIDLabelFmt, clusterID)] = "owned"
5758
for _, label := range ic.Config.GCP.UserLabels {
5859
labels[label.Key] = label.Value
5960
}

pkg/asset/machines/gcp/gcpmachines.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/openshift/installer/pkg/asset"
1515
"github.com/openshift/installer/pkg/asset/installconfig"
16+
gcpconsts "github.com/openshift/installer/pkg/constants/gcp"
1617
"github.com/openshift/installer/pkg/types"
1718
gcptypes "github.com/openshift/installer/pkg/types/gcp"
1819
)
@@ -197,7 +198,7 @@ func getLabelsFromInstallConfig(installConfig *installconfig.InstallConfig, infr
197198
userLabels[label.Key] = label.Value
198199
}
199200
// add OCP default label
200-
userLabels[fmt.Sprintf("kubernetes-io-cluster-%s", infraID)] = "owned"
201+
userLabels[fmt.Sprintf(gcpconsts.ClusterIDLabelFmt, infraID)] = "owned"
201202

202203
return userLabels
203204
}

pkg/asset/machines/gcp/gcpmachines_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
capi "sigs.k8s.io/cluster-api/api/v1beta1"
1515

1616
"github.com/openshift/installer/pkg/asset/installconfig"
17+
gcpconsts "github.com/openshift/installer/pkg/constants/gcp"
1718
"github.com/openshift/installer/pkg/types"
1819
gcptypes "github.com/openshift/installer/pkg/types/gcp"
1920
)
@@ -164,7 +165,7 @@ func getBaseGCPMachine() *capg.GCPMachine {
164165
Subnet: &subnet,
165166
Image: &image,
166167
AdditionalLabels: capg.Labels{
167-
"kubernetes-io-cluster-012345678": "owned",
168+
fmt.Sprintf(gcpconsts.ClusterIDLabelFmt, "012345678"): "owned",
168169
},
169170
RootDeviceSize: 128,
170171
RootDeviceType: ptr.To(capg.DiskType(diskType)),
@@ -181,9 +182,9 @@ func getBaseGCPMachine() *capg.GCPMachine {
181182
func getGCPMachineWithLabels() *capg.GCPMachine {
182183
gcpMachine := getBaseGCPMachine()
183184
gcpMachine.Spec.AdditionalLabels = capg.Labels{
184-
"kubernetes-io-cluster-012345678": "owned",
185-
"foo": "bar",
186-
"id": "1234"}
185+
fmt.Sprintf(gcpconsts.ClusterIDLabelFmt, "012345678"): "owned",
186+
"foo": "bar",
187+
"id": "1234"}
187188
return gcpMachine
188189
}
189190

pkg/asset/manifests/gcp/cluster.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/openshift/installer/pkg/asset"
1515
"github.com/openshift/installer/pkg/asset/installconfig"
1616
"github.com/openshift/installer/pkg/asset/manifests/capiutils"
17+
gcpconsts "github.com/openshift/installer/pkg/constants/gcp"
1718
"github.com/openshift/installer/pkg/types/gcp"
1819
)
1920

@@ -92,7 +93,7 @@ func GenerateClusterAssets(installConfig *installconfig.InstallConfig, clusterID
9293
autoCreateSubnets := false
9394

9495
labels := map[string]string{}
95-
labels[fmt.Sprintf("kubernetes-io-cluster-%s", clusterID.InfraID)] = "owned"
96+
labels[fmt.Sprintf(gcpconsts.ClusterIDLabelFmt, clusterID.InfraID)] = "owned"
9697
labels[fmt.Sprintf("capg-cluster-%s", clusterID.InfraID)] = "owned"
9798
for _, label := range installConfig.Config.GCP.UserLabels {
9899
labels[label.Key] = label.Value

pkg/destroy/gcp/disk.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"google.golang.org/api/compute/v1"
99
"google.golang.org/api/googleapi"
1010

11+
gcpconsts "github.com/openshift/installer/pkg/constants/gcp"
1112
"github.com/openshift/installer/pkg/types/gcp"
1213
)
1314

@@ -35,7 +36,7 @@ func (o *ClusterUninstaller) storageIDFilter() string {
3536
}
3637

3738
func (o *ClusterUninstaller) storageLabelFilter() string {
38-
return fmt.Sprintf("labels.kubernetes-io-cluster-%s = \"owned\"", o.formatClusterIDForStorage())
39+
return fmt.Sprintf("labels.%s = \"owned\"", fmt.Sprintf(gcpconsts.ClusterIDLabelFmt, o.formatClusterIDForStorage()))
3940
}
4041

4142
// storageLabelOrClusterIDFilter will perform the search for resources with the ClusterID, but

pkg/infrastructure/gcp/clusterapi/labels.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import (
44
"fmt"
55

66
"github.com/openshift/installer/pkg/asset/installconfig"
7+
gcpconsts "github.com/openshift/installer/pkg/constants/gcp"
78
)
89

910
func mergeLabels(ic *installconfig.InstallConfig, clusterID string) map[string]string {
1011
labels := map[string]string{}
11-
labels[fmt.Sprintf("kubernetes-io-cluster-%s", clusterID)] = "owned"
12+
labels[fmt.Sprintf(gcpconsts.ClusterIDLabelFmt, clusterID)] = "owned"
1213
for _, label := range ic.Config.GCP.UserLabels {
1314
labels[label.Key] = label.Value
1415
}

pkg/tfvars/gcp/gcp.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@ import (
55
"fmt"
66

77
machineapi "github.com/openshift/api/machine/v1beta1"
8+
gcpconsts "github.com/openshift/installer/pkg/constants/gcp"
89
"github.com/openshift/installer/pkg/types"
910
)
1011

1112
const (
1213
kmsKeyNameFmt = "projects/%s/locations/%s/keyRings/%s/cryptoKeys/%s"
13-
14-
// ocpDefaultLabelFmt is the format string for the default label
15-
// added to the OpenShift created GCP resources.
16-
ocpDefaultLabelFmt = "kubernetes-io-cluster-%s"
1714
)
1815

1916
// Auth is the collection of credentials that will be used by terrform.
@@ -79,7 +76,7 @@ func TFVars(sources TFVarsSources) ([]byte, error) {
7976

8077
labels := make(map[string]string, len(masterConfig.Labels)+1)
8178
// add OCP default label
82-
labels[fmt.Sprintf(ocpDefaultLabelFmt, sources.InfrastructureName)] = "owned"
79+
labels[fmt.Sprintf(gcpconsts.ClusterIDLabelFmt, sources.InfrastructureName)] = "owned"
8380
for k, v := range masterConfig.Labels {
8481
labels[k] = v
8582
}

0 commit comments

Comments
 (0)