diff --git a/README.md b/README.md index ab02b0c..493a528 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/kubernetes.go b/kubernetes.go index 0f6af6c..0645dad 100644 --- a/kubernetes.go +++ b/kubernetes.go @@ -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) { @@ -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, }) @@ -127,7 +128,7 @@ 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) @@ -135,5 +136,5 @@ func kubeGetReadinessHandler() (readiness, error) { if clientset == nil { return nil, nil } - return &kubernetesReadiness{clientset: clientset}, nil + return &kubernetesReadiness{clientset: clientset, ignoreDaemonSets: ignoreDaemonSets}, nil } diff --git a/main.go b/main.go index 54b7061..aeb5aa1 100644 --- a/main.go +++ b/main.go @@ -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) }