Skip to content

Commit

Permalink
Add possibility to change drain command parameters (#9)
Browse files Browse the repository at this point in the history
* Add possibility to change drain command parameters

* fixup! Add possibility to change drain command parameters

* fixup! Add possibility to change drain command parameters

* fixup! Add possibility to change drain command parameters

* fixup! Add possibility to change drain command parameters
  • Loading branch information
wandera-ci authored and JoelSpeed committed Jun 14, 2019
1 parent 36309f4 commit 822d6de
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ To achieve this, add the following flag to your Kubelet:
--node-labels="node-role.kubernetes.io/spot-worker=true"
```

#### Configuration

To define any custom parameters to the drain command you can use `DRAIN_PARAMETERS` environment property. If not defined, default parameters are `--grace-period=120 --force --ignore-daemonsets`.
```yaml
env:
- name: DRAIN_PARAMETERS
value: '--grace-period=120 --force --ignore-daemonsets --delete-local-data'
```
## Related
- [K8s Spot Rescheduler](https://github.com/pusher/k8s-spot-rescheduler): Move nodes from on-demand instances to spot instances when space is available.
Expand Down
3 changes: 3 additions & 0 deletions deploy/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ spec:
valueFrom:
fieldRef:
fieldPath: spec.nodeName
# Parameters to drain commmand can be adjusted
- name: DRAIN_PARAMETERS
value: '--grace-period=120 --force --ignore-daemonsets'
resources:
requests:
cpu: 5m
Expand Down
7 changes: 4 additions & 3 deletions docker_entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def main():

node_name = getenv('NODE_NAME')

drain_parameters = getenv('DRAIN_PARAMETERS', '--grace-period=120 --force --ignore-daemonsets')

print('Watching for termination notice on node %s' % node_name)

counter = 0
Expand All @@ -22,9 +24,8 @@ def main():
"http://169.254.169.254/latest/meta-data/spot/termination-time"
)
if response.status_code == 200:
kube_command = ['kubectl', 'drain', node_name,
'--grace-period=120', '--force',
'--ignore-daemonsets']
kube_command = ['kubectl', 'drain', node_name]
kube_command += drain_parameters.split()

print("Draining node: %s" % node_name)
result = call(kube_command)
Expand Down

0 comments on commit 822d6de

Please sign in to comment.