Skip to content

Commit

Permalink
CORS-3254: Use a constant for the cluster ID gcp label format
Browse files Browse the repository at this point in the history
  • Loading branch information
bharath-b-rh committed Apr 3, 2024
1 parent 4d09657 commit b9c61f2
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 14 deletions.
3 changes: 2 additions & 1 deletion pkg/asset/ignition/bootstrap/gcp/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/asset/machines/gcp/gcpmachines.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}
9 changes: 5 additions & 4 deletions pkg/asset/machines/gcp/gcpmachines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)),
Expand All @@ -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
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/asset/manifests/gcp/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pkg/destroy/gcp/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pkg/infrastructure/gcp/clusterapi/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
7 changes: 2 additions & 5 deletions pkg/tfvars/gcp/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit b9c61f2

Please sign in to comment.