Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#133 from iamjanr/EOS-11307
Browse files Browse the repository at this point in the history
[EOS-11307] Eliminar el container si esta creado al ppio de la ejecución
  • Loading branch information
iamjanr authored Jun 1, 2023
2 parents a9c4266 + 4fee981 commit 729f0de
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
8 changes: 8 additions & 0 deletions pkg/cluster/createoption.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ func CreateWithAvoidCreation(avoidCreation bool) CreateOption {
})
}

// CreateWithWaitForceDelete removes local cluster container
func CreateWithForceDelete(forceDelete bool) CreateOption {
return createOptionAdapter(func(o *internalcreate.ClusterOptions) error {
o.ForceDelete = forceDelete
return nil
})
}

// CreateWithWaitForReady configures a maximum wait time for the control plane
// node(s) to be ready. By default no waiting is performed
func CreateWithWaitForReady(waitTime time.Duration) CreateOption {
Expand Down
10 changes: 9 additions & 1 deletion pkg/cluster/internal/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ type ClusterOptions struct {
DescriptorPath string
MoveManagement bool
AvoidCreation bool
// Force local container delete before creating the cluster if it already exists
ForceDelete bool
// NodeImage overrides the nodes' images in Config if non-zero
NodeImage string
Retain bool
Expand All @@ -85,7 +87,13 @@ func Cluster(logger log.Logger, p providers.Provider, opts *ClusterOptions) erro

// Check if the cluster name already exists
if err := alreadyExists(p, opts.Config.Name); err != nil {
return err
if opts.ForceDelete {
// Delete current cluster container
_ = delete.Cluster(nil, p, opts.Config.Name, "")
} else {
return errors.Errorf("A cluster with the name %q already exists \n"+
"Please use a different cluster name or delete the current container with --delete-previous flag", opts.Config.Name)
}
}

// warn if cluster name might typically be too long
Expand Down
8 changes: 8 additions & 0 deletions pkg/cmd/kind/create/cluster/createcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type flagpole struct {
DescriptorPath string
MoveManagement bool
AvoidCreation bool
ForceDelete bool
}

const clusterDefaultPath = "./cluster.yaml"
Expand Down Expand Up @@ -132,6 +133,12 @@ func NewCommand(logger log.Logger, streams cmd.IOStreams) *cobra.Command {
false,
"by setting this flag the worker cluster won't be created",
)
cmd.Flags().BoolVar(
&flags.ForceDelete,
"delete-previous",
false,
"by setting this flag the local cluster will be deleted",
)

return cmd
}
Expand Down Expand Up @@ -197,6 +204,7 @@ func runE(logger log.Logger, streams cmd.IOStreams, flags *flagpole) error {
cluster.CreateWithRetain(flags.Retain),
cluster.CreateWithMove(flags.MoveManagement),
cluster.CreateWithAvoidCreation(flags.AvoidCreation),
cluster.CreateWithForceDelete(flags.ForceDelete),
cluster.CreateWithWaitForReady(flags.Wait),
cluster.CreateWithKubeconfigPath(flags.Kubeconfig),
cluster.CreateWithDisplayUsage(true),
Expand Down

0 comments on commit 729f0de

Please sign in to comment.