diff --git a/cmd/crank/beta/trace/internal/printer/default.go b/cmd/crank/beta/trace/internal/printer/default.go index 393f209e150..2aa364ff775 100644 --- a/cmd/crank/beta/trace/internal/printer/default.go +++ b/cmd/crank/beta/trace/internal/printer/default.go @@ -21,6 +21,7 @@ import ( "io" "strings" + corev1 "k8s.io/api/core/v1" "k8s.io/cli-runtime/pkg/printers" xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" @@ -42,12 +43,12 @@ type DefaultPrinter struct { var _ Printer = &DefaultPrinter{} type defaultPrinterRow struct { - namespace string - apiVersion string - name string - ready string - synced string - latestEvent string + namespace string + apiVersion string + name string + ready string + synced string + status string } func (r *defaultPrinterRow) String() string { @@ -57,7 +58,7 @@ func (r *defaultPrinterRow) String() string { r.name, r.ready, r.synced, - r.latestEvent, + r.status, }, "\t") + "\t" } @@ -67,12 +68,12 @@ func (p *DefaultPrinter) Print(w io.Writer, root *resource.Resource) error { tw := printers.GetNewTabWriter(w) headers := defaultPrinterRow{ - namespace: "NAMESPACE", - apiVersion: "APIVERSION", - name: "NAME", - ready: "READY", - synced: "SYNCED", - latestEvent: "LATESTEVENT", + namespace: "NAMESPACE", + apiVersion: "APIVERSION", + name: "NAME", + ready: "READY", + synced: "SYNCED", + status: "STATUS", } if _, err := fmt.Fprintln(tw, headers.String()); err != nil { return errors.Errorf(errFmtCannotWriteHeader, err) @@ -109,16 +110,15 @@ func (p *DefaultPrinter) Print(w io.Writer, root *resource.Resource) error { } name.WriteString(fmt.Sprintf("%s/%s", item.resource.Unstructured.GetKind(), item.resource.Unstructured.GetName())) + ready, synced, status := getResourceStatus(item.resource) row := defaultPrinterRow{ namespace: item.resource.Unstructured.GetNamespace(), apiVersion: item.resource.Unstructured.GetAPIVersion(), name: name.String(), - ready: string(item.resource.GetCondition(xpv1.TypeReady).Status), - synced: string(item.resource.GetCondition(xpv1.TypeSynced).Status), - } - if e := item.resource.LatestEvent; e != nil { - row.latestEvent = fmt.Sprintf("[%s] %s", e.Type, e.Message) + ready: ready, + synced: synced, + status: status, } if _, err := fmt.Fprintln(tw, row.String()); err != nil { return errors.Errorf(errFmtCannotWriteRow, err) @@ -137,7 +137,22 @@ func (p *DefaultPrinter) Print(w io.Writer, root *resource.Resource) error { return nil } -// NeedLatestEvent implements the Printer interface. -func (p *DefaultPrinter) NeedLatestEvent() bool { - return true +// getResourceStatus returns the status of the resource. +func getResourceStatus(r *resource.Resource) (ready string, synced string, status string) { + readyCond := r.GetCondition(xpv1.TypeReady) + syncedCond := r.GetCondition(xpv1.TypeSynced) + switch { + case r.Error != nil: + status = fmt.Sprintf("Error: %s", r.Error) + case readyCond.Status == corev1.ConditionTrue && syncedCond.Status == corev1.ConditionTrue: + status = string(readyCond.Reason) + case readyCond.Status == corev1.ConditionFalse: + status = fmt.Sprintf("%s: %q", readyCond.Reason, readyCond.Message) + case syncedCond.Status == corev1.ConditionFalse: + status = fmt.Sprintf("%s: %q", syncedCond.Reason, syncedCond.Message) + case syncedCond.Status != corev1.ConditionTrue && readyCond.Status != corev1.ConditionTrue: + status = fmt.Sprintf("%s: %q", readyCond.Reason, readyCond.Message) + } + + return string(readyCond.Status), string(syncedCond.Status), status } diff --git a/cmd/crank/beta/trace/internal/printer/default_test.go b/cmd/crank/beta/trace/internal/printer/default_test.go index 8650d1b0af5..b4aed7c8aaf 100644 --- a/cmd/crank/beta/trace/internal/printer/default_test.go +++ b/cmd/crank/beta/trace/internal/printer/default_test.go @@ -45,21 +45,21 @@ func TestDefaultPrinter(t *testing.T) { }{ // Test valid resource "ResourceWithChildren": { - reason: "Should print a complex Resource with children and events.", + reason: "Should print a complex Resource with children.", args: args{ resource: GetComplexResource(), }, want: want{ // Note: Use spaces instead of tabs for intendation output: ` -NAMESPACE APIVERSION NAME READY SYNCED LATESTEVENT -default test.cloud/v1alpha1 ObjectStorage/test-resource True True [Normal] Successfully selected composition -default test.cloud/v1alpha1 └── XObjectStorage/test-resource-hash True True -default test.cloud/v1alpha1 ├── Bucket/test-resource-bucket-hash True True [Warning] Error with bucket -default test.cloud/v1alpha1 │ ├── User/test-resource-child-1-bucket-hash False True -default test.cloud/v1alpha1 │ └── User/test-resource-child-2-bucket-hash False True -default test.cloud/v1alpha1 │ └── User/test-resource-child-2-1-bucket-hash False True -default test.cloud/v1alpha1 └── User/test-resource-user-hash True True [Normal] User ready +NAMESPACE APIVERSION NAME READY SYNCED STATUS +default test.cloud/v1alpha1 ObjectStorage/test-resource True True +default test.cloud/v1alpha1 └── XObjectStorage/test-resource-hash True True +default test.cloud/v1alpha1 ├── Bucket/test-resource-bucket-hash True True +default test.cloud/v1alpha1 │ ├── User/test-resource-child-1-bucket-hash False True SomethingWrongHappened: "Error with bucket child 1" +default test.cloud/v1alpha1 │ └── User/test-resource-child-2-bucket-hash False True SomethingWrongHappened: "Error with bucket child 2" +default test.cloud/v1alpha1 │ └── User/test-resource-child-2-1-bucket-hash False True SomethingWrongHappened: "Error with bucket child 2-1" +default test.cloud/v1alpha1 └── User/test-resource-user-hash True True `, err: nil, }, diff --git a/cmd/crank/beta/trace/internal/printer/dot.go b/cmd/crank/beta/trace/internal/printer/dot.go index 4d93dcb0dd8..0c2a4cf5bd3 100644 --- a/cmd/crank/beta/trace/internal/printer/dot.go +++ b/cmd/crank/beta/trace/internal/printer/dot.go @@ -25,6 +25,7 @@ type dotLabel struct { name string ready string synced string + error string } func (r *dotLabel) String() string { @@ -41,6 +42,11 @@ func (r *dotLabel) String() string { "Ready: "+r.ready, "Synced: "+r.synced, ) + if r.error != "" { + out = append(out, + "Error: "+r.error, + ) + } return strings.Join(out, "\n") + "\n" } @@ -93,8 +99,3 @@ func (p *DotPrinter) Print(w io.Writer, root *resource.Resource) error { return nil } - -// NeedLatestEvent implements the Printer interface. -func (p *DotPrinter) NeedLatestEvent() bool { - return false -} diff --git a/cmd/crank/beta/trace/internal/printer/dot_test.go b/cmd/crank/beta/trace/internal/printer/dot_test.go index a262289dd7a..ef643392a1b 100644 --- a/cmd/crank/beta/trace/internal/printer/dot_test.go +++ b/cmd/crank/beta/trace/internal/printer/dot_test.go @@ -29,7 +29,7 @@ func TestPrintDotGraph(t *testing.T) { }{ // Test valid resource "ResourceWithChildren": { - reason: "Should print a complex Resource with children and events.", + reason: "Should print a complex Resource with children.", args: args{ resource: GetComplexResource(), }, diff --git a/cmd/crank/beta/trace/internal/printer/json.go b/cmd/crank/beta/trace/internal/printer/json.go index 7edc4e00fdf..7089816fac1 100644 --- a/cmd/crank/beta/trace/internal/printer/json.go +++ b/cmd/crank/beta/trace/internal/printer/json.go @@ -45,8 +45,3 @@ func (p *JSONPrinter) Print(w io.Writer, root *resource.Resource) error { _, err = fmt.Fprintln(w, string(out)) return err } - -// NeedLatestEvent implements the Printer interface. -func (p *JSONPrinter) NeedLatestEvent() bool { - return true -} diff --git a/cmd/crank/beta/trace/internal/printer/json_test.go b/cmd/crank/beta/trace/internal/printer/json_test.go index c76547e6dad..b613188f593 100644 --- a/cmd/crank/beta/trace/internal/printer/json_test.go +++ b/cmd/crank/beta/trace/internal/printer/json_test.go @@ -22,7 +22,6 @@ import ( "testing" "github.com/google/go-cmp/cmp" - v1 "k8s.io/api/core/v1" "github.com/crossplane/crossplane-runtime/pkg/test" @@ -46,33 +45,9 @@ func TestJSONPrinter(t *testing.T) { }{ // Test valid resource "ResourceWithChildren": { - reason: "Should print a complex Resource with children and events.", + reason: "Should print a complex Resource with children.", args: args{ - resource: &resource.Resource{ - Unstructured: DummyManifest("ObjectStorage", "test-resource", "True", "True"), - LatestEvent: &v1.Event{ - Message: "Successfully selected composition", - }, - Children: []*resource.Resource{ - { - Unstructured: DummyManifest("XObjectStorage", "test-resource-hash", "True", "True"), - Children: []*resource.Resource{ - { - Unstructured: DummyManifest("Bucket", "test-resource-bucket-hash", "True", "True"), - LatestEvent: &v1.Event{ - Message: "Synced bucket", - }, - }, - { - Unstructured: DummyManifest("User", "test-resource-user-hash", "True", "True"), - LatestEvent: &v1.Event{ - Message: "User ready", - }, - }, - }, - }, - }, - }, + resource: GetComplexResource(), }, want: want{ // Note: Use spaces instead of tabs for intendation @@ -92,8 +67,10 @@ func TestJSONPrinter(t *testing.T) { "type": "Synced" }, { + "type": "Ready", "status": "True", - "type": "Ready" + "lastTransitionTime": null, + "reason": "" } ] } @@ -114,8 +91,10 @@ func TestJSONPrinter(t *testing.T) { "type": "Synced" }, { + "type": "Ready", "status": "True", - "type": "Ready" + "lastTransitionTime": null, + "reason": "" } ] } @@ -136,25 +115,93 @@ func TestJSONPrinter(t *testing.T) { "type": "Synced" }, { + "type": "Ready", "status": "True", - "type": "Ready" + "lastTransitionTime": null, + "reason": "" } ] } }, - "latestEvent": { - "metadata": { - "creationTimestamp": null + "children": [ + { + "object": { + "apiVersion": "test.cloud/v1alpha1", + "kind": "User", + "metadata": { + "name": "test-resource-child-1-bucket-hash", + "namespace": "default" + }, + "status": { + "conditions": [ + { + "status": "True", + "type": "Synced" + }, + { + "type": "Ready", + "status": "False", + "lastTransitionTime": null, + "reason": "SomethingWrongHappened", + "message": "Error with bucket child 1" + } + ] + } + } }, - "involvedObject": {}, - "message": "Synced bucket", - "source": {}, - "firstTimestamp": null, - "lastTimestamp": null, - "eventTime": null, - "reportingComponent": "", - "reportingInstance": "" - } + { + "object": { + "apiVersion": "test.cloud/v1alpha1", + "kind": "User", + "metadata": { + "name": "test-resource-child-2-bucket-hash", + "namespace": "default" + }, + "status": { + "conditions": [ + { + "status": "True", + "type": "Synced" + }, + { + "type": "Ready", + "status": "False", + "lastTransitionTime": null, + "reason": "SomethingWrongHappened", + "message": "Error with bucket child 2" + } + ] + } + }, + "children": [ + { + "object": { + "apiVersion": "test.cloud/v1alpha1", + "kind": "User", + "metadata": { + "name": "test-resource-child-2-1-bucket-hash", + "namespace": "default" + }, + "status": { + "conditions": [ + { + "status": "True", + "type": "Synced" + }, + { + "type": "Ready", + "status": "False", + "lastTransitionTime": null, + "reason": "SomethingWrongHappened", + "message": "Error with bucket child 2-1" + } + ] + } + } + } + ] + } + ] }, { "object": { @@ -171,44 +218,20 @@ func TestJSONPrinter(t *testing.T) { "type": "Synced" }, { + "type": "Ready", "status": "True", - "type": "Ready" + "lastTransitionTime": null, + "reason": "" } ] } - }, - "latestEvent": { - "metadata": { - "creationTimestamp": null - }, - "involvedObject": {}, - "message": "User ready", - "source": {}, - "firstTimestamp": null, - "lastTimestamp": null, - "eventTime": null, - "reportingComponent": "", - "reportingInstance": "" } } ] } - ], - "latestEvent": { - "metadata": { - "creationTimestamp": null - }, - "involvedObject": {}, - "message": "Successfully selected composition", - "source": {}, - "firstTimestamp": null, - "lastTimestamp": null, - "eventTime": null, - "reportingComponent": "", - "reportingInstance": "" - } + ] } - `, +`, err: nil, }, }, diff --git a/cmd/crank/beta/trace/internal/printer/printer.go b/cmd/crank/beta/trace/internal/printer/printer.go index 06bb0142b31..bdd6f4f0833 100644 --- a/cmd/crank/beta/trace/internal/printer/printer.go +++ b/cmd/crank/beta/trace/internal/printer/printer.go @@ -43,7 +43,6 @@ const ( // Printer implements the interface which is used by all printers in this package. type Printer interface { Print(io.Writer, *resource.Resource) error - NeedLatestEvent() bool } // New creates a new printer based on the specified type. diff --git a/cmd/crank/beta/trace/internal/printer/printer_test.go b/cmd/crank/beta/trace/internal/printer/printer_test.go index 4510cf0973c..2d09dd9a416 100644 --- a/cmd/crank/beta/trace/internal/printer/printer_test.go +++ b/cmd/crank/beta/trace/internal/printer/printer_test.go @@ -17,14 +17,15 @@ limitations under the License. package printer import ( - v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" + "github.com/crossplane/crossplane/cmd/crank/beta/trace/internal/resource" ) // Returns an unstructured that has basic fields set to be used by other tests. -func DummyManifest(kind, name, syncedStatus, readyStatus string) unstructured.Unstructured { +func DummyManifest(kind, name, syncedStatus string, readyCond *xpv1.Condition) unstructured.Unstructured { m := unstructured.Unstructured{ Object: map[string]interface{}{ "apiVersion": "test.cloud/v1alpha1", @@ -39,10 +40,7 @@ func DummyManifest(kind, name, syncedStatus, readyStatus string) unstructured.Un "status": syncedStatus, "type": "Synced", }, - map[string]interface{}{ - "status": readyStatus, - "type": "Ready", - }, + readyCond, }, }, }, @@ -53,42 +51,56 @@ func DummyManifest(kind, name, syncedStatus, readyStatus string) unstructured.Un func GetComplexResource() *resource.Resource { return &resource.Resource{ - Unstructured: DummyManifest("ObjectStorage", "test-resource", "True", "True"), - LatestEvent: &v1.Event{ - Type: "Normal", - Message: "Successfully selected composition", - }, + Unstructured: DummyManifest("ObjectStorage", "test-resource", "True", &xpv1.Condition{ + Type: "Ready", + Status: "True", + }), Children: []*resource.Resource{ { - Unstructured: DummyManifest("XObjectStorage", "test-resource-hash", "True", "True"), - LatestEvent: nil, + Unstructured: DummyManifest("XObjectStorage", "test-resource-hash", "True", &xpv1.Condition{ + Type: "Ready", + Status: "True", + }), Children: []*resource.Resource{ { - Unstructured: DummyManifest("Bucket", "test-resource-bucket-hash", "True", "True"), - LatestEvent: &v1.Event{ - Type: "Warning", - Message: "Error with bucket", - }, + Unstructured: DummyManifest("Bucket", "test-resource-bucket-hash", "True", &xpv1.Condition{ + Type: "Ready", + Status: "True", + }), Children: []*resource.Resource{ { - Unstructured: DummyManifest("User", "test-resource-child-1-bucket-hash", "True", "False"), + Unstructured: DummyManifest("User", "test-resource-child-1-bucket-hash", "True", &xpv1.Condition{ + Type: "Ready", + Status: "False", + Reason: "SomethingWrongHappened", + Message: "Error with bucket child 1", + }), }, { - Unstructured: DummyManifest("User", "test-resource-child-2-bucket-hash", "True", "False"), + Unstructured: DummyManifest("User", "test-resource-child-2-bucket-hash", "True", &xpv1.Condition{ + Type: "Ready", + Reason: "SomethingWrongHappened", + Status: "False", + Message: "Error with bucket child 2", + }), Children: []*resource.Resource{ { - Unstructured: DummyManifest("User", "test-resource-child-2-1-bucket-hash", "True", "False"), + Unstructured: DummyManifest("User", "test-resource-child-2-1-bucket-hash", "True", &xpv1.Condition{ + Type: "Ready", + Reason: "SomethingWrongHappened", + Status: "False", + Message: "Error with bucket child 2-1", + }), }, }, }, }, }, { - Unstructured: DummyManifest("User", "test-resource-user-hash", "True", "True"), - LatestEvent: &v1.Event{ - Type: "Normal", - Message: "User ready", - }, + Unstructured: DummyManifest("User", "test-resource-user-hash", "True", &xpv1.Condition{ + Type: "Ready", + Status: "True", + }), }, }, }, diff --git a/cmd/crank/beta/trace/internal/resource/client.go b/cmd/crank/beta/trace/internal/resource/client.go index e566495773b..32bf77836cd 100644 --- a/cmd/crank/beta/trace/internal/resource/client.go +++ b/cmd/crank/beta/trace/internal/resource/client.go @@ -21,9 +21,9 @@ import ( "fmt" v1 "k8s.io/api/core/v1" + kerrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/runtime/schema" "sigs.k8s.io/controller-runtime/pkg/client" @@ -35,24 +35,19 @@ import ( ) const ( - errCouldntGetRootResource = "couldn't get root resource" - errCouldntGetChildResource = "couldn't get child resource" - errCouldntGetResource = "couldn't get resource" - errCouldntGetEventForResource = "couldn't get event for resource" - errCouldntGetEventListForResource = "couldn't get event list for resource" - errFmtResourceTypeNotFound = "the server doesn't have a resource type %q" + errCouldntGetRootResource = "couldn't get root resource" + errCouldntGetChildResource = "couldn't get child resource" + errCouldntGetResource = "couldn't get resource" + errFmtResourceTypeNotFound = "the server doesn't have a resource type %q" ) -// Client to get a Resource with all its children and latest events. +// Client to get a Resource with all its children. type Client struct { - gatherLatestEvent bool - client client.Client rmapper meta.RESTMapper } -// GetResourceTree returns the requested Resource and all its children, with -// latest events for each of them, if any. +// GetResourceTree returns the requested Resource and all its children. func (kc *Client) GetResourceTree(ctx context.Context, rootRef *v1.ObjectReference) (*Resource, error) { // Get the root resource root, err := kc.getResource(ctx, rootRef) @@ -84,34 +79,21 @@ func (kc *Client) GetResourceTree(ctx context.Context, rootRef *v1.ObjectReferen return root, nil } -// getResource returns the requested Resource with the latest event set, if required. +// getResource returns the requested Resource. func (kc *Client) getResource(ctx context.Context, ref *v1.ObjectReference) (*Resource, error) { result := unstructured.Unstructured{} result.SetGroupVersionKind(ref.GroupVersionKind()) - if err := kc.client.Get(ctx, xpmeta.NamespacedNameOf(ref), &result); err != nil { - return nil, errors.Wrap(err, errCouldntGetResource) + err := kc.client.Get(ctx, xpmeta.NamespacedNameOf(ref), &result) + if kerrors.IsNotFound(err) { + result.SetName(ref.Name) + result.SetNamespace(ref.Namespace) + return &Resource{Unstructured: result, Error: err}, nil } - - res := &Resource{Unstructured: result} - - if !kc.gatherLatestEvent { - return res, nil - } - - // Get event - event, err := kc.getLatestEvent(ctx, v1.ObjectReference{ - Kind: result.GetKind(), - APIVersion: result.GetAPIVersion(), - Name: result.GetName(), - Namespace: result.GetNamespace(), - UID: result.GetUID(), - }) if err != nil { - return nil, errors.Wrap(err, errCouldntGetEventForResource) + return nil, errors.Wrap(err, errCouldntGetResource) } - res.LatestEvent = event - return res, nil + return &Resource{Unstructured: result}, nil } // getResourceChildrenRefs returns the references to the children for the given @@ -154,41 +136,6 @@ func getResourceChildrenRefs(r *Resource) []v1.ObjectReference { return refs } -// The getLatestEvent returns the latest Event for the given resource reference. -func (kc *Client) getLatestEvent(ctx context.Context, ref v1.ObjectReference) (*v1.Event, error) { - // List events for the resource. - fieldSelectors := []fields.Selector{ - fields.OneTermEqualSelector("involvedObject.name", ref.Name), - fields.OneTermEqualSelector("involvedObject.kind", ref.Kind), - fields.OneTermEqualSelector("involvedObject.apiVersion", ref.APIVersion), - } - - if ref.UID != "" { - fieldSelectors = append(fieldSelectors, fields.OneTermEqualSelector("involvedObject.uid", string(ref.UID))) - } - eventList := v1.EventList{} - if err := kc.client.List(ctx, &eventList, client.MatchingFieldsSelector{ - Selector: fields.AndSelectors(fieldSelectors...), - }); err != nil { - return nil, errors.Wrap(err, errCouldntGetEventListForResource) - } - - // Check if there are any events. - if len(eventList.Items) == 0 { - return nil, nil - } - - latestEvent := eventList.Items[0] - for _, event := range eventList.Items { - if event.LastTimestamp.After(latestEvent.LastTimestamp.Time) { - latestEvent = event - } - } - - // Get the latest event. - return &latestEvent, nil -} - // MappingFor returns the RESTMapping for the given resource or kind argument. // Copied over from cli-runtime pkg/resource Builder, // https://github.com/kubernetes/cli-runtime/blob/9a91d944dd43186c52e0162e12b151b0e460354a/pkg/resource/builder.go#L768 @@ -230,27 +177,12 @@ func (kc *Client) MappingFor(resourceOrKindArg string) (*meta.RESTMapping, error return mapping, nil } -// ClientOption is used to configure a Client. -type ClientOption func(*Client) - -// WithLatestEvent returns a ClientOption configuring the Client to gather the -// latest event for each resource. -func WithLatestEvent() ClientOption { - return func(c *Client) { - c.gatherLatestEvent = true - } -} - // NewClient returns a new Client. -func NewClient(in client.Client, rmapper meta.RESTMapper, opts ...ClientOption) (*Client, error) { +func NewClient(in client.Client, rmapper meta.RESTMapper) (*Client, error) { uClient := xpunstructured.NewClient(in) - c := &Client{ + return &Client{ client: uClient, rmapper: rmapper, - } - for _, opt := range opts { - opt(c) - } - return c, nil + }, nil } diff --git a/cmd/crank/beta/trace/internal/resource/resource.go b/cmd/crank/beta/trace/internal/resource/resource.go index 49494f3717c..b0b315f5d91 100644 --- a/cmd/crank/beta/trace/internal/resource/resource.go +++ b/cmd/crank/beta/trace/internal/resource/resource.go @@ -19,7 +19,6 @@ limitations under the License. package resource import ( - v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" @@ -29,8 +28,8 @@ import ( // Resource struct represents a kubernetes resource. type Resource struct { Unstructured unstructured.Unstructured `json:"object"` + Error error `json:"error,omitempty"` Children []*Resource `json:"children,omitempty"` - LatestEvent *v1.Event `json:"latestEvent,omitempty"` } // GetCondition of this resource. diff --git a/cmd/crank/beta/trace/trace.go b/cmd/crank/beta/trace/trace.go index 7c1bcb10863..8a4a9580dec 100644 --- a/cmd/crank/beta/trace/trace.go +++ b/cmd/crank/beta/trace/trace.go @@ -68,7 +68,7 @@ If needed the resource kind can be also specified further, 'TYPE[.VERSION][.GROUP]', e.g. mykind.example.org. Examples: - # Trace a MyKind (mykinds.example.org/v1alpha1) named 'my-res' in the namespace 'my-ns' + # Trace a MyKind resource (mykinds.example.org/v1alpha1) named 'my-res' in the namespace 'my-ns' crossplane beta trace mykind my-res -n my-ns # Output a graph in dot format and pipe to dot to generate a png @@ -117,14 +117,8 @@ func (c *Cmd) Run(k *kong.Context, logger logging.Logger) error { //nolint:gocyc d := memory.NewMemCacheClient(discoveryClient) rmapper := restmapper.NewShortcutExpander(restmapper.NewDeferredDiscoveryRESTMapper(d), d) - var opts []resource.ClientOption - if p.NeedLatestEvent() { - logger.Debug("Adding latest event option") - opts = append(opts, resource.WithLatestEvent()) - } - // Get client for k8s package - resClient, err := resource.NewClient(client, rmapper, opts...) + resClient, err := resource.NewClient(client, rmapper) if err != nil { return errors.Wrap(err, errInitKubeClient) }