diff --git a/pkg/asset/ignition/bootstrap/gcp/storage.go b/pkg/asset/ignition/bootstrap/gcp/storage.go index a024e55fd67..c3c90144297 100644 --- a/pkg/asset/ignition/bootstrap/gcp/storage.go +++ b/pkg/asset/ignition/bootstrap/gcp/storage.go @@ -10,6 +10,7 @@ import ( "github.com/openshift/installer/pkg/asset/installconfig" gcpic "github.com/openshift/installer/pkg/asset/installconfig/gcp" + gcpconsts "github.com/openshift/installer/pkg/constants/gcp" ) const ( @@ -53,7 +54,7 @@ func CreateBucketHandle(ctx context.Context, bucketName string) (*storage.Bucket // the data stored inside the object can be set at a later time. func CreateStorage(ctx context.Context, ic *installconfig.InstallConfig, bucketHandle *storage.BucketHandle, clusterID string) error { labels := map[string]string{} - labels[fmt.Sprintf("kubernetes-io-cluster-%s", clusterID)] = "owned" + labels[fmt.Sprintf(gcpconsts.ClusterIDLabelFmt, clusterID)] = "owned" for _, label := range ic.Config.GCP.UserLabels { labels[label.Key] = label.Value } diff --git a/pkg/asset/machines/gcp/gcpmachines.go b/pkg/asset/machines/gcp/gcpmachines.go index ecb65b9f1a6..c3c9e115d58 100644 --- a/pkg/asset/machines/gcp/gcpmachines.go +++ b/pkg/asset/machines/gcp/gcpmachines.go @@ -13,6 +13,7 @@ import ( "github.com/openshift/installer/pkg/asset" "github.com/openshift/installer/pkg/asset/installconfig" + gcpconsts "github.com/openshift/installer/pkg/constants/gcp" "github.com/openshift/installer/pkg/types" gcptypes "github.com/openshift/installer/pkg/types/gcp" ) @@ -197,7 +198,7 @@ func getLabelsFromInstallConfig(installConfig *installconfig.InstallConfig, infr userLabels[label.Key] = label.Value } // add OCP default label - userLabels[fmt.Sprintf("kubernetes-io-cluster-%s", infraID)] = "owned" + userLabels[fmt.Sprintf(gcpconsts.ClusterIDLabelFmt, infraID)] = "owned" return userLabels } diff --git a/pkg/asset/machines/gcp/gcpmachines_test.go b/pkg/asset/machines/gcp/gcpmachines_test.go index 801598a7df5..bd3c987e78d 100644 --- a/pkg/asset/machines/gcp/gcpmachines_test.go +++ b/pkg/asset/machines/gcp/gcpmachines_test.go @@ -14,6 +14,7 @@ import ( capi "sigs.k8s.io/cluster-api/api/v1beta1" "github.com/openshift/installer/pkg/asset/installconfig" + gcpconsts "github.com/openshift/installer/pkg/constants/gcp" "github.com/openshift/installer/pkg/types" gcptypes "github.com/openshift/installer/pkg/types/gcp" ) @@ -164,7 +165,7 @@ func getBaseGCPMachine() *capg.GCPMachine { Subnet: &subnet, Image: &image, AdditionalLabels: capg.Labels{ - "kubernetes-io-cluster-012345678": "owned", + fmt.Sprintf(gcpconsts.ClusterIDLabelFmt, "012345678"): "owned", }, RootDeviceSize: 128, RootDeviceType: ptr.To(capg.DiskType(diskType)), @@ -181,9 +182,9 @@ func getBaseGCPMachine() *capg.GCPMachine { func getGCPMachineWithLabels() *capg.GCPMachine { gcpMachine := getBaseGCPMachine() gcpMachine.Spec.AdditionalLabels = capg.Labels{ - "kubernetes-io-cluster-012345678": "owned", - "foo": "bar", - "id": "1234"} + fmt.Sprintf(gcpconsts.ClusterIDLabelFmt, "012345678"): "owned", + "foo": "bar", + "id": "1234"} return gcpMachine } diff --git a/pkg/asset/manifests/gcp/cluster.go b/pkg/asset/manifests/gcp/cluster.go index b3aa9c8e414..52824e8a85a 100644 --- a/pkg/asset/manifests/gcp/cluster.go +++ b/pkg/asset/manifests/gcp/cluster.go @@ -14,6 +14,7 @@ import ( "github.com/openshift/installer/pkg/asset" "github.com/openshift/installer/pkg/asset/installconfig" "github.com/openshift/installer/pkg/asset/manifests/capiutils" + gcpconsts "github.com/openshift/installer/pkg/constants/gcp" "github.com/openshift/installer/pkg/types/gcp" ) @@ -92,7 +93,7 @@ func GenerateClusterAssets(installConfig *installconfig.InstallConfig, clusterID autoCreateSubnets := false labels := map[string]string{} - labels[fmt.Sprintf("kubernetes-io-cluster-%s", clusterID.InfraID)] = "owned" + labels[fmt.Sprintf(gcpconsts.ClusterIDLabelFmt, clusterID.InfraID)] = "owned" labels[fmt.Sprintf("capg-cluster-%s", clusterID.InfraID)] = "owned" for _, label := range installConfig.Config.GCP.UserLabels { labels[label.Key] = label.Value diff --git a/pkg/destroy/gcp/disk.go b/pkg/destroy/gcp/disk.go index f0f2d4344e9..d68e3dc1d8b 100644 --- a/pkg/destroy/gcp/disk.go +++ b/pkg/destroy/gcp/disk.go @@ -8,6 +8,7 @@ import ( "google.golang.org/api/compute/v1" "google.golang.org/api/googleapi" + gcpconsts "github.com/openshift/installer/pkg/constants/gcp" "github.com/openshift/installer/pkg/types/gcp" ) @@ -35,7 +36,7 @@ func (o *ClusterUninstaller) storageIDFilter() string { } func (o *ClusterUninstaller) storageLabelFilter() string { - return fmt.Sprintf("labels.kubernetes-io-cluster-%s = \"owned\"", o.formatClusterIDForStorage()) + return fmt.Sprintf("labels.%s = \"owned\"", fmt.Sprintf(gcpconsts.ClusterIDLabelFmt, o.formatClusterIDForStorage())) } // storageLabelOrClusterIDFilter will perform the search for resources with the ClusterID, but diff --git a/pkg/infrastructure/gcp/clusterapi/labels.go b/pkg/infrastructure/gcp/clusterapi/labels.go index c514eee0205..488e4e5339a 100644 --- a/pkg/infrastructure/gcp/clusterapi/labels.go +++ b/pkg/infrastructure/gcp/clusterapi/labels.go @@ -4,11 +4,12 @@ import ( "fmt" "github.com/openshift/installer/pkg/asset/installconfig" + gcpconsts "github.com/openshift/installer/pkg/constants/gcp" ) func mergeLabels(ic *installconfig.InstallConfig, clusterID string) map[string]string { labels := map[string]string{} - labels[fmt.Sprintf("kubernetes-io-cluster-%s", clusterID)] = "owned" + labels[fmt.Sprintf(gcpconsts.ClusterIDLabelFmt, clusterID)] = "owned" for _, label := range ic.Config.GCP.UserLabels { labels[label.Key] = label.Value } diff --git a/pkg/tfvars/gcp/gcp.go b/pkg/tfvars/gcp/gcp.go index ea8c32b2751..fcc3869927d 100644 --- a/pkg/tfvars/gcp/gcp.go +++ b/pkg/tfvars/gcp/gcp.go @@ -5,15 +5,12 @@ import ( "fmt" machineapi "github.com/openshift/api/machine/v1beta1" + gcpconsts "github.com/openshift/installer/pkg/constants/gcp" "github.com/openshift/installer/pkg/types" ) const ( kmsKeyNameFmt = "projects/%s/locations/%s/keyRings/%s/cryptoKeys/%s" - - // ocpDefaultLabelFmt is the format string for the default label - // added to the OpenShift created GCP resources. - ocpDefaultLabelFmt = "kubernetes-io-cluster-%s" ) // Auth is the collection of credentials that will be used by terrform. @@ -79,7 +76,7 @@ func TFVars(sources TFVarsSources) ([]byte, error) { labels := make(map[string]string, len(masterConfig.Labels)+1) // add OCP default label - labels[fmt.Sprintf(ocpDefaultLabelFmt, sources.InfrastructureName)] = "owned" + labels[fmt.Sprintf(gcpconsts.ClusterIDLabelFmt, sources.InfrastructureName)] = "owned" for k, v := range masterConfig.Labels { labels[k] = v }