Skip to content

Commit

Permalink
Merge pull request #595 from turkenh/ctp-columns
Browse files Browse the repository at this point in the history
Show healthy column and read message from status for CTP list/get commands
  • Loading branch information
adamwg authored Aug 6, 2024
2 parents e9489b3 + 15baa87 commit e884e8f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 19 deletions.
6 changes: 3 additions & 3 deletions cmd/up/controlplane/controlplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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))),
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/controlplane/controlplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ type Response struct {
Group string
Name string
CrossplaneVersion string
Synced string
Ready string
Healthy string
Message string
Age *time.Duration

Expand Down
4 changes: 3 additions & 1 deletion internal/controlplane/space/space.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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: "",
Expand Down
24 changes: 13 additions & 11 deletions internal/controlplane/space/space_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}(),
Expand All @@ -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: "",
},
Expand All @@ -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
}(),
Expand All @@ -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",
},
Expand All @@ -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",
},
},
},
Expand Down
10 changes: 7 additions & 3 deletions internal/resources/controlplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e884e8f

Please sign in to comment.