Skip to content

Commit

Permalink
revert optional command in retire
Browse files Browse the repository at this point in the history
  • Loading branch information
YZ775 committed Nov 11, 2024
1 parent 8835089 commit be6f34e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 47 deletions.
8 changes: 0 additions & 8 deletions cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,6 @@ const DefaultRepairHealthCheckCommandTimeoutSeconds = 30
const DefaultRepairCommandTimeoutSeconds = 30
const DefaultRepairSuccessCommandTimeoutSeconds = 30

type Retire struct {
OptionalCommand []string `json:"optional_command,omitempty"`
OptionalCommandTimeoutSeconds *int `json:"optional_command_timeout_seconds,omitempty"`
}

const DefaultRetireOptionalCommandTimeoutSeconds = 30

// Options is a set of optional parameters for k8s components.
type Options struct {
Etcd EtcdParams `json:"etcd"`
Expand All @@ -353,7 +346,6 @@ type Cluster struct {
DNSService string `json:"dns_service"`
Reboot Reboot `json:"reboot"`
Repair Repair `json:"repair"`
Retire Retire `json:"retire"`
Options Options `json:"options"`
}

Expand Down
3 changes: 0 additions & 3 deletions mtest/cke-cluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ repair:
need_drain: true
watch_seconds: 30
health_check_command: ["sh", "-c", "test -f /tmp/mtest-repair-$1 && echo true", "health_check"]
retire:
optional_command: ["true"]
optional_command_timeout_seconds: 30
options:
kube-api:
extra_binds:
Expand Down
41 changes: 5 additions & 36 deletions op/kube_node_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import (
"context"
"fmt"
"strings"
"time"

"github.com/cybozu-go/cke"
"github.com/cybozu-go/well"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand All @@ -18,13 +16,12 @@ import (
type kubeNodeRemove struct {
apiserver *cke.Node
nodes []*corev1.Node
config *cke.Retire
done bool
}

// KubeNodeRemoveOp removes k8s Node resources.
func KubeNodeRemoveOp(apiserver *cke.Node, nodes []*corev1.Node, config *cke.Retire) cke.Operator {
return &kubeNodeRemove{apiserver: apiserver, nodes: nodes, config: config}
func KubeNodeRemoveOp(apiserver *cke.Node, nodes []*corev1.Node) cke.Operator {
return &kubeNodeRemove{apiserver: apiserver, nodes: nodes}
}

func (o *kubeNodeRemove) Name() string {
Expand All @@ -37,12 +34,7 @@ func (o *kubeNodeRemove) NextCommand() cke.Commander {
}

o.done = true
return nodeRemoveCommand{
o.apiserver,
o.nodes,
o.config.OptionalCommand,
o.config.OptionalCommandTimeoutSeconds,
}
return nodeRemoveCommand{o.apiserver, o.nodes}
}

func (o *kubeNodeRemove) Targets() []string {
Expand All @@ -52,10 +44,8 @@ func (o *kubeNodeRemove) Targets() []string {
}

type nodeRemoveCommand struct {
apiserver *cke.Node
nodes []*corev1.Node
optionalCommand []string
optionalCommandTimeoutSeconds *int
apiserver *cke.Node
nodes []*corev1.Node
}

func (c nodeRemoveCommand) Run(ctx context.Context, inf cke.Infrastructure, _ string) error {
Expand Down Expand Up @@ -87,27 +77,6 @@ func (c nodeRemoveCommand) Run(ctx context.Context, inf cke.Infrastructure, _ st
return fmt.Errorf("failed to patch node %s: %v", n.Name, err)
}
}
if len(c.optionalCommand) != 0 {
err := func() error {
ctx := ctx
timeout := cke.DefaultRetireOptionalCommandTimeoutSeconds
if c.optionalCommandTimeoutSeconds != nil {
timeout = *c.optionalCommandTimeoutSeconds
}
if timeout != 0 {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(ctx, time.Second*time.Duration(timeout))
defer cancel()
}
args := append(c.optionalCommand[1:], n.Name)
command := well.CommandContext(ctx, c.optionalCommand[0], args...)
return command.Run()
}()
if err != nil {
return fmt.Errorf("failed to execute optional command in retirement %s: %v", n.Name, err)
}
}

err = nodesAPI.Delete(ctx, n.Name, metav1.DeleteOptions{})
if err != nil {
return fmt.Errorf("failed to delete node %s: %v", n.Name, err)
Expand Down

0 comments on commit be6f34e

Please sign in to comment.