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

WIP: Attempt at cordon but no drain #45

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,11 @@ draino_cordoned_nodes_total{result="failed"} 1
draino_drained_nodes_total{result="succeeded"} 1
draino_drained_nodes_total{result="failed"} 1
```

## Modes

### Dry Run
Draino can be run in dry run mode using the `--dry-run` flag.

### Cordon Only
Draino can also optionally be run in a mode where the nodes are only cordoned, and not drained. This can be achieved by using the `--no-drain` flag
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Period at the end of this sentence.

3 changes: 3 additions & 0 deletions cmd/draino/draino.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ func main() {
drainBuffer = app.Flag("drain-buffer", "Minimum time between starting each drain. Nodes are always cordoned immediately.").Default(kubernetes.DefaultDrainBuffer.String()).Duration()
nodeLabels = app.Flag("node-label", "Only nodes with this label will be eligible for cordoning and draining. May be specified multiple times.").PlaceHolder("KEY=VALUE").StringMap()

drain = app.Flag("drain", "Drain the nodes").Default("true").Bool()

evictDaemonSetPods = app.Flag("evict-daemonset-pods", "Evict pods that were created by an extant DaemonSet.").Bool()
evictLocalStoragePods = app.Flag("evict-emptydir-pods", "Evict pods with local storage, i.e. with emptyDir volumes.").Bool()
evictUnreplicatedPods = app.Flag("evict-unreplicated-pods", "Evict pods that were not created by a replication controller.").Bool()
Expand Down Expand Up @@ -121,6 +123,7 @@ func main() {
kubernetes.NewAPICordonDrainer(cs,
kubernetes.MaxGracePeriod(*maxGracePeriod),
kubernetes.EvictionHeadroom(*evictionHeadroom),
kubernetes.WithDrain(*drain),
kubernetes.WithPodFilter(kubernetes.NewPodFilters(pf...))),
kubernetes.NewEventRecorder(cs),
kubernetes.WithLogger(log),
Expand Down
17 changes: 17 additions & 0 deletions internal/kubernetes/drainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const (
DefaultEvictionOverhead time.Duration = 30 * time.Second

kindDaemonSet = "DaemonSet"

DefaultWithDrain = true
)

type errTimeout struct{}
Expand Down Expand Up @@ -89,6 +91,7 @@ type APICordonDrainer struct {

maxGracePeriod time.Duration
evictionHeadroom time.Duration
withDrain bool
}

// SuppliedCondition defines the condition will be watched.
Expand Down Expand Up @@ -126,6 +129,13 @@ func WithPodFilter(f PodFilterFunc) APICordonDrainerOption {
}
}

// WithDrain determines if we're actually going to drain nodes
func WithDrain(b bool) APICordonDrainerOption {
return func(d *APICordonDrainer) {
d.withDrain = b
}
}

// NewAPICordonDrainer returns a CordonDrainer that cordons and drains nodes via
// the Kubernetes API.
func NewAPICordonDrainer(c kubernetes.Interface, ao ...APICordonDrainerOption) *APICordonDrainer {
Expand All @@ -134,6 +144,7 @@ func NewAPICordonDrainer(c kubernetes.Interface, ao ...APICordonDrainerOption) *
filter: NewPodFilters(),
maxGracePeriod: DefaultMaxGracePeriod,
evictionHeadroom: DefaultEvictionOverhead,
withDrain: DefaultWithDrain,
}
for _, o := range ao {
o(d)
Expand Down Expand Up @@ -163,6 +174,12 @@ func (d *APICordonDrainer) Cordon(n *core.Node) error {

// Drain the supplied node. Evicts the node of all but mirror and DaemonSet pods.
func (d *APICordonDrainer) Drain(n *core.Node) error {

// Do nothing
if !d.withDrain {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file just needs a gofmt run on it.

return nil
}

pods, err := d.getPods(n.GetName())
if err != nil {
return errors.Wrapf(err, "cannot get pods for node %s", n.GetName())
Expand Down