From 15baa8788dfdec83efeb157c9696ce84832e25f5 Mon Sep 17 00:00:00 2001 From: Hasan Turken Date: Sat, 3 Aug 2024 01:01:34 +0300 Subject: [PATCH] CTP list: show Healthy columns and read message from status Signed-off-by: Hasan Turken --- cmd/up/controlplane/controlplane.go | 6 +++--- internal/controlplane/controlplane.go | 2 +- internal/controlplane/space/space.go | 4 +++- internal/controlplane/space/space_test.go | 24 ++++++++++++----------- internal/resources/controlplane.go | 10 +++++++--- 5 files changed, 27 insertions(+), 19 deletions(-) diff --git a/cmd/up/controlplane/controlplane.go b/cmd/up/controlplane/controlplane.go index 7c25138d..4a74d05d 100644 --- a/cmd/up/controlplane/controlplane.go +++ b/cmd/up/controlplane/controlplane.go @@ -38,7 +38,7 @@ import ( ) var ( - spacefieldNames = []string{"GROUP", "NAME", "CROSSPLANE", "SYNCED", "READY", "MESSAGE", "AGE"} + spacefieldNames = []string{"GROUP", "NAME", "CROSSPLANE", "READY", "HEALTHY", "MESSAGE", "AGE"} ) // BeforeReset is the first hook to run. @@ -142,9 +142,9 @@ func extractSpaceFields(obj any) []string { ctp.GetNamespace(), ctp.GetName(), v, - string(ctp.GetCondition(xpcommonv1.TypeSynced).Status), string(ctp.GetCondition(xpcommonv1.TypeReady).Status), - ctp.Annotations["internal.spaces.upbound.io/message"], + string(ctp.GetCondition(spacesv1beta1.ConditionTypeHealthy).Status), + ctp.Status.Message, formatAge(ptr.To(time.Since(ctp.CreationTimestamp.Time))), } } diff --git a/internal/controlplane/controlplane.go b/internal/controlplane/controlplane.go index 4dee1cb2..b633654b 100644 --- a/internal/controlplane/controlplane.go +++ b/internal/controlplane/controlplane.go @@ -26,8 +26,8 @@ type Response struct { Group string Name string CrossplaneVersion string - Synced string Ready string + Healthy string Message string Age *time.Duration diff --git a/internal/controlplane/space/space.go b/internal/controlplane/space/space.go index 3f265b98..fbb3778d 100644 --- a/internal/controlplane/space/space.go +++ b/internal/controlplane/space/space.go @@ -18,6 +18,8 @@ import ( "context" "fmt" + "github.com/upbound/up-sdk-go/apis/spaces/v1beta1" + corev1 "k8s.io/api/core/v1" kerrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -151,8 +153,8 @@ func convert(ctp *resources.ControlPlane) *controlplane.Response { Group: ctp.GetNamespace(), Name: ctp.GetName(), CrossplaneVersion: ctp.GetCrossplaneVersion(), - Synced: string(ctp.GetCondition(xpcommonv1.TypeSynced).Status), Ready: string(ctp.GetCondition(xpcommonv1.TypeReady).Status), + Healthy: string(ctp.GetCondition(v1beta1.ConditionTypeHealthy).Status), Message: ctp.GetMessage(), Age: ctp.GetAge(), Cfg: "", diff --git a/internal/controlplane/space/space_test.go b/internal/controlplane/space/space_test.go index 51f7c676..52d5afcb 100644 --- a/internal/controlplane/space/space_test.go +++ b/internal/controlplane/space/space_test.go @@ -19,6 +19,8 @@ import ( "errors" "testing" + spacesv1beta1 "github.com/upbound/up-sdk-go/apis/spaces/v1beta1" + "github.com/google/go-cmp/cmp" kerrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -427,9 +429,9 @@ func TestConvert(t *testing.T) { Name: "kubeconfig-ctp1", Namespace: "default", }) - c.SetConditions([]xpcommonv1.Condition{xpcommonv1.ReconcileSuccess()}...) c.SetConditions([]xpcommonv1.Condition{xpcommonv1.Available()}...) - c.SetAnnotations(map[string]string{"internal.spaces.upbound.io/message": ""}) + c.SetConditions(spacesv1beta1.Healthy()) + c.SetMessage("") return c }(), @@ -439,8 +441,8 @@ func TestConvert(t *testing.T) { Name: "ctp1", ID: "mxp1", Group: "default", - Synced: "True", Ready: "True", + Healthy: "True", ConnName: "kubeconfig-ctp1", Message: "", }, @@ -458,9 +460,9 @@ func TestConvert(t *testing.T) { Name: "kubeconfig-ctp1", Namespace: "default", }) - c.SetConditions(xpcommonv1.ReconcileSuccess()) c.SetConditions(xpcommonv1.Creating().WithMessage("something")) - c.SetAnnotations(map[string]string{"internal.spaces.upbound.io/message": "creating..."}) + c.SetConditions(spacesv1beta1.Healthy()) + c.SetMessage("creating...") return c }(), @@ -470,8 +472,8 @@ func TestConvert(t *testing.T) { Name: "ctp1", ID: "mxp1", Group: "default", - Synced: "True", Ready: "False", + Healthy: "True", Message: "creating...", ConnName: "kubeconfig-ctp1", }, @@ -484,18 +486,18 @@ func TestConvert(t *testing.T) { c := &resources.ControlPlane{} c.SetName("ctp1") c.SetControlPlaneID("mxp1") - c.SetConditions(xpcommonv1.ReconcileSuccess()) c.SetConditions([]xpcommonv1.Condition{xpcommonv1.Available()}...) + c.SetConditions(spacesv1beta1.Healthy()) return c }(), }, want: want{ resp: &controlplane.Response{ - Name: "ctp1", - ID: "mxp1", - Synced: "True", - Ready: "True", + Name: "ctp1", + ID: "mxp1", + Ready: "True", + Healthy: "True", }, }, }, diff --git a/internal/resources/controlplane.go b/internal/resources/controlplane.go index 62497a71..33c0f75d 100644 --- a/internal/resources/controlplane.go +++ b/internal/resources/controlplane.go @@ -98,11 +98,15 @@ func (c *ControlPlane) GetCrossplaneVersion() string { } func (c *ControlPlane) GetMessage() string { - var ann map[string]string - if err := fieldpath.Pave(c.Object).GetValueInto("metadata.annotations", &ann); err != nil { + msg, err := fieldpath.Pave(c.Object).GetString("status.message") + if err != nil { return "" } - return ann["internal.spaces.upbound.io/message"] + return msg +} + +func (c *ControlPlane) SetMessage(msg string) { + _ = fieldpath.Pave(c.Object).SetString("status.message", msg) } func (c *ControlPlane) GetAge() *time.Duration {