Skip to content

Commit 822d6de

Browse files
wandera-ciJoelSpeed
authored andcommitted
Add possibility to change drain command parameters (#9)
* 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
1 parent 36309f4 commit 822d6de

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ To achieve this, add the following flag to your Kubelet:
4141
--node-labels="node-role.kubernetes.io/spot-worker=true"
4242
```
4343

44+
#### Configuration
45+
46+
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`.
47+
```yaml
48+
env:
49+
- name: DRAIN_PARAMETERS
50+
value: '--grace-period=120 --force --ignore-daemonsets --delete-local-data'
51+
```
52+
4453
## Related
4554
- [K8s Spot Rescheduler](https://github.com/pusher/k8s-spot-rescheduler): Move nodes from on-demand instances to spot instances when space is available.
4655

deploy/daemonset.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ spec:
2323
valueFrom:
2424
fieldRef:
2525
fieldPath: spec.nodeName
26+
# Parameters to drain commmand can be adjusted
27+
- name: DRAIN_PARAMETERS
28+
value: '--grace-period=120 --force --ignore-daemonsets'
2629
resources:
2730
requests:
2831
cpu: 5m

docker_entrypoint.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ def main():
1313

1414
node_name = getenv('NODE_NAME')
1515

16+
drain_parameters = getenv('DRAIN_PARAMETERS', '--grace-period=120 --force --ignore-daemonsets')
17+
1618
print('Watching for termination notice on node %s' % node_name)
1719

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

2930
print("Draining node: %s" % node_name)
3031
result = call(kube_command)

0 commit comments

Comments
 (0)