From 4218314653de2b94491dc925e2f8b81559eb7372 Mon Sep 17 00:00:00 2001 From: Darren Shepherd Date: Fri, 14 Feb 2020 16:20:04 -0700 Subject: [PATCH] Add state fields to metadata --- pkg/server/resources/common/formatter.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pkg/server/resources/common/formatter.go b/pkg/server/resources/common/formatter.go index 72845c5..a2c3b19 100644 --- a/pkg/server/resources/common/formatter.go +++ b/pkg/server/resources/common/formatter.go @@ -1,11 +1,16 @@ package common import ( + "strings" + "github.com/rancher/steve/pkg/accesscontrol" "github.com/rancher/steve/pkg/schema" "github.com/rancher/steve/pkg/schemaserver/types" "github.com/rancher/steve/pkg/server/store/proxy" + "github.com/rancher/wrangler/pkg/data" + "github.com/rancher/wrangler/pkg/summary" "k8s.io/apimachinery/pkg/api/meta" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" ) func DefaultTemplate(clientGetter proxy.ClientGetter, asl accesscontrol.AccessSetLookup) schema.Template { @@ -32,4 +37,14 @@ func Formatter(request *types.APIRequest, resource *types.RawResource) { if _, ok := resource.Links["update"]; !ok { resource.Links["update"] = u } + + if unstr, ok := resource.APIObject.Object.(*unstructured.Unstructured); ok { + summary := summary.Summarize(unstr) + data.PutValue(unstr.Object, map[string]interface{}{ + "name": summary.State, + "error": summary.Error, + "transitioning": summary.Transitioning, + "message": strings.Join(summary.Message, ":"), + }, "metadata", "state") + } }