Skip to content

Commit

Permalink
Merge pull request #2 from deitch/configurable-daemonsets
Browse files Browse the repository at this point in the history
Provide option to not ignore DaemonSets in kube nodes
  • Loading branch information
deitch authored Feb 5, 2019
2 parents 5ee7675 + a3c722b commit c96c1fe
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,5 @@ ASG Roller takes its configuration via environment variables. All environment va

* `ROLLER_ASG`: comma-separated list of auto-scaling groups that should be managed.
* `ROLLER_KUBERNETES`: If set to `true`, will check if a new node is ready via-a-vis Kubernetes before declaring it "ready", and will drain an old node before eliminating it. Defaults to `true` when running in Kubernetes as a pod, `false` otherwise.
* `ROLLER_IGNORE_DAEMONSETS`: If set to `false`, will not reclaim a node until there are no DaemonSets running on the node; if set to `true` (default), will reclaim node when all regular pods are drained off, but will ignore the presence of DaemonSets, which should be present on every node anyways. Normally, you want this set to `true`, which is the default.
* `KUBECONFIG`: Path to kubernetes config file for authenticating to the kubernetes cluster. Required only if `ROLLER_KUBERNETES` is `true` and we are not operating in a kubernetes cluster.
9 changes: 5 additions & 4 deletions kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import (
)

type kubernetesReadiness struct {
clientset *kubernetes.Clientset
clientset *kubernetes.Clientset
ignoreDaemonSets bool
}

func (k *kubernetesReadiness) getUnreadyCount(hostnames []string, ids []string) (int, error) {
Expand Down Expand Up @@ -67,7 +68,7 @@ func (k *kubernetesReadiness) prepareTermination(hostnames []string, ids []strin
}
// set options and drain nodes
err = drain.Drain(k.clientset, []*corev1.Node{node}, &drain.DrainOptions{
IgnoreDaemonsets: true,
IgnoreDaemonsets: k.ignoreDaemonSets,
GracePeriodSeconds: -1,
Force: true,
})
Expand Down Expand Up @@ -127,13 +128,13 @@ func homeDir() string {
return os.Getenv("USERPROFILE") // windows
}

func kubeGetReadinessHandler() (readiness, error) {
func kubeGetReadinessHandler(ignoreDaemonSets bool) (readiness, error) {
clientset, err := kubeGetClientset()
if err != nil {
log.Fatalf("Error getting kubernetes connection: %v", err)
}
if clientset == nil {
return nil, nil
}
return &kubernetesReadiness{clientset: clientset}, nil
return &kubernetesReadiness{clientset: clientset, ignoreDaemonSets: ignoreDaemonSets}, nil
}
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ func main() {
log.Fatal("Must supply at least one ASG in ROLLER_ASG environment variable")
}

// get config env
ignoreDaemonSets := os.Getenv("ROLLER_IGNORE_DAEMONSETS") != "false"
// get a kube connection
readinessHandler, err := kubeGetReadinessHandler()
readinessHandler, err := kubeGetReadinessHandler(ignoreDaemonSets)
if err != nil {
log.Fatalf("Error getting kubernetes readiness handler when required: %v", err)
}
Expand Down

0 comments on commit c96c1fe

Please sign in to comment.