mirror of
https://github.com/rancher/k3k.git
synced 2026-08-18 20:07:06 +00:00
* Add cluster deletion and completion enhancements - Implemented `--all` flag for deleting all clusters in a namespace. - Updated argument parsing to allow for maximum one cluster name. - Added completion functions for cluster names with namespace filtering. - Enhanced tests for cluster argument resolution and completion functions. * fix docs * Add log message for empty cluster deletion in specified namespace * Refactor context handling in command functions to use `cmd.Context()`
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package cmds
|
|
|
|
import (
|
|
"github.com/spf13/cobra"
|
|
"k8s.io/apimachinery/pkg/types"
|
|
"k8s.io/cli-runtime/pkg/printers"
|
|
|
|
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
|
|
|
"github.com/rancher/k3k/pkg/apis/k3k.io/v1beta1"
|
|
)
|
|
|
|
func NewPolicyListCmd(appCtx *AppContext) *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "list",
|
|
Short: "List all existing policies.",
|
|
Example: "k3kcli policy list [command options]",
|
|
RunE: policyList(appCtx),
|
|
Args: cobra.NoArgs,
|
|
}
|
|
}
|
|
|
|
func policyList(appCtx *AppContext) func(cmd *cobra.Command, args []string) error {
|
|
return func(cmd *cobra.Command, args []string) error {
|
|
ctx := cmd.Context()
|
|
client := appCtx.Client
|
|
|
|
var policies v1beta1.VirtualClusterPolicyList
|
|
if err := client.List(ctx, &policies); err != nil {
|
|
return err
|
|
}
|
|
|
|
crd := &apiextensionsv1.CustomResourceDefinition{}
|
|
if err := client.Get(ctx, types.NamespacedName{Name: "virtualclusterpolicies.k3k.io"}, crd); err != nil {
|
|
return err
|
|
}
|
|
|
|
items := toPointerSlice(policies.Items)
|
|
table := createTable(crd, items)
|
|
|
|
printer := printers.NewTablePrinter(printers.PrintOptions{})
|
|
|
|
return printer.PrintObj(table, cmd.OutOrStdout())
|
|
}
|
|
}
|