Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: skip MarkDrain when --skip-drain #136

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions cmd/draino/draino.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ func main() {
kubernetes.NewEventRecorder(cs),
kubernetes.WithLogger(log),
kubernetes.WithDrainBuffer(*drainBuffer),
kubernetes.WithConditionsFilter(*conditions))
kubernetes.WithConditionsFilter(*conditions),
kubernetes.WithSkipDrainEvent(*skipDrain))

if *dryRun {
h = cache.FilteringResourceEventHandler{
Expand All @@ -179,7 +180,8 @@ func main() {
kubernetes.NewEventRecorder(cs),
kubernetes.WithLogger(log),
kubernetes.WithDrainBuffer(*drainBuffer),
kubernetes.WithConditionsFilter(*conditions)),
kubernetes.WithConditionsFilter(*conditions),
kubernetes.WithSkipDrainEvent(*skipDrain)),
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/kubernetes/drainSchedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (d *DrainSchedules) DeleteSchedule(name string) {
if s, ok := d.schedules[name]; ok {
s.timer.Stop()
} else {
d.logger.Error("Failed schedule deletion", zap.String("key", name))
d.logger.Info("Schedule Not Found", zap.String("key", name))
}
delete(d.schedules, name)
}
Expand Down
6 changes: 6 additions & 0 deletions internal/kubernetes/drainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ func (d *APICordonDrainer) Uncordon(n *core.Node, mutators ...nodeMutatorFn) err

// MarkDrain set a condition on the node to mark that that drain is scheduled.
func (d *APICordonDrainer) MarkDrain(n *core.Node, when, finish time.Time, failed bool) error {
// Do nothing if draining is not enabled.
if d.skipDrain {
d.l.Debug("Skipping drain because draining is disabled")
return nil
}

nodeName := n.Name
// Refresh the node object
freshNode, err := d.c.CoreV1().Nodes().Get(nodeName, meta.GetOptions{})
Expand Down
12 changes: 12 additions & 0 deletions internal/kubernetes/eventhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,19 @@ type DrainingResourceEventHandler struct {
buffer time.Duration

conditions []SuppliedCondition
skipDrain bool
}

// DrainingResourceEventHandlerOption configures an DrainingResourceEventHandler.
type DrainingResourceEventHandlerOption func(d *DrainingResourceEventHandler)

// WithSkipDrainEvent configures if should skip drain in handler
func WithSkipDrainEvent(skipDrain bool) DrainingResourceEventHandlerOption {
return func(h *DrainingResourceEventHandler) {
h.skipDrain = skipDrain
}
}

// WithLogger configures a DrainingResourceEventHandler to use the supplied
// logger.
func WithLogger(l *zap.Logger) DrainingResourceEventHandlerOption {
Expand Down Expand Up @@ -167,6 +175,10 @@ func (h *DrainingResourceEventHandler) HandleNode(n *core.Node) {
h.cordon(n, badConditions)
}

if h.skipDrain {
return
}

// Let's ensure that a drain is scheduled
hasSChedule, failedDrain := h.drainScheduler.HasSchedule(n.GetName())
if !hasSChedule {
Expand Down