Skip to content

Commit 99f611a

Browse files
More work
1 parent 3e135c8 commit 99f611a

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

cmd/clusterctl/cmd/describe_cluster.go

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
3535
"k8s.io/apimachinery/pkg/util/duration"
3636
"k8s.io/apimachinery/pkg/util/sets"
37+
"k8s.io/utils/ptr"
3738
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
3839

3940
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
@@ -269,6 +270,14 @@ func addObjectRowV1Beta2(prefix string, tbl *tablewriter.Table, objectTree *tree
269270
// NOTE: The object name gets manipulated in order to improve readability.
270271
name := getRowName(obj)
271272

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+
272281
// Add the row representing the object that includes
273282
// - The row name with the tree view prefix.
274283
// - The object's available condition + counters
@@ -510,8 +519,37 @@ func newV1beta2RowDescriptor(obj ctrlclient.Object) v1beta2RowDescriptor {
510519
v := v1beta2RowDescriptor{}
511520
switch t := obj.(type) {
512521
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+
}
514545

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+
}
515553
case *clusterv1.MachineDeployment:
516554
md := obj.(*clusterv1.MachineDeployment)
517555
if md.Spec.Replicas != nil {

0 commit comments

Comments
 (0)