mirror of
https://github.com/rancher/k3k.git
synced 2026-03-27 13:56:54 +00:00
* adding scripts for asciidoc cli generation * fix small typos to align to existing docs * added pandoc * pandoc check
48 lines
1003 B
Go
48 lines
1003 B
Go
package cmds
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/spf13/cobra"
|
|
|
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
|
|
|
"github.com/rancher/k3k/pkg/apis/k3k.io/v1beta1"
|
|
)
|
|
|
|
func NewPolicyDeleteCmd(appCtx *AppContext) *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "delete",
|
|
Short: "Delete an existing policy.",
|
|
Example: "k3kcli policy delete [command options] NAME",
|
|
RunE: policyDeleteAction(appCtx),
|
|
Args: cobra.ExactArgs(1),
|
|
}
|
|
}
|
|
|
|
func policyDeleteAction(appCtx *AppContext) func(cmd *cobra.Command, args []string) error {
|
|
return func(cmd *cobra.Command, args []string) error {
|
|
ctx := context.Background()
|
|
client := appCtx.Client
|
|
name := args[0]
|
|
|
|
policy := &v1beta1.VirtualClusterPolicy{}
|
|
policy.Name = name
|
|
|
|
if err := client.Delete(ctx, policy); err != nil {
|
|
if !apierrors.IsNotFound(err) {
|
|
return err
|
|
}
|
|
|
|
logrus.Warnf("Policy '%s' not found", name)
|
|
|
|
return nil
|
|
}
|
|
|
|
logrus.Infof("Policy '%s' deleted", name)
|
|
|
|
return nil
|
|
}
|
|
}
|