Skip to content

Commit

Permalink
Merge pull request #6185 from AnnaZivkovic/gcp_add_tags_to_installcon…
Browse files Browse the repository at this point in the history
…fig_defaultMachinePlatform

GCP: Added user specified tags on compute instances in installconfig
  • Loading branch information
openshift-ci[bot] authored Aug 5, 2022
2 parents d4eebc6 + a361340 commit 3f27a2e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
18 changes: 18 additions & 0 deletions data/data/install.openshift.io_installconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,12 @@ spec:
required:
- DiskSizeGB
type: object
tags:
description: Tags defines a set of network tags which will
be added to instances in the machineset
items:
type: string
type: array
type:
description: InstanceType defines the GCP instance type.
eg. n1-standard-4
Expand Down Expand Up @@ -1010,6 +1016,12 @@ spec:
required:
- DiskSizeGB
type: object
tags:
description: Tags defines a set of network tags which will
be added to instances in the machineset
items:
type: string
type: array
type:
description: InstanceType defines the GCP instance type. eg.
n1-standard-4
Expand Down Expand Up @@ -2186,6 +2198,12 @@ spec:
required:
- DiskSizeGB
type: object
tags:
description: Tags defines a set of network tags which will
be added to instances in the machineset
items:
type: string
type: array
type:
description: InstanceType defines the GCP instance type. eg.
n1-standard-4
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 @@ -113,7 +113,7 @@ func provider(clusterID string, platform *gcp.Platform, mpool *gcp.MachinePool,
Email: fmt.Sprintf("%s-%s@%s.iam.gserviceaccount.com", clusterID, role[0:1], platform.ProjectID),
Scopes: []string{"https://www.googleapis.com/auth/cloud-platform"},
}},
Tags: []string{fmt.Sprintf("%s-%s", clusterID, role)},
Tags: append(mpool.Tags, []string{fmt.Sprintf("%s-%s", clusterID, role)}...),
MachineType: mpool.InstanceType,
Region: platform.Region,
Zone: az,
Expand Down
9 changes: 9 additions & 0 deletions pkg/types/gcp/machinepools.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ type MachinePool struct {
//
// +optional
OSDisk `json:"osDisk"`

// Tags defines a set of network tags which will be added to instances in the machineset
//
// +optional
Tags []string `json:"tags,omitempty"`
}

// OSDisk defines the disk for machines on GCP.
Expand Down Expand Up @@ -53,6 +58,10 @@ func (a *MachinePool) Set(required *MachinePool) {
a.InstanceType = required.InstanceType
}

if required.Tags != nil {
a.Tags = required.Tags
}

if required.OSDisk.DiskSizeGB > 0 {
a.OSDisk.DiskSizeGB = required.OSDisk.DiskSizeGB
}
Expand Down
13 changes: 13 additions & 0 deletions pkg/types/gcp/validation/machinepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package validation

import (
"fmt"
"regexp"
"strings"
"unicode"

"github.com/openshift/installer/pkg/types"
"github.com/openshift/installer/pkg/types/gcp"
Expand Down Expand Up @@ -33,6 +35,17 @@ func ValidateMachinePool(platform *gcp.Platform, p *gcp.MachinePool, fldPath *fi
}
}

for i, tag := range p.Tags {
if tag == "" {
allErrs = append(allErrs, field.Invalid(fldPath.Child("tags").Index(i), tag, fmt.Sprintf("tag can not be empty")))
} else if !unicode.IsLetter(rune(tag[0])) || (!unicode.IsLetter(rune(tag[len(tag)-1])) && !unicode.IsNumber(rune(tag[len(tag)-1]))) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("tags").Index(i), tag, fmt.Sprintf("tag can only start with a letter and must end with a letter or a number")))
} else if !regexp.MustCompile(`^[a-z0-9-]*$`).MatchString(tag) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("tags").Index(i), tag, fmt.Sprintf("tag can only contain lowercase letters, numbers, and dashes")))
} else if len(tag) > 63 {
allErrs = append(allErrs, field.Invalid(fldPath.Child("tags").Index(i), tag, fmt.Sprintf("maximum number of characters is 63")))
}
}
return allErrs
}

Expand Down

0 comments on commit 3f27a2e

Please sign in to comment.