@@ -1031,9 +1031,7 @@ func (m *machinePool) CreateNodePools(r *rosa.Runtime, cmd *cobra.Command, clust
10311031 return nil
10321032}
10331033
1034- // ListMachinePools lists all machinepools (or, nodepools if hypershift) in a cluster
10351034func (m * machinePool ) ListMachinePools (r * rosa.Runtime , clusterKey string , cluster * cmv1.Cluster , args ListMachinePoolArgs ) error {
1036- // Load any existing machine pools for this cluster
10371035 r .Reporter .Debugf ("Loading machine pools for cluster '%s'" , clusterKey )
10381036 isHypershift := cluster .Hypershift ().Enabled ()
10391037 var err error
@@ -1058,49 +1056,44 @@ func (m *machinePool) ListMachinePools(r *rosa.Runtime, clusterKey string, clust
10581056 return output .Print (machinePools )
10591057 }
10601058
1061- // Create the writer that will be used to print the tabulated results:
10621059 writer := tabwriter .NewWriter (os .Stdout , 0 , 0 , 2 , ' ' , 0 )
10631060
1064- // Get table as string first (hunterkepley's suggestion - less invasive approach)
1065- var tableString string
1061+ var headers []string
1062+ var tableData [][]string
1063+
10661064 if isHypershift {
1067- tableString = getNodePoolsString (nodePools )
1065+ headers , tableData = getNodePoolsData (nodePools )
10681066 } else {
1069- tableString = getMachinePoolsString (r , machinePools , args )
1067+ headers , tableData = getMachinePoolsData (r , machinePools , args )
10701068 }
10711069
1072- // Parse the string output into headers and data
1073- headers , tableData := parseTableString (tableString )
1074-
1075- // Only hide empty columns if the flag is set
10761070 if output .ShouldHideEmptyColumns () {
1077- // Find which columns are special (controlled by flags)
1078- specialColumns := make (map [int ]bool )
10791071 if ! isHypershift {
1072+ specialColumns := make (map [int ]bool )
10801073 for i , header := range headers {
10811074 if (header == "AZ TYPE" && (args .ShowAZType || args .ShowAll )) ||
10821075 (header == "WIN-LI ENABLED" && (args .ShowWindowsLI || args .ShowAll )) ||
10831076 (header == "DEDICATED HOST" && (args .ShowDedicated || args .ShowAll )) {
10841077 specialColumns [i ] = true
10851078 }
10861079 }
1080+ headers , tableData = output .FilterColumnsWithConditions (headers , tableData , specialColumns )
1081+ tableData = append ([][]string {headers }, tableData ... )
1082+ } else {
1083+ tableData = output .RemoveEmptyColumns (headers , tableData )
10871084 }
1088-
1089- // Remove empty columns but preserve special columns when their flags are set
1090- headers , tableData = output .FilterColumnsWithConditions (headers , tableData , specialColumns )
1085+ } else {
1086+ tableData = append ([][]string {headers }, tableData ... )
10911087 }
10921088
1093- fullTableData := [][]string {headers }
1094- fullTableData = append (fullTableData , tableData ... )
1095- output .BuildTable (writer , "\t " , fullTableData )
1089+ output .BuildTable (writer , "\t " , tableData )
10961090
10971091 if err := writer .Flush (); err != nil {
10981092 return err
10991093 }
11001094 return nil
11011095}
11021096
1103- // DescribeMachinePool describes either a machinepool, or, a nodepool (if hypershift)
11041097func (m * machinePool ) DescribeMachinePool (r * rosa.Runtime , cluster * cmv1.Cluster , clusterKey string ,
11051098 machinePoolId string ) error {
11061099 if cluster .Hypershift ().Enabled () {
@@ -1265,50 +1258,6 @@ func appendUpgradesIfExist(scheduledUpgrade *cmv1.NodePoolUpgradePolicy, output
12651258 return output
12661259}
12671260
1268- // parseTableString parses a tab-delimited string into headers and table data
1269- // This implements hunterkepley's suggestion to parse string output
1270- func parseTableString (tableString string ) ([]string , [][]string ) {
1271- lines := strings .Split (strings .TrimSpace (tableString ), "\n " )
1272- if len (lines ) == 0 {
1273- return nil , nil
1274- }
1275-
1276- // First line is headers
1277- headers := strings .Split (lines [0 ], "\t " )
1278-
1279- // Rest are data rows
1280- var tableData [][]string
1281- for i := 1 ; i < len (lines ); i ++ {
1282- if lines [i ] != "" {
1283- row := strings .Split (lines [i ], "\t " )
1284- tableData = append (tableData , row )
1285- }
1286- }
1287-
1288- return headers , tableData
1289- }
1290-
1291- // getMachinePoolsString returns machine pools as a formatted string
1292- func getMachinePoolsString (
1293- runtime * rosa.Runtime ,
1294- machinePools []* cmv1.MachinePool ,
1295- args ListMachinePoolArgs ,
1296- ) string {
1297- headers , tableData := getMachinePoolsData (runtime , machinePools , args )
1298-
1299- // Build string output
1300- var result strings.Builder
1301- result .WriteString (strings .Join (headers , "\t " ))
1302- result .WriteString ("\n " )
1303-
1304- for _ , row := range tableData {
1305- result .WriteString (strings .Join (row , "\t " ))
1306- result .WriteString ("\n " )
1307- }
1308-
1309- return result .String ()
1310- }
1311-
13121261func getMachinePoolsData (
13131262 runtime * rosa.Runtime ,
13141263 machinePools []* cmv1.MachinePool ,
@@ -1369,23 +1318,6 @@ func getMachinePoolsData(
13691318 return headers , tableData
13701319}
13711320
1372- // getNodePoolsString returns node pools as a formatted string
1373- func getNodePoolsString (nodePools []* cmv1.NodePool ) string {
1374- headers , tableData := getNodePoolsData (nodePools )
1375-
1376- // Build string output
1377- var result strings.Builder
1378- result .WriteString (strings .Join (headers , "\t " ))
1379- result .WriteString ("\n " )
1380-
1381- for _ , row := range tableData {
1382- result .WriteString (strings .Join (row , "\t " ))
1383- result .WriteString ("\n " )
1384- }
1385-
1386- return result .String ()
1387- }
1388-
13891321func getNodePoolsData (nodePools []* cmv1.NodePool ) ([]string , [][]string ) {
13901322 headers := []string {"ID" , "AUTOSCALING" , "REPLICAS" , "INSTANCE TYPE" , "LABELS" , "TAINTS" ,
13911323 "AVAILABILITY ZONE" , "SUBNET" , "DISK SIZE" , "VERSION" , "AUTOREPAIR" }
0 commit comments