diff --git a/cmd/describe/machinepool/cmd.go b/cmd/describe/machinepool/cmd.go index a88f95754d..a1684f1c62 100644 --- a/cmd/describe/machinepool/cmd.go +++ b/cmd/describe/machinepool/cmd.go @@ -23,6 +23,7 @@ import ( cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1" "github.com/spf13/cobra" + "github.com/openshift/rosa/pkg/machinepool" "github.com/openshift/rosa/pkg/ocm" "github.com/openshift/rosa/pkg/output" "github.com/openshift/rosa/pkg/rosa" @@ -67,12 +68,11 @@ func run(cmd *cobra.Command, argv []string) { } func runWithRuntime(r *rosa.Runtime, cmd *cobra.Command, argv []string) error { - machinePool := args.machinePool // Allow the use also directly the machine pool id as positional parameter if len(argv) == 1 && !cmd.Flag("machinepool").Changed { - machinePool = argv[0] + args.machinePool = argv[0] } - if machinePool == "" { + if args.machinePool == "" { return fmt.Errorf("You need to specify a machine pool name") } clusterKey := r.GetClusterKey() @@ -83,9 +83,11 @@ func runWithRuntime(r *rosa.Runtime, cmd *cobra.Command, argv []string) error { } isHypershift := cluster.Hypershift().Enabled() + service := machinepool.NewMachinePoolService() + if isHypershift { - return describeNodePool(r, cluster, clusterKey, machinePool) + return service.DescribeNodePool(r, cluster, clusterKey, args.machinePool) } else { - return describeMachinePool(r, cluster, clusterKey, machinePool) + return service.DescribeMachinePool(r, cluster, clusterKey, args.machinePool) } } diff --git a/cmd/describe/machinepool/cmd_test.go b/cmd/describe/machinepool/cmd_test.go index 6f04238aa3..222d378d9f 100644 --- a/cmd/describe/machinepool/cmd_test.go +++ b/cmd/describe/machinepool/cmd_test.go @@ -176,7 +176,7 @@ var _ = Describe("Upgrade machine pool", func() { stdout, stderr, err := test.RunWithOutputCaptureAndArgv(runWithRuntime, testRuntime.RosaRuntime, Cmd, &[]string{nodePoolName}) Expect(err).ToNot(BeNil()) - Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("Machine pool '%s' not found", nodePoolName))) + Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("Node pool '%s' not found", nodePoolName))) Expect(stdout).To(BeEmpty()) Expect(stderr).To(BeEmpty()) }) @@ -187,7 +187,7 @@ var _ = Describe("Upgrade machine pool", func() { stdout, stderr, err := test.RunWithOutputCaptureAndArgv(runWithRuntime, testRuntime.RosaRuntime, Cmd, &[]string{}) Expect(err).ToNot(BeNil()) - Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("Machine pool '%s' not found", nodePoolName))) + Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("Node pool '%s' not found", nodePoolName))) Expect(stdout).To(BeEmpty()) Expect(stderr).To(BeEmpty()) }) diff --git a/cmd/describe/machinepool/machinepool.go b/cmd/describe/machinepool/machinepool.go deleted file mode 100644 index 09b85e5159..0000000000 --- a/cmd/describe/machinepool/machinepool.go +++ /dev/null @@ -1,57 +0,0 @@ -package machinepool - -import ( - "fmt" - - cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1" - - ocmOutput "github.com/openshift/rosa/pkg/ocm/output" - "github.com/openshift/rosa/pkg/output" - "github.com/openshift/rosa/pkg/rosa" -) - -func describeMachinePool(r *rosa.Runtime, cluster *cmv1.Cluster, clusterKey string, machinePoolID string) error { - r.Reporter.Debugf("Fetching machine pool '%s' for cluster '%s'", machinePoolID, clusterKey) - machinePool, exists, err := r.OCMClient.GetMachinePool(cluster.ID(), machinePoolID) - if err != nil { - return err - } - if !exists { - return fmt.Errorf("Machine pool '%s' not found", machinePoolID) - } - - if output.HasFlag() { - return output.Print(machinePool) - } - - // Prepare string - machinePoolOutput := fmt.Sprintf("\n"+ - "ID: %s\n"+ - "Cluster ID: %s\n"+ - "Autoscaling: %s\n"+ - "Replicas: %s\n"+ - "Instance type: %s\n"+ - "Labels: %s\n"+ - "Taints: %s\n"+ - "Availability zones: %s\n"+ - "Subnets: %s\n"+ - "Spot instances: %s\n"+ - "Disk size: %s\n"+ - "Security Group IDs: %s\n", - machinePool.ID(), - cluster.ID(), - ocmOutput.PrintMachinePoolAutoscaling(machinePool.Autoscaling()), - ocmOutput.PrintMachinePoolReplicas(machinePool.Autoscaling(), machinePool.Replicas()), - machinePool.InstanceType(), - ocmOutput.PrintLabels(machinePool.Labels()), - ocmOutput.PrintTaints(machinePool.Taints()), - output.PrintStringSlice(machinePool.AvailabilityZones()), - output.PrintStringSlice(machinePool.Subnets()), - ocmOutput.PrintMachinePoolSpot(machinePool), - ocmOutput.PrintMachinePoolDiskSize(machinePool), - output.PrintStringSlice(machinePool.AWS().AdditionalSecurityGroupIds()), - ) - fmt.Print(machinePoolOutput) - - return nil -} diff --git a/cmd/describe/machinepool/nodepool.go b/cmd/describe/machinepool/nodepool.go deleted file mode 100644 index a125279ac3..0000000000 --- a/cmd/describe/machinepool/nodepool.go +++ /dev/null @@ -1,117 +0,0 @@ -package machinepool - -import ( - "bytes" - "encoding/json" - "fmt" - - cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1" - - ocmOutput "github.com/openshift/rosa/pkg/ocm/output" - "github.com/openshift/rosa/pkg/output" - "github.com/openshift/rosa/pkg/rosa" -) - -func describeNodePool(r *rosa.Runtime, cluster *cmv1.Cluster, clusterKey string, nodePoolID string) error { - r.Reporter.Debugf("Fetching node pool '%s' for cluster '%s'", nodePoolID, clusterKey) - nodePool, exists, err := r.OCMClient.GetNodePool(cluster.ID(), nodePoolID) - if err != nil { - return err - } - if !exists { - return fmt.Errorf("Machine pool '%s' not found", nodePoolID) - } - - _, scheduledUpgrade, err := r.OCMClient.GetHypershiftNodePoolUpgrade(cluster.ID(), clusterKey, nodePoolID) - if err != nil { - return err - } - - if output.HasFlag() { - var formattedOutput map[string]interface{} - formattedOutput, err = formatNodePoolOutput(nodePool, scheduledUpgrade) - if err != nil { - return err - } - return output.Print(formattedOutput) - } - - // Prepare string - nodePoolOutput := fmt.Sprintf("\n"+ - "ID: %s\n"+ - "Cluster ID: %s\n"+ - "Autoscaling: %s\n"+ - "Desired replicas: %s\n"+ - "Current replicas: %s\n"+ - "Instance type: %s\n"+ - "Labels: %s\n"+ - "Tags: %s\n"+ - "Taints: %s\n"+ - "Availability zone: %s\n"+ - "Subnet: %s\n"+ - "Version: %s\n"+ - "Autorepair: %s\n"+ - "Tuning configs: %s\n"+ - "Additional security group IDs: %s\n"+ - "Node drain grace period: %s\n"+ - "Message: %s\n", - nodePool.ID(), - cluster.ID(), - ocmOutput.PrintNodePoolAutoscaling(nodePool.Autoscaling()), - ocmOutput.PrintNodePoolReplicas(nodePool.Autoscaling(), nodePool.Replicas()), - ocmOutput.PrintNodePoolCurrentReplicas(nodePool.Status()), - ocmOutput.PrintNodePoolInstanceType(nodePool.AWSNodePool()), - ocmOutput.PrintLabels(nodePool.Labels()), - ocmOutput.PrintUserAwsTags(nodePool.AWSNodePool().Tags()), - ocmOutput.PrintTaints(nodePool.Taints()), - nodePool.AvailabilityZone(), - nodePool.Subnet(), - ocmOutput.PrintNodePoolVersion(nodePool.Version()), - ocmOutput.PrintNodePoolAutorepair(nodePool.AutoRepair()), - ocmOutput.PrintNodePoolTuningConfigs(nodePool.TuningConfigs()), - ocmOutput.PrintNodePoolAdditionalSecurityGroups(nodePool.AWSNodePool()), - ocmOutput.PrintNodeDrainGracePeriod(nodePool.NodeDrainGracePeriod()), - ocmOutput.PrintNodePoolMessage(nodePool.Status()), - ) - - // Print scheduled upgrades if existing - if scheduledUpgrade != nil { - nodePoolOutput = fmt.Sprintf("%s"+ - "Scheduled upgrade: %s %s on %s\n", - nodePoolOutput, - scheduledUpgrade.State().Value(), - scheduledUpgrade.Version(), - scheduledUpgrade.NextRun().Format("2006-01-02 15:04 MST"), - ) - } - fmt.Print(nodePoolOutput) - - return nil -} - -func formatNodePoolOutput(nodePool *cmv1.NodePool, - scheduledUpgrade *cmv1.NodePoolUpgradePolicy) (map[string]interface{}, error) { - - var b bytes.Buffer - err := cmv1.MarshalNodePool(nodePool, &b) - if err != nil { - return nil, err - } - ret := make(map[string]interface{}) - err = json.Unmarshal(b.Bytes(), &ret) - if err != nil { - return nil, err - } - if scheduledUpgrade != nil && - scheduledUpgrade.State() != nil && - len(scheduledUpgrade.Version()) > 0 && - len(scheduledUpgrade.State().Value()) > 0 { - upgrade := make(map[string]interface{}) - upgrade["version"] = scheduledUpgrade.Version() - upgrade["state"] = scheduledUpgrade.State().Value() - upgrade["nextRun"] = scheduledUpgrade.NextRun().Format("2006-01-02 15:04 MST") - ret["scheduledUpgrade"] = upgrade - } - - return ret, nil -} diff --git a/pkg/machinepool/machinepool.go b/pkg/machinepool/machinepool.go new file mode 100644 index 0000000000..9ad2b6cb66 --- /dev/null +++ b/pkg/machinepool/machinepool.go @@ -0,0 +1,121 @@ +package machinepool + +import ( + "bytes" + "encoding/json" + "fmt" + + cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1" + + "github.com/openshift/rosa/pkg/output" + "github.com/openshift/rosa/pkg/rosa" +) + +var fetchMessage string = "Fetching %s '%s' for cluster '%s'" +var notFoundMessage string = "%s '%s' not found" + +//go:generate mockgen -source=machinepool.go -package=mocks -destination=machinepool_mock.go +type MachinePoolService interface { + DescribeMachinePool(*rosa.Runtime, *cmv1.Cluster, string, string) error + DescribeNodePool(*rosa.Runtime, *cmv1.Cluster, string, string) error +} + +type machinePool struct { +} + +var _ MachinePoolService = &machinePool{} + +func NewMachinePoolService() MachinePoolService { + return &machinePool{} +} + +func (m machinePool) DescribeMachinePool(r *rosa.Runtime, cluster *cmv1.Cluster, clusterKey string, + machinePoolId string) error { + r.Reporter.Debugf(fetchMessage, "machine pool", machinePoolId, clusterKey) + machinePool, exists, err := r.OCMClient.GetMachinePool(cluster.ID(), machinePoolId) + if err != nil { + return err + } + if !exists { + return fmt.Errorf(notFoundMessage, "Machine pool", machinePoolId) + } + + if output.HasFlag() { + return output.Print(machinePool) + } + + fmt.Print(machinePoolOutput(cluster.ID(), machinePool)) + + return nil +} + +func (m machinePool) DescribeNodePool(r *rosa.Runtime, cluster *cmv1.Cluster, clusterKey string, + nodePoolId string) error { + r.Reporter.Debugf(fetchMessage, "node pool", nodePoolId, clusterKey) + nodePool, exists, err := r.OCMClient.GetNodePool(cluster.ID(), nodePoolId) + if err != nil { + return err + } + if !exists { + return fmt.Errorf(notFoundMessage, "Node pool", nodePoolId) + } + + _, scheduledUpgrade, err := r.OCMClient.GetHypershiftNodePoolUpgrade(cluster.ID(), clusterKey, nodePoolId) + if err != nil { + return err + } + + if output.HasFlag() { + var formattedOutput map[string]interface{} + formattedOutput, err = formatNodePoolOutput(nodePool, scheduledUpgrade) + if err != nil { + return err + } + return output.Print(formattedOutput) + } + + // Attach and print scheduledUpgrades if they exist, otherwise, print output normally + fmt.Print(appendUpgradesIfExist(scheduledUpgrade, nodePoolOutput(cluster.ID(), nodePool))) + + return nil +} + +func formatNodePoolOutput(nodePool *cmv1.NodePool, + scheduledUpgrade *cmv1.NodePoolUpgradePolicy) (map[string]interface{}, error) { + + var b bytes.Buffer + err := cmv1.MarshalNodePool(nodePool, &b) + if err != nil { + return nil, err + } + ret := make(map[string]interface{}) + err = json.Unmarshal(b.Bytes(), &ret) + if err != nil { + return nil, err + } + if scheduledUpgrade != nil && + scheduledUpgrade.State() != nil && + len(scheduledUpgrade.Version()) > 0 && + len(scheduledUpgrade.State().Value()) > 0 { + upgrade := make(map[string]interface{}) + upgrade["version"] = scheduledUpgrade.Version() + upgrade["state"] = scheduledUpgrade.State().Value() + upgrade["nextRun"] = scheduledUpgrade.NextRun().Format("2006-01-02 15:04 MST") + ret["scheduledUpgrade"] = upgrade + } + + return ret, nil +} + +func appendUpgradesIfExist(scheduledUpgrade *cmv1.NodePoolUpgradePolicy, output string) string { + if scheduledUpgrade != nil { + return fmt.Sprintf("%s"+ + "Scheduled upgrade: %s %s on %s\n", + output, + scheduledUpgrade.State().Value(), + scheduledUpgrade.Version(), + scheduledUpgrade.NextRun().Format("2006-01-02 15:04 MST"), + ) + } + return output +} diff --git a/pkg/machinepool/machinepool_suite_test.go b/pkg/machinepool/machinepool_suite_test.go new file mode 100644 index 0000000000..def2c8a470 --- /dev/null +++ b/pkg/machinepool/machinepool_suite_test.go @@ -0,0 +1,13 @@ +package machinepool + +import ( + "testing" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +func TestDescribeUpgrade(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Machinepool/nodepool suite") +} diff --git a/pkg/machinepool/machinepool_test.go b/pkg/machinepool/machinepool_test.go new file mode 100644 index 0000000000..4ed301b266 --- /dev/null +++ b/pkg/machinepool/machinepool_test.go @@ -0,0 +1,69 @@ +package machinepool + +import ( + "fmt" + "time" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1" +) + +var policyBuilder cmv1.NodePoolUpgradePolicyBuilder +var date time.Time + +var _ = Describe("Machinepool and nodepool", func() { + Context("Machinepools", func() { + + }) + Context("Nodepools", Ordered, func() { + BeforeAll(func() { + location, err := time.LoadLocation("America/New_York") + Expect(err).ToNot(HaveOccurred()) + date = time.Date(2024, time.April, 2, 2, 2, 0, 0, location) + policyBuilder = *cmv1.NewNodePoolUpgradePolicy().ID("test-policy").Version("1"). + ClusterID("test-cluster").State(cmv1.NewUpgradePolicyState().ID("test-state"). + Value(cmv1.UpgradePolicyStateValueScheduled)). + NextRun(date) + }) + It("Test appendUpgradesIfExist", func() { + policy, err := policyBuilder.Build() + Expect(err).ToNot(HaveOccurred()) + out := appendUpgradesIfExist(policy, "test\n") + Expect(out).To(Equal(fmt.Sprintf("test\nScheduled upgrade: %s %s on %s\n", + cmv1.UpgradePolicyStateValueScheduled, "1", date.Format("2006-01-02 15:04 MST")))) + }) + It("Test appendUpgradesIfExist nil schedule", func() { + out := appendUpgradesIfExist(nil, "test\n") + Expect(out).To(Equal("test\n")) + }) + It("Test func formatNodePoolOutput", func() { + policy, err := policyBuilder.Build() + Expect(err).ToNot(HaveOccurred()) + nodePool, err := cmv1.NewNodePool().ID("test-np").Version(cmv1.NewVersion().ID("1")). + Subnet("test-subnet").Replicas(4).AutoRepair(true).Build() + Expect(err).ToNot(HaveOccurred()) + + out, err := formatNodePoolOutput(nodePool, policy) + Expect(err).ToNot(HaveOccurred()) + expectedOutput := make(map[string]interface{}) + upgrade := make(map[string]interface{}) + upgrade["version"] = policy.Version() + upgrade["state"] = policy.State().Value() + upgrade["nextRun"] = policy.NextRun().Format("2006-01-02 15:04 MST") + expectedOutput["subnet"] = "test-subnet" + + expectedOutput["kind"] = "NodePool" + expectedOutput["id"] = "test-np" + expectedOutput["replicas"] = 4.0 + version := make(map[string]interface{}) + version["kind"] = "Version" + version["id"] = "1" + expectedOutput["auto_repair"] = true + expectedOutput["version"] = version + expectedOutput["scheduledUpgrade"] = upgrade + fmt.Println(out) + Expect(fmt.Sprint(out)).To(Equal(fmt.Sprint(expectedOutput))) + }) + }) +}) diff --git a/pkg/machinepool/output.go b/pkg/machinepool/output.go new file mode 100644 index 0000000000..54d6751b06 --- /dev/null +++ b/pkg/machinepool/output.go @@ -0,0 +1,82 @@ +package machinepool + +import ( + "fmt" + + cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1" + + ocmOutput "github.com/openshift/rosa/pkg/ocm/output" + "github.com/openshift/rosa/pkg/output" +) + +var nodePoolOutputString string = "\n" + + "ID: %s\n" + + "Cluster ID: %s\n" + + "Autoscaling: %s\n" + + "Desired replicas: %s\n" + + "Current replicas: %s\n" + + "Instance type: %s\n" + + "Labels: %s\n" + + "Tags: %s\n" + + "Taints: %s\n" + + "Availability zone: %s\n" + + "Subnet: %s\n" + + "Version: %s\n" + + "Autorepair: %s\n" + + "Tuning configs: %s\n" + + "Additional security group IDs: %s\n" + + "Node drain grace period: %s\n" + + "Message: %s\n" + +var machinePoolOutputString = "\n" + + "ID: %s\n" + + "Cluster ID: %s\n" + + "Autoscaling: %s\n" + + "Replicas: %s\n" + + "Instance type: %s\n" + + "Labels: %s\n" + + "Taints: %s\n" + + "Availability zones: %s\n" + + "Subnets: %s\n" + + "Spot instances: %s\n" + + "Disk size: %s\n" + + "Security Group IDs: %s\n" + +func machinePoolOutput(clusterId string, machinePool *cmv1.MachinePool) string { + return fmt.Sprintf(machinePoolOutputString, + machinePool.ID(), + clusterId, + ocmOutput.PrintMachinePoolAutoscaling(machinePool.Autoscaling()), + ocmOutput.PrintMachinePoolReplicas(machinePool.Autoscaling(), machinePool.Replicas()), + machinePool.InstanceType(), + ocmOutput.PrintLabels(machinePool.Labels()), + ocmOutput.PrintTaints(machinePool.Taints()), + output.PrintStringSlice(machinePool.AvailabilityZones()), + output.PrintStringSlice(machinePool.Subnets()), + ocmOutput.PrintMachinePoolSpot(machinePool), + ocmOutput.PrintMachinePoolDiskSize(machinePool), + output.PrintStringSlice(machinePool.AWS().AdditionalSecurityGroupIds()), + ) +} + +func nodePoolOutput(clusterId string, nodePool *cmv1.NodePool) string { + return fmt.Sprintf(nodePoolOutputString, + nodePool.ID(), + clusterId, + ocmOutput.PrintNodePoolAutoscaling(nodePool.Autoscaling()), + ocmOutput.PrintNodePoolReplicas(nodePool.Autoscaling(), nodePool.Replicas()), + ocmOutput.PrintNodePoolCurrentReplicas(nodePool.Status()), + ocmOutput.PrintNodePoolInstanceType(nodePool.AWSNodePool()), + ocmOutput.PrintLabels(nodePool.Labels()), + ocmOutput.PrintUserAwsTags(nodePool.AWSNodePool().Tags()), + ocmOutput.PrintTaints(nodePool.Taints()), + nodePool.AvailabilityZone(), + nodePool.Subnet(), + ocmOutput.PrintNodePoolVersion(nodePool.Version()), + ocmOutput.PrintNodePoolAutorepair(nodePool.AutoRepair()), + ocmOutput.PrintNodePoolTuningConfigs(nodePool.TuningConfigs()), + ocmOutput.PrintNodePoolAdditionalSecurityGroups(nodePool.AWSNodePool()), + ocmOutput.PrintNodeDrainGracePeriod(nodePool.NodeDrainGracePeriod()), + ocmOutput.PrintNodePoolMessage(nodePool.Status()), + ) +} diff --git a/pkg/machinepool/output_test.go b/pkg/machinepool/output_test.go new file mode 100644 index 0000000000..f0073f075e --- /dev/null +++ b/pkg/machinepool/output_test.go @@ -0,0 +1,97 @@ +package machinepool + +import ( + "fmt" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1" + + ocmOutput "github.com/openshift/rosa/pkg/ocm/output" +) + +var taintsBuilder *cmv1.TaintBuilder +var labels map[string]string +var taint *cmv1.Taint + +var _ = Describe("Output", Ordered, func() { + Context("Test output for machinepools and nodepools", func() { + BeforeAll(func() { + var err error + taintsBuilder = cmv1.NewTaint().Value("test-taint").Value("test-value") + taint, err = taintsBuilder.Build() + labels = map[string]string{"test": "test"} + Expect(err).ToNot(HaveOccurred()) + }) + It("machinepool output with autoscaling", func() { + 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") + 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), "") + + result := machinePoolOutput("test-cluster", machinePool) + Expect(out).To(Equal(result)) + }) + It("machinepool output without autoscaling", func() { + machinePoolBuilder := *cmv1.NewMachinePool().ID("test-mp2"). + Replicas(4).InstanceType("test-it2").Labels(labels). + Taints(taintsBuilder).AvailabilityZones("test-az2").Subnets("test-subnet2") + machinePool, err := machinePoolBuilder.Build() + Expect(err).ToNot(HaveOccurred()) + labelsOutput := ocmOutput.PrintLabels(labels) + taintsOutput := ocmOutput.PrintTaints([]*cmv1.Taint{taint}) + + out := fmt.Sprintf(machinePoolOutputString, + "test-mp2", "test-cluster", "No", "4", "test-it2", labelsOutput, taintsOutput, + "test-az2", "test-subnet2", ocmOutput.PrintMachinePoolSpot(machinePool), + ocmOutput.PrintMachinePoolDiskSize(machinePool), "") + + result := machinePoolOutput("test-cluster", machinePool) + Expect(out).To(Equal(result)) + }) + It("nodepool output with autoscaling", func() { + nodePoolBuilder := *cmv1.NewNodePool().ID("test-mp").Autoscaling(cmv1.NewNodePoolAutoscaling(). + ID("test-as").MinReplica(2).MaxReplica(8)).Replicas(4). + AvailabilityZone("test-az").Subnet("test-subnets").Version(cmv1.NewVersion(). + ID("1")).AutoRepair(false).TuningConfigs("test-tc").Labels(labels). + Taints(taintsBuilder) + nodePool, err := nodePoolBuilder.Build() + Expect(err).ToNot(HaveOccurred()) + labelsOutput := ocmOutput.PrintLabels(labels) + taintsOutput := ocmOutput.PrintTaints([]*cmv1.Taint{taint}) + + out := fmt.Sprintf(nodePoolOutputString, + "test-mp", "test-cluster", "Yes", "2-8", "", "", labelsOutput, "", taintsOutput, "test-az", + "test-subnets", "1", "No", "test-tc", "", "", "") + + result := nodePoolOutput("test-cluster", nodePool) + Expect(out).To(Equal(result)) + }) + It("nodepool output without autoscaling", func() { + nodePoolBuilder := *cmv1.NewNodePool().ID("test-mp").Replicas(4). + AvailabilityZone("test-az").Subnet("test-subnets").Version(cmv1.NewVersion(). + ID("1")).AutoRepair(false).TuningConfigs("test-tc"). + Labels(labels).Taints(taintsBuilder) + nodePool, err := nodePoolBuilder.Build() + Expect(err).ToNot(HaveOccurred()) + labelsOutput := ocmOutput.PrintLabels(labels) + taintsOutput := ocmOutput.PrintTaints([]*cmv1.Taint{taint}) + + out := fmt.Sprintf(nodePoolOutputString, + "test-mp", "test-cluster", "No", "4", "", "", labelsOutput, "", taintsOutput, "test-az", + "test-subnets", "1", "No", "test-tc", "", "", "") + + result := nodePoolOutput("test-cluster", nodePool) + Expect(out).To(Equal(result)) + }) + }) +})