diff --git a/cmd/ocm/list/machinepool/cmd.go b/cmd/ocm/list/machinepool/cmd.go index 760f14c7..e0aabf6b 100644 --- a/cmd/ocm/list/machinepool/cmd.go +++ b/cmd/ocm/list/machinepool/cmd.go @@ -98,10 +98,10 @@ func run(cmd *cobra.Command, argv []string) error { // Create the writer that will be used to print the tabulated results: writer := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0) - fmt.Fprintf(writer, "ID\tAUTOSCALING\tREPLICAS\tINSTANCE TYPE\tLABELS\t\tTAINTS\t\tAVAILABILITY ZONES\n") + fmt.Fprintf(writer, "ID\tAUTOSCALING\tREPLICAS\tINSTANCE TYPE\tLABELS\t\tTAINTS\t\tAVAILABILITY ZONES\tSG IDs\n") for _, machinePool := range machinePools { - fmt.Fprintf(writer, "%s\t%s\t%s\t%s\t%s\t\t%s\t\t%s\n", + fmt.Fprintf(writer, "%s\t%s\t%s\t%s\t%s\t\t%s\t\t%s\t%s\n", machinePool.ID(), printAutoscaling(machinePool.Autoscaling()), printReplicas(machinePool.Autoscaling(), machinePool.Replicas()), @@ -109,6 +109,7 @@ func run(cmd *cobra.Command, argv []string) error { printLabels(machinePool.Labels()), printTaints(machinePool.Taints()), printAZ(machinePool.AvailabilityZones()), + printAdditionalSecurityGroups(machinePool.AWS().AdditionalSecurityGroupIds()), ) } writer.Flush() @@ -132,6 +133,13 @@ func printReplicas(autoscaling *cmv1.MachinePoolAutoscaling, replicas int) strin return fmt.Sprintf("%d", replicas) } +func printAdditionalSecurityGroups(securityGroups []string) string { + if len(securityGroups) == 0 { + return "" + } + return strings.Join(securityGroups, ", ") +} + func printAZ(az []string) string { if len(az) == 0 { return "" diff --git a/pkg/cluster/describe.go b/pkg/cluster/describe.go index d2d03422..2fa10638 100644 --- a/pkg/cluster/describe.go +++ b/pkg/cluster/describe.go @@ -18,6 +18,7 @@ package cluster import ( "fmt" + "strings" "time" sdk "github.com/openshift-online/ocm-sdk-go" @@ -109,16 +110,6 @@ func PrintClusterDescription(connection *sdk.Connection, cluster *cmv1.Cluster) shard = shardPath.Body().HiveConfig().Server() } - var computesStr string - if cluster.Nodes().AutoscaleCompute() != nil { - computesStr = fmt.Sprintf("%d-%d (Autoscaled)", - cluster.Nodes().AutoscaleCompute().MinReplicas(), - cluster.Nodes().AutoscaleCompute().MaxReplicas(), - ) - } else { - computesStr = fmt.Sprintf("%d", cluster.Nodes().Compute()) - } - clusterAdminEnabled := false if cluster.CCS().Enabled() { clusterAdminEnabled = true @@ -189,12 +180,22 @@ func PrintClusterDescription(connection *sdk.Connection, cluster *cmv1.Cluster) ) } + var computesStr string + if cluster.Nodes().AutoscaleCompute() != nil { + computesStr = fmt.Sprintf("%d-%d (Autoscaled)", + cluster.Nodes().AutoscaleCompute().MinReplicas(), + cluster.Nodes().AutoscaleCompute().MaxReplicas(), + ) + } else { + computesStr = fmt.Sprintf("%d", cluster.Nodes().Compute()) + } + fmt.Printf("API URL: %s\n"+ "API Listening: %s\n"+ "Console URL: %s\n"+ - "Masters: %d\n"+ - "Infra: %d\n"+ - "Computes: %s\n"+ + "Control Plane:\n%s\n"+ + "Infra:\n%s\n"+ + "Compute:\n%s\n"+ "Product: %s\n"+ "Subscription type: %s\n"+ "Provider: %s\n"+ @@ -217,9 +218,9 @@ func PrintClusterDescription(connection *sdk.Connection, cluster *cmv1.Cluster) apiURL, apiListening, cluster.Console().URL(), - cluster.Nodes().Master(), - cluster.Nodes().Infra(), - computesStr, + printNodeInfo(fmt.Sprintf("%d", cluster.Nodes().Master()), cluster.AWS().AdditionalControlPlaneSecurityGroupIds()), + printNodeInfo(fmt.Sprintf("%d", cluster.Nodes().Infra()), cluster.AWS().AdditionalInfraSecurityGroupIds()), + printNodeInfo(computesStr, cluster.AWS().AdditionalComputeSecurityGroupIds()), cluster.Product().ID(), cluster.BillingModel(), cluster.CloudProvider().ID(), @@ -294,6 +295,15 @@ func PrintClusterDescription(connection *sdk.Connection, cluster *cmv1.Cluster) return nil } +func printNodeInfo(replicasInfo string, securityGroups []string) string { + nodeStr := "" + nodeStr += fmt.Sprintf("\tReplicas: %s", replicasInfo) + if len(securityGroups) > 0 { + nodeStr += fmt.Sprintf("\n\tAWS Additional Security Group IDs: %s", strings.Join(securityGroups, ", ")) + } + return nodeStr +} + // findHyperShiftMgmtSvcClusters returns the name of a HyperShift cluster's management and service clusters. // It essentially ignores error as these endpoint is behind specific permissions by returning empty strings when any // errors are encountered, which results in them not being printed in the output.