Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OCM-6716 | feat: classic mp aws tags on create/describe #1968

Merged
merged 2 commits into from
Apr 25, 2024
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
11 changes: 6 additions & 5 deletions cmd/create/machinepool/machinepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/spf13/cobra"

"github.com/openshift/rosa/pkg/helper"
"github.com/openshift/rosa/pkg/helper/machinepools"
mpHelpers "github.com/openshift/rosa/pkg/helper/machinepools"
"github.com/openshift/rosa/pkg/helper/versions"
"github.com/openshift/rosa/pkg/interactive"
Expand All @@ -27,11 +28,6 @@ import (
func addMachinePool(cmd *cobra.Command, clusterKey string, cluster *cmv1.Cluster, r *rosa.Runtime) {
var err error

if cmd.Flags().Changed("tags") {
r.Reporter.Errorf("Setting the 'tags' flag is currently only allowed for Hosted Control Plane clusters")
os.Exit(1)
}

// Validate flags that are only allowed for multi-AZ clusters
isMultiAvailabilityZoneSet := cmd.Flags().Changed("multi-availability-zone")
if isMultiAvailabilityZoneSet && !cluster.MultiAZ() {
Expand Down Expand Up @@ -437,6 +433,8 @@ func addMachinePool(cmd *cobra.Command, clusterKey string, cluster *cmv1.Cluster
maxPrice = &price
}

awsTags := machinepools.GetAwsTags(cmd, r, args.tags)

mpBuilder := cmv1.NewMachinePool().
ID(name).
InstanceType(instanceType).
Expand All @@ -463,6 +461,9 @@ func addMachinePool(cmd *cobra.Command, clusterKey string, cluster *cmv1.Cluster
if len(securityGroupIds) > 0 {
awsMpBuilder.AdditionalSecurityGroupIds(securityGroupIds...)
}
if len(awsTags) > 0 {
awsMpBuilder.Tags(awsTags)
}
mpBuilder.AWS(awsMpBuilder)

// Create a single AZ machine pool for a multi-AZ cluster
Expand Down
1 change: 1 addition & 0 deletions cmd/describe/machinepool/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ Subnets:
Spot instances: Yes (max $5)
Disk size: default
Additional Security Group IDs:
Tags:
`
describeClassicYamlOutput = `availability_zones:
- us-east-1a
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ require (
github.com/onsi/ginkgo/v2 v2.13.0
github.com/onsi/gomega v1.29.0
github.com/openshift-online/ocm-common v0.0.0-20240129111424-ff8c6c11d909
github.com/openshift-online/ocm-sdk-go v0.1.416
github.com/openshift-online/ocm-sdk-go v0.1.418
github.com/pkg/errors v0.9.1
github.com/robfig/cron/v3 v3.0.1
github.com/sirupsen/logrus v1.9.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ github.com/onsi/gomega v1.29.0 h1:KIA/t2t5UBzoirT4H9tsML45GEbo3ouUnBHsCfD2tVg=
github.com/onsi/gomega v1.29.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ=
github.com/openshift-online/ocm-common v0.0.0-20240129111424-ff8c6c11d909 h1:WV67GNazQuGDaLX3kBbz0859NYPOQCsDCY5XUScF85M=
github.com/openshift-online/ocm-common v0.0.0-20240129111424-ff8c6c11d909/go.mod h1:7FaAb07S63RF4sFMLSLtQaJLvPdaRnhAT4dBLD8/5kM=
github.com/openshift-online/ocm-sdk-go v0.1.416 h1:V23RQyYI9xVWSqmbMLb59j8zQvevFlxj7Ku8Of9zTSo=
github.com/openshift-online/ocm-sdk-go v0.1.416/go.mod h1:CiAu2jwl3ITKOxkeV0Qnhzv4gs35AmpIzVABQLtcI2Y=
github.com/openshift-online/ocm-sdk-go v0.1.418 h1:UgMcx16YOS0cs6c0b0ZXbffnjciiuvAp2fE63tnLwLI=
github.com/openshift-online/ocm-sdk-go v0.1.418/go.mod h1:CiAu2jwl3ITKOxkeV0Qnhzv4gs35AmpIzVABQLtcI2Y=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down
4 changes: 3 additions & 1 deletion pkg/machinepool/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ var machinePoolOutputString = "\n" +
"Subnets: %s\n" +
"Spot instances: %s\n" +
"Disk size: %s\n" +
"Additional Security Group IDs: %s\n"
"Additional Security Group IDs: %s\n" +
"Tags: %s\n"

func machinePoolOutput(clusterId string, machinePool *cmv1.MachinePool) string {
return fmt.Sprintf(machinePoolOutputString,
Expand All @@ -56,6 +57,7 @@ func machinePoolOutput(clusterId string, machinePool *cmv1.MachinePool) string {
ocmOutput.PrintMachinePoolSpot(machinePool),
ocmOutput.PrintMachinePoolDiskSize(machinePool),
output.PrintStringSlice(machinePool.AWS().AdditionalSecurityGroupIds()),
ocmOutput.PrintUserAwsTags(machinePool.AWS().Tags()),
)
}

Expand Down
28 changes: 25 additions & 3 deletions pkg/machinepool/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var _ = Describe("Output", Ordered, func() {
out := fmt.Sprintf(machinePoolOutputString,
"test-mp", "test-cluster", "Yes", "0-0", "test-it", labelsOutput, taintsOutput,
"test-az", "test-subnet", ocmOutput.PrintMachinePoolSpot(machinePool),
ocmOutput.PrintMachinePoolDiskSize(machinePool), "")
ocmOutput.PrintMachinePoolDiskSize(machinePool), "", "")

result := machinePoolOutput("test-cluster", machinePool)
Expect(out).To(Equal(result))
Expand All @@ -56,7 +56,29 @@ var _ = Describe("Output", Ordered, func() {
out := fmt.Sprintf(machinePoolOutputString,
"test-mp", "test-cluster", "Yes", "0-0", "test-it", labelsOutput, taintsOutput,
"test-az", "test-subnet", ocmOutput.PrintMachinePoolSpot(machinePool),
ocmOutput.PrintMachinePoolDiskSize(machinePool), "123")
ocmOutput.PrintMachinePoolDiskSize(machinePool), "123", "")

result := machinePoolOutput("test-cluster", machinePool)
Expect(out).To(Equal(result))
})
It("machinepool output with aws tags", func() {
awsMachinePoolBuilder := cmv1.NewAWSMachinePool().Tags(map[string]string{
"test-tag": "test-value",
})
machinePoolBuilder := *cmv1.NewMachinePool().ID("test-mp").Autoscaling(cmv1.NewMachinePoolAutoscaling().
ID("test-as")).Replicas(4).InstanceType("test-it").
Labels(labels).Taints(taintsBuilder).AvailabilityZones("test-az").
Subnets("test-subnet").
AWS(awsMachinePoolBuilder)
machinePool, err := machinePoolBuilder.Build()
Expect(err).ToNot(HaveOccurred())
labelsOutput := ocmOutput.PrintLabels(labels)
taintsOutput := ocmOutput.PrintTaints([]*cmv1.Taint{taint})

out := fmt.Sprintf(machinePoolOutputString,
"test-mp", "test-cluster", "Yes", "0-0", "test-it", labelsOutput, taintsOutput,
"test-az", "test-subnet", ocmOutput.PrintMachinePoolSpot(machinePool),
ocmOutput.PrintMachinePoolDiskSize(machinePool), "", "test-tag=test-value")

result := machinePoolOutput("test-cluster", machinePool)
Expect(out).To(Equal(result))
Expand All @@ -73,7 +95,7 @@ var _ = Describe("Output", Ordered, func() {
out := fmt.Sprintf(machinePoolOutputString,
"test-mp2", "test-cluster", "No", "4", "test-it2", labelsOutput, taintsOutput,
"test-az2", "test-subnet2", ocmOutput.PrintMachinePoolSpot(machinePool),
ocmOutput.PrintMachinePoolDiskSize(machinePool), "")
ocmOutput.PrintMachinePoolDiskSize(machinePool), "", "")

result := machinePoolOutput("test-cluster", machinePool)
Expect(out).To(Equal(result))
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading