@@ -34,6 +34,7 @@ import (
34
34
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
35
35
"k8s.io/apimachinery/pkg/util/duration"
36
36
"k8s.io/apimachinery/pkg/util/sets"
37
+ "k8s.io/utils/ptr"
37
38
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
38
39
39
40
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
@@ -269,6 +270,14 @@ func addObjectRowV1Beta2(prefix string, tbl *tablewriter.Table, objectTree *tree
269
270
// NOTE: The object name gets manipulated in order to improve readability.
270
271
name := getRowName (obj )
271
272
273
+ // If we are going to should all conditions from this object, let's drop condition picked from the object line
274
+ if tree .IsShowConditionsObject (obj ) {
275
+ rowDescriptor .status = ""
276
+ rowDescriptor .reason = ""
277
+ rowDescriptor .age = ""
278
+ rowDescriptor .message = ""
279
+ }
280
+
272
281
// Add the row representing the object that includes
273
282
// - The row name with the tree view prefix.
274
283
// - The object's available condition + counters
@@ -510,8 +519,37 @@ func newV1beta2RowDescriptor(obj ctrlclient.Object) v1beta2RowDescriptor {
510
519
v := v1beta2RowDescriptor {}
511
520
switch t := obj .(type ) {
512
521
case * clusterv1.Cluster :
513
- fmt .Printf ("This is a cluster!" )
522
+ c := obj .(* clusterv1.Cluster )
523
+ if c .Status .V1Beta2 != nil {
524
+ cp := c .Status .V1Beta2 .ControlPlane
525
+ if cp == nil {
526
+ cp = & clusterv1.ClusterControlPlaneStatus {}
527
+ }
528
+ w := c .Status .V1Beta2 .Workers
529
+ if w == nil {
530
+ w = & clusterv1.WorkersStatus {}
531
+ }
532
+ if cp .DesiredReplicas != nil || w .DesiredReplicas != nil || cp .Replicas != nil || w .Replicas != nil {
533
+ v .replicas = fmt .Sprintf ("%d/%d" , ptr .Deref (cp .DesiredReplicas , 0 )+ ptr .Deref (w .DesiredReplicas , 0 ), ptr .Deref (cp .Replicas , 0 )+ ptr .Deref (w .Replicas , 0 ))
534
+ }
535
+ if cp .AvailableReplicas != nil || w .AvailableReplicas != nil {
536
+ v .availableCounters = fmt .Sprintf ("%d" , ptr .Deref (cp .AvailableReplicas , 0 )+ ptr .Deref (w .AvailableReplicas , 0 ))
537
+ }
538
+ if cp .ReadyReplicas != nil || w .ReadyReplicas != nil {
539
+ v .readyCounters = fmt .Sprintf ("%d" , ptr .Deref (cp .ReadyReplicas , 0 )+ ptr .Deref (w .ReadyReplicas , 0 ))
540
+ }
541
+ if cp .UpToDateReplicas != nil || w .UpToDateReplicas != nil {
542
+ v .upToDateCounters = fmt .Sprintf ("%d" , ptr .Deref (cp .UpToDateReplicas , 0 )+ ptr .Deref (w .UpToDateReplicas , 0 ))
543
+ }
544
+ }
514
545
546
+ if available := tree .GetAvailableV1Beta2Condition (obj ); available != nil {
547
+ availableColor , availableStatus , availableAge , availableReason , availableMessage := v1Beta2ConditionInfo (* available , true )
548
+ v .status = availableColor .Sprintf ("Available: %s" , availableStatus )
549
+ v .reason = availableColor .Sprint (availableReason )
550
+ v .age = availableColor .Sprint (availableAge )
551
+ v .message = availableColor .Sprint (availableMessage )
552
+ }
515
553
case * clusterv1.MachineDeployment :
516
554
md := obj .(* clusterv1.MachineDeployment )
517
555
if md .Spec .Replicas != nil {
0 commit comments