NodeDelete: add NodeDeleteOpts
This commit is contained in:
parent
c809767448
commit
a37b01c5b9
@ -14,6 +14,7 @@
|
||||
- `pkg/cluster` is now `pkg/client`
|
||||
- `ClusterCreate` and `NodeCreate` don't start the entities (containers) anymore
|
||||
- `ClusterRun` and `NodeRun` orchestrate the new Create and Start functionality
|
||||
- `NodeDelete` now takes an additional `NodeDeleteOpts` struct to toggle specific steps
|
||||
- New config flow: CLIConfig (SimpleConfig) -> ClusterConfig -> Cluster + Opts
|
||||
|
||||
#### CLI
|
||||
|
@ -48,7 +48,7 @@ func NewCmdNodeDelete() *cobra.Command {
|
||||
log.Infoln("No nodes found")
|
||||
} else {
|
||||
for _, node := range nodes {
|
||||
if err := client.NodeDelete(cmd.Context(), runtimes.SelectedRuntime, node); err != nil {
|
||||
if err := client.NodeDelete(cmd.Context(), runtimes.SelectedRuntime, node, k3d.NodeDeleteOpts{SkipRegistryCheck: true}); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ func NewCmdRegistryDelete() *cobra.Command {
|
||||
log.Infoln("No nodes found")
|
||||
} else {
|
||||
for _, node := range nodes {
|
||||
if err := client.NodeDelete(cmd.Context(), runtimes.SelectedRuntime, node); err != nil {
|
||||
if err := client.NodeDelete(cmd.Context(), runtimes.SelectedRuntime, node, k3d.NodeDeleteOpts{SkipLBUpdate: true}); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
}
|
||||
|
@ -539,7 +539,7 @@ func ClusterDelete(ctx context.Context, runtime k3drt.Runtime, cluster *k3d.Clus
|
||||
|
||||
failed := 0
|
||||
for _, node := range cluster.Nodes {
|
||||
if err := runtime.DeleteNode(ctx, node); err != nil {
|
||||
if err := NodeDelete(ctx, runtime, node, k3d.NodeDeleteOpts{SkipLBUpdate: true}); err != nil {
|
||||
log.Warningf("Failed to delete node '%s': Try to delete it manually", node.Name)
|
||||
failed++
|
||||
continue
|
||||
|
@ -287,13 +287,20 @@ func NodeCreate(ctx context.Context, runtime runtimes.Runtime, node *k3d.Node, c
|
||||
}
|
||||
|
||||
// NodeDelete deletes an existing node
|
||||
func NodeDelete(ctx context.Context, runtime runtimes.Runtime, node *k3d.Node) error {
|
||||
func NodeDelete(ctx context.Context, runtime runtimes.Runtime, node *k3d.Node, opts k3d.NodeDeleteOpts) error {
|
||||
|
||||
// registry: only delete, if not connected to other networks
|
||||
if !opts.SkipRegistryCheck && node.Role == k3d.RegistryRole {
|
||||
log.Debugln("NodeDelete special case: registry -> not yet implemented")
|
||||
}
|
||||
|
||||
// delete node
|
||||
if err := runtime.DeleteNode(ctx, node); err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
|
||||
if node.Role == k3d.ServerRole || node.Role == k3d.AgentRole {
|
||||
// update the server loadbalancer
|
||||
if !opts.SkipLBUpdate && (node.Role == k3d.ServerRole || node.Role == k3d.AgentRole) {
|
||||
cluster, err := ClusterGet(ctx, runtime, &k3d.Cluster{Name: node.Labels[k3d.LabelClusterName]})
|
||||
if err != nil {
|
||||
log.Errorf("Failed to find cluster for node '%s'", node.Name)
|
||||
|
@ -78,6 +78,7 @@ func RegistryCreate(ctx context.Context, runtime runtimes.Runtime, reg *k3d.Regi
|
||||
|
||||
// setup the node labels
|
||||
registryNode.Labels = map[string]string{
|
||||
k3d.LabelClusterName: reg.ClusterRef,
|
||||
k3d.LabelRole: string(k3d.RegistryRole),
|
||||
k3d.LabelRegistryHost: reg.ExposureOpts.Host, // TODO: docker machine host?
|
||||
k3d.LabelRegistryHostIP: reg.ExposureOpts.Binding.HostIP,
|
||||
|
@ -241,6 +241,7 @@ func TransformSimpleToClusterConfig(ctx context.Context, runtime runtimes.Runtim
|
||||
return nil, fmt.Errorf("Failed to get port for registry: %+v", err)
|
||||
}
|
||||
clusterCreateOpts.Registries.Create = &k3d.Registry{
|
||||
ClusterRef: newCluster.Name,
|
||||
Host: fmt.Sprintf("%s-%s-registry", k3d.DefaultObjectNamePrefix, newCluster.Name),
|
||||
Image: fmt.Sprintf("%s:%s", k3d.DefaultRegistryImageRepo, k3d.DefaultRegistryImageTag),
|
||||
ExposureOpts: *regPort,
|
||||
|
@ -222,6 +222,12 @@ type NodeStartOpts struct {
|
||||
NodeHooks []NodeHook `yaml:"nodeHooks,omitempty" json:"nodeHooks,omitempty"`
|
||||
}
|
||||
|
||||
// NodeDeleteOpts describes a set of options one can set when deleting a node
|
||||
type NodeDeleteOpts struct {
|
||||
SkipLBUpdate bool // skip updating the loadbalancer
|
||||
SkipRegistryCheck bool // skip checking if this is a registry (and act accordingly)
|
||||
}
|
||||
|
||||
// NodeHookAction is an interface to implement actions that should trigger at specific points of the node lifecycle
|
||||
type NodeHookAction interface {
|
||||
Run(ctx context.Context, node *Node) error
|
||||
|
Loading…
Reference in New Issue
Block a user