Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions cmd/crossplane/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ package resource

import (
"github.com/crossplane/cli/v2/cmd/crossplane/simulate"
"github.com/crossplane/cli/v2/cmd/crossplane/trace"
"github.com/crossplane/cli/v2/cmd/crossplane/tree"
"github.com/crossplane/cli/v2/cmd/crossplane/validate"
)

// Cmd contains commands for working with Crossplane resources.
type Cmd struct {
Simulate simulate.Cmd `cmd:"" help:"Preview what applying managed resources would do." maturity:"alpha"`
Trace trace.Cmd `cmd:"" help:"Trace a Crossplane resource for troubleshooting."`
Validate validate.Cmd `cmd:"" help:"Validate Crossplane resources."`
Simulate simulate.Cmd `cmd:"" help:"Preview what applying managed resources would do." maturity:"alpha"`
Trace tree.TraceCmd `cmd:"" help:"Trace a Crossplane resource for troubleshooting."`
Validate validate.Cmd `cmd:"" help:"Validate Crossplane resources."`
Suspend tree.SuspendCmd `cmd:"" help:"Suspend crossplane resource reconciliation."`
Resume tree.ResumeCmd `cmd:"" help:"Resume reconciliation for suspended crossplane resources."`
Reconcile tree.ReconcileCmd `cmd:"" help:"Trigger an immediate reconciliation for a crossplane resource."`
}
105 changes: 0 additions & 105 deletions cmd/crossplane/trace/trace_test.go

This file was deleted.

46 changes: 46 additions & 0 deletions cmd/crossplane/tree/annotate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
Copyright 2026 The Crossplane Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package tree

import (
"context"
"encoding/json"

"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/crossplane/crossplane-runtime/v2/pkg/errors"
)

// patchAnnotations sets and removes annotations.
func patchAnnotations(ctx context.Context, c client.Client, u *unstructured.Unstructured, annotations map[string]*string) error {
data, err := json.Marshal(map[string]any{
"metadata": map[string]any{
"annotations": annotations,
},
})
if err != nil {
return errors.Wrapf(err, errFmtUpdateResource, u.GetKind(), u.GetName(), u.GetNamespace())
}

if err := c.Patch(ctx, u, client.RawPatch(types.MergePatchType, data)); err != nil {
return errors.Wrapf(err, errFmtUpdateResource, u.GetKind(), u.GetName(), u.GetNamespace())
}

return nil
}
69 changes: 69 additions & 0 deletions cmd/crossplane/tree/help/reconcile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
The `resource reconcile` command triggers an immediate reconciliation of a Crossplane resource (Claim,
Composite, or Managed Resource) by setting the
`crossplane.io/reconcile-requested-at` annotation.

Paused resources (with the `crossplane.io/paused: "true"` annotation) are not
reconciled. If any affected resource is paused, including descendants when
using `--cascade`, the command fails without changing anything. Use
`crossplane resource resume` to resume and reconcile paused resources.

The command requires a resource type. The resource name is optional; when it
is omitted, the command applies to all resources of that type:

```shell
crossplane resource reconcile <resource kind> [<resource name>]
```

Kubernetes-style `<kind>/<name>` input works too: for example, `crossplane
resource reconcile example.crossplane.io/my-xr`.

You can further specify the kind as `TYPE[.VERSION][.GROUP]` if needed; for
example, `mykind.example.org` or `mykind.v1alpha1.example.org`.

By default, `crossplane resource reconcile` uses the Kubernetes configuration at
`~/.kube/config`. Override with the `KUBECONFIG` environment variable.

## Cascade

By default, `reconcile` only applies to the requested resource. Use `--cascade`
to reconcile the whole resource tree recursively. Combine it with `--watch` to
follow the status afterwards:

```shell
crossplane resource reconcile <resource kind> <resource name> --cascade --watch
```

## Output options

After applying the change, `reconcile` prints the affected resources to the
terminal as a tree, the same way `crossplane resource trace` does. Without
`--cascade` only the requested resources are printed.

Change the format with `-o` (`--output`): `wide`, `json`, `yaml`, or `dot` (for
a [Graphviz](https://graphviz.org/docs/layouts/dot/) graph).

## Examples

Reconcile a `MyKind` resource named `my-res` in the namespace `my-ns`:

```shell
crossplane resource reconcile mykind my-res -n my-ns
```

Reconcile all `MyKind` resources in the namespace `my-ns`:

```shell
crossplane resource reconcile mykind -n my-ns
```

Reconcile a resource and all of its descendants:

```shell
crossplane resource reconcile mykind my-res -n my-ns --cascade
```

Reconcile a resource and watch it continuously until its deletion:

```shell
crossplane resource reconcile mykind my-res -n my-ns --watch
```
66 changes: 66 additions & 0 deletions cmd/crossplane/tree/help/resume.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
The `resource resume` command resumes the reconciliation of a paused Crossplane resource (Claim,
Composite, or Managed Resource) by removing the `crossplane.io/paused` annotation.
It also sets the `crossplane.io/reconcile-requested-at` annotation to the
current time, so the resource is reconciled right away instead of waiting for
the next poll interval.

The command requires a resource type. The resource name is optional; when it
is omitted, the command applies to all resources of that type:

```shell
crossplane resource resume <resource kind> [<resource name>]
```

Kubernetes-style `<kind>/<name>` input works too: for example, `crossplane
resource resume example.crossplane.io/my-xr`.

You can further specify the kind as `TYPE[.VERSION][.GROUP]` if needed; for
example, `mykind.example.org` or `mykind.v1alpha1.example.org`.

By default, `crossplane resource resume` uses the Kubernetes configuration at
`~/.kube/config`. Override with the `KUBECONFIG` environment variable.

## Cascade

By default, `resume` only applies to the requested resource. Use `--cascade`
to resume the whole resource tree recursively. Combine it with `--watch` to
follow the status afterwards:

```shell
crossplane resource resume <resource kind> <resource name> --cascade --watch
```

## Output options

After applying the change, `resume` prints the affected resources to the
terminal as a tree, the same way `crossplane resource trace` does. Without
`--cascade` only the requested resources are printed.

Change the format with `-o` (`--output`): `wide`, `json`, `yaml`, or `dot` (for
a [Graphviz](https://graphviz.org/docs/layouts/dot/) graph).

## Examples

Resume a `MyKind` resource named `my-res` in the namespace `my-ns`:

```shell
crossplane resource resume mykind my-res -n my-ns
```

Resume all `MyKind` resources in the namespace `my-ns`:

```shell
crossplane resource resume mykind -n my-ns
```

Resume a resource and all of its descendants:

```shell
crossplane resource resume mykind my-res -n my-ns --cascade
```

Resume a resource and watch it continuously until its deletion:

```shell
crossplane resource resume mykind my-res -n my-ns --watch
```
63 changes: 63 additions & 0 deletions cmd/crossplane/tree/help/suspend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
The `resource suspend` command pauses the reconciliation of a Crossplane resource (Claim, Composite, or
Managed Resource) by setting the `crossplane.io/paused` annotation.

The command requires a resource type. The resource name is optional; when it
is omitted, the command applies to all resources of that type:

```shell
crossplane resource suspend <resource kind> [<resource name>]
```

Kubernetes-style `<kind>/<name>` input works too: for example, `crossplane
resource suspend example.crossplane.io/my-xr`.

You can further specify the kind as `TYPE[.VERSION][.GROUP]` if needed; for
example, `mykind.example.org` or `mykind.v1alpha1.example.org`.

By default, `crossplane resource suspend` uses the Kubernetes configuration at
`~/.kube/config`. Override with the `KUBECONFIG` environment variable.

## Cascade

By default, `suspend` only applies to the requested resource. Use `--cascade`
to suspend the whole resource tree recursively. Combine it with `--watch` to
follow the status afterwards:

```shell
crossplane resource suspend <resource kind> <resource name> --cascade --watch
```

## Output options

After applying the change, `suspend` prints the affected resources to the
terminal as a tree, the same way `crossplane resource trace` does. Without
`--cascade` only the requested resources are printed.

Change the format with `-o` (`--output`): `wide`, `json`, `yaml`, or `dot` (for
a [Graphviz](https://graphviz.org/docs/layouts/dot/) graph).

## Examples

Suspend a `MyKind` resource named `my-res` in the namespace `my-ns`:

```shell
crossplane resource suspend mykind my-res -n my-ns
```

Suspend all `MyKind` resources in the namespace `my-ns`:

```shell
crossplane resource suspend mykind -n my-ns
```

Suspend a resource and all of its descendants:

```shell
crossplane resource suspend mykind my-res -n my-ns --cascade
```

Suspend a resource and watch it continuously until its deletion:

```shell
crossplane resource suspend mykind my-res -n my-ns --watch
```
Loading