Skip to content

Commit

Permalink
Add --force flag to minio delete command (#1687)
Browse files Browse the repository at this point in the history
* Add --force flag to minio  delete command

---------

Co-authored-by: Cesar Celis Hernandez <celis.hernandez.cesar@gmail.com>
Co-authored-by: Pedro Juarez <pjuarezd@users.noreply.github.com>
  • Loading branch information
3 people committed Jul 25, 2023
1 parent e0ab20e commit 41ac8de
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions helm/operator/templates/minio.min.io_tenants.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
Expand Down
1 change: 1 addition & 0 deletions helm/operator/templates/sts.min.io_policybindings.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
Expand Down
15 changes: 13 additions & 2 deletions kubectl-minio/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ type deleteCmd struct {
errOut io.Writer
output bool
operatorOpts resources.OperatorOptions
force bool
dangerous bool
}

func newDeleteCmd(out io.Writer, errOut io.Writer) *cobra.Command {
Expand All @@ -57,8 +59,15 @@ func newDeleteCmd(out io.Writer, errOut io.Writer) *cobra.Command {
Example: deleteExample,
Args: cobra.MaximumNArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
if !helpers.Ask("Are you sure you want to delete ALL the MinIO Tenants and MinIO Operator, this is not a reversible operation") {
return fmt.Errorf(Bold("Aborting Operator deletion"))
if !o.force {
if !helpers.Ask("This is irreversible, are you sure you want to delete MinIO Operator and all it's tenants") {
return fmt.Errorf("Aborting MinIO Operator deletion")
}
}
if !o.dangerous {
if !helpers.Ask("Please provide the dangerous flag to confirm deletion") {
return fmt.Errorf("Aborting MinIO Operator deletion")
}
}
err := o.run(out)
if err != nil {
Expand All @@ -71,6 +80,8 @@ func newDeleteCmd(out io.Writer, errOut io.Writer) *cobra.Command {
cmd = helpers.DisableHelp(cmd)
f := cmd.Flags()
f.StringVarP(&o.operatorOpts.Namespace, "namespace", "n", helpers.DefaultNamespace, "namespace scope for this request")
f.BoolVarP(&o.force, "force", "f", false, "allow without confirmation")
f.BoolVarP(&o.dangerous, "dangerous", "d", false, "confirm deletion")
return cmd
}

Expand Down
2 changes: 1 addition & 1 deletion kubectl-minio/cmd/kubectl-minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func init() {
}

// New creates a new root command for kubectl-minio
func New(streams genericclioptions.IOStreams) *cobra.Command {
func New(_ genericclioptions.IOStreams) *cobra.Command {
rootCmd = helpers.DisableHelp(rootCmd)
cobra.EnableCommandSorting = false
rootCmd.AddCommand(newInitCmd(rootCmd.OutOrStdout(), rootCmd.ErrOrStderr()))
Expand Down
2 changes: 1 addition & 1 deletion kubectl-minio/cmd/resources/tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func NewTenant(opts *TenantOptions, userSecret *v1.Secret) (*miniov2.Tenant, err
return t, t.Validate()
}

func getAutoCertConfig(opts *TenantOptions) *miniov2.CertificateConfig {
func getAutoCertConfig(_ *TenantOptions) *miniov2.CertificateConfig {
return &miniov2.CertificateConfig{
CommonName: "",
OrganizationName: []string{},
Expand Down
2 changes: 1 addition & 1 deletion kubectl-minio/cmd/tenant-create.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (c *createCmd) validate(args []string) error {
}

// run initializes local config and installs MinIO Operator to Kubernetes cluster.
func (c *createCmd) run(args []string) error {
func (c *createCmd) run(_ []string) error {
// Create operator and kube client
path, _ := rootCmd.Flags().GetString(kubeconfig)
operatorClient, err := helpers.GetKubeOperatorClient(path)
Expand Down
2 changes: 1 addition & 1 deletion kubectl-minio/cmd/tenant-list.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (d *listCmd) validate(args []string) error {
}

// run initializes local config and installs MinIO Operator to Kubernetes cluster.
func (d *listCmd) run(args []string) error {
func (d *listCmd) run(_ []string) error {
// Create operator client
path, _ := rootCmd.Flags().GetString(kubeconfig)
oclient, err := helpers.GetKubeOperatorClient(path)
Expand Down
2 changes: 1 addition & 1 deletion kubectl-minio/cmd/tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func getTenantNamespace(client *operatorv1.Clientset, tenantName string) (string
return "", fmt.Errorf("tenant: %s not found on any namespace", tenantName)
}

func newTenantCmd(out io.Writer, errOut io.Writer) *cobra.Command {
func newTenantCmd(_ io.Writer, _ io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "tenant",
Short: "Manage MinIO tenant(s)",
Expand Down

0 comments on commit 41ac8de

Please sign in to comment.