Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion data/data/gcp/bootstrap/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ resource "google_compute_firewall" "bootstrap_ingress_ssh" {
resource "google_compute_instance" "bootstrap" {
count = var.bootstrap_enabled ? 1 : 0

name = "${var.cluster_id}-bootstrap"
name = "${var.cluster_id}-b"
machine_type = var.machine_type
zone = var.zone

Expand Down
2 changes: 1 addition & 1 deletion data/data/gcp/master/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ resource "google_project_iam_member" "master-object-storage-admin" {
resource "google_compute_instance" "master" {
count = var.instance_count

name = "${var.cluster_id}-master-${count.index}"
name = "${var.cluster_id}-m-${count.index}"
machine_type = var.machine_type
zone = element(var.zones, count.index)

Expand Down
22 changes: 15 additions & 7 deletions pkg/asset/installconfig/clusterid.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ import (
utilrand "k8s.io/apimachinery/pkg/util/rand"

"github.com/openshift/installer/pkg/asset"
gcptypes "github.com/openshift/installer/pkg/types/gcp"
)

const (
// resource using InfraID usually have suffixes like `[-/_][a-z]{3,4}` eg. `_int`, `-ext` or `-ctlp`
maxNameLen = 32 - 5
randomLen = 5
maxBaseLen = maxNameLen - randomLen - 1
randomLen = 5
)

// ClusterID is the unique ID of the cluster, immutable during the cluster's life
Expand All @@ -41,8 +39,17 @@ func (a *ClusterID) Generate(dep asset.Parents) error {
ica := &InstallConfig{}
dep.Get(ica)

// resource using InfraID usually have suffixes like `[-/_][a-z]{3,4}` eg. `_int`, `-ext` or `-ctlp`
// and the maximum length for most resources is approx 32.
maxLen := 27
switch ica.Config.Platform.Name() {
case gcptypes.Name:
// GCP has stricter limit on instance names which are prefixed with infra-id
maxLen = 12
}

// add random chars to the end to randomize
a.InfraID = generateInfraID(ica.Config.ObjectMeta.Name)
a.InfraID = generateInfraID(ica.Config.ObjectMeta.Name, maxLen)
a.UUID = uuid.New()
return nil
}
Expand All @@ -53,9 +60,10 @@ func (a *ClusterID) Name() string {
}

// generateInfraID take base and returns a ID that
// - is of length maxNameLen
// - is of length maxLen
// - only contains `alphanum` or `-`
func generateInfraID(base string) string {
func generateInfraID(base string, maxLen int) string {
maxBaseLen := maxLen - (randomLen + 1)
// truncate to maxBaseLen
if len(base) > maxBaseLen {
base = base[:maxBaseLen]
Expand Down
4 changes: 2 additions & 2 deletions pkg/asset/installconfig/clusterid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func Test_generateInfraID(t *testing.T) {
expNonRand: "qwertyuiop",
}, {
input: "qwertyuiopasdfghjklzxcvbnm",
expLen: maxBaseLen + randomLen + 1,
expLen: 27,
expNonRand: "qwertyuiopasdfghjklzx",
}, {
input: "qwe.rty.@iop!",
Expand All @@ -27,7 +27,7 @@ func Test_generateInfraID(t *testing.T) {
}}
for _, test := range tests {
t.Run("", func(t *testing.T) {
got := generateInfraID(test.input)
got := generateInfraID(test.input, 27)
t.Log("InfraID", got)
assert.Equal(t, test.expLen, len(got))
assert.Equal(t, test.expNonRand, got[:len(got)-randomLen-1])
Expand Down
2 changes: 1 addition & 1 deletion pkg/asset/machines/gcp/machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func Machines(clusterID string, config *types.InstallConfig, pool *types.Machine
},
ObjectMeta: metav1.ObjectMeta{
Namespace: "openshift-machine-api",
Name: fmt.Sprintf("%s-%s-%d", clusterID, pool.Name, idx),
Name: fmt.Sprintf("%s-%s-%d", clusterID, pool.Name[:1], idx),
Labels: map[string]string{
"machine.openshift.io/cluster-api-cluster": clusterID,
"machine.openshift.io/cluster-api-machine-role": role,
Expand Down
3 changes: 2 additions & 1 deletion pkg/asset/machines/gcp/machinesets.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gcp

import (
"fmt"
"strings"

machineapi "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -41,7 +42,7 @@ func MachineSets(clusterID string, config *types.InstallConfig, pool *types.Mach
if err != nil {
return nil, errors.Wrap(err, "failed to create provider")
}
name := fmt.Sprintf("%s-%s-%s", clusterID, pool.Name, az)
name := fmt.Sprintf("%s-%s-%s", clusterID, pool.Name[:1], strings.TrimPrefix(az, fmt.Sprintf("%s-", platform.Region)))
mset := &machineapi.MachineSet{
TypeMeta: metav1.TypeMeta{
APIVersion: "machine.openshift.io/v1beta1",
Expand Down