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

feat(playbook-k8s): node cordon, uncordon, drain #376

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions charts/playbooks-kubernetes/templates/cordon-node.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/flanksource/duty/main/schema/openapi/playbook.schema.json

{{- if and .Values.playbooks.enabled .Values.playbooks.cordonNode }}
---
apiVersion: mission-control.flanksource.com/v1
kind: Playbook
metadata:
name: kubernetes-cordon-node
spec:
title: Cordon Node
icon: k8s-node
category: Kubernetes
configs:
- agent: all
types:
- Kubernetes::Node

parameters:
- name: selector
Copy link
Member

Choose a reason for hiding this comment

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

I don't think select makes sense here, because we have already selected the node config item
Dry run on a cordon is probably also overkill - For a drain yeh it makes sense

label: 'Selector'
type: text
default: ""
- name: dry_run
label: 'Dry Run'
type: list
default: 'none'
properties:
options:
- label: none
value: none
- label: server
value: server
- label: client
value: client

runsOn:
- {{` "{{- if .agent }}{{.agent.id}}{{ else }}local{{ end }}" `}}

actions:
- name: Drain node
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- name: Drain node
- name: Cordon node

exec:
connections:
fromConfigItem: '$(.config.id)'
script: |
kubectl cordon $(.config.name) --selector=$(.params.selector | quote) --dry-run=$(.params.dry_run | quote)
{{- end}}
50 changes: 50 additions & 0 deletions charts/playbooks-kubernetes/templates/drain-node.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/flanksource/duty/main/schema/openapi/playbook.schema.json

{{- if and .Values.playbooks.enabled .Values.playbooks.drainNode }}
---
apiVersion: mission-control.flanksource.com/v1
kind: Playbook
metadata:
name: kubernetes-drain-node
spec:
title: Drain Node
icon: k8s-node
category: Kubernetes
configs:
- agent: all
types:
- Kubernetes::Node

parameters:
- name: delete_emptydir_data
label: 'Delete emptydir data'
type: text
Copy link
Member

Choose a reason for hiding this comment

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

these should be bools

default: "false"
- name: force
label: '--force'
type: text
default: "false"
- name: grace_period
label: 'Grace period'
type: text
default: "-1"
- name: timeout
label: 'Timeout'
type: text
default: "0s"
- name: selector
label: 'Selector'
type: text
default: ""

runsOn:
- {{` "{{- if .agent }}{{.agent.id}}{{ else }}local{{ end }}" `}}

actions:
- name: Drain node
exec:
connections:
fromConfigItem: '$(.config.id)'
script: |
kubectl drain $(.config.name) --delete-emptydir-data=$(.params.delete_emptydir_data) --force=$(.params.force) --grace-period=$(.params.grace_period) --timeout=$(.params.timeout) --selector=$(.params.selector)
{{- end}}
46 changes: 46 additions & 0 deletions charts/playbooks-kubernetes/templates/uncordon-node.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/flanksource/duty/main/schema/openapi/playbook.schema.json

{{- if and .Values.playbooks.enabled .Values.playbooks.uncordonNode }}
---
apiVersion: mission-control.flanksource.com/v1
kind: Playbook
metadata:
name: kubernetes-uncordon-node
spec:
title: Uncordon Node
icon: k8s-node
category: Kubernetes
configs:
- agent: all
types:
- Kubernetes::Node

parameters:
- name: selector
label: 'Selector'
type: text
default: ""
- name: dry_run
label: 'Dry Run'
type: list
default: 'none'
properties:
options:
- label: none
value: none
- label: server
value: server
- label: client
value: client

runsOn:
- {{` "{{- if .agent }}{{.agent.id}}{{ else }}local{{ end }}" `}}

actions:
- name: Uncordon node
exec:
connections:
fromConfigItem: '$(.config.id)'
script: |
kubectl uncordon $(.config.name) --selector=$(.params.selector | quote) --dry-run=$(.params.dry_run | quote)
{{- end}}
24 changes: 23 additions & 1 deletion charts/playbooks-kubernetes/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,20 @@
},
"playbooks": {
"additionalProperties": false,
"description": "yaml-language-server: $schema=values.schema.json",
"properties": {
"cleanupFailedPods": {
"default": true,
"required": [],
"title": "cleanupFailedPods",
"type": "boolean"
},
"cordonNode": {
"default": true,
"required": [],
"title": "cordonNode",
"type": "boolean"
},
"createDeployment": {
"default": true,
"required": [],
Expand All @@ -87,6 +94,12 @@
"title": "deployHelmChart",
"type": "boolean"
},
"drainNode": {
"default": true,
"required": [],
"title": "drainNode",
"type": "boolean"
},
"enabled": {
"default": true,
"description": "If this is set to false, no playbooks will be created",
Expand Down Expand Up @@ -130,6 +143,12 @@
"title": "scale",
"type": "boolean"
},
"uncordonNode": {
"default": true,
"required": [],
"title": "uncordonNode",
"type": "boolean"
},
"updateImage": {
"default": true,
"required": [],
Expand All @@ -156,7 +175,10 @@
"scale",
"updateImage",
"updateResources",
"deployHelmChart"
"deployHelmChart",
"drainNode",
"cordonNode",
"uncordonNode"
],
"title": "playbooks",
"type": "object"
Expand Down
3 changes: 3 additions & 0 deletions charts/playbooks-kubernetes/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ playbooks:
updateImage: true
updateResources: true
deployHelmChart: true
drainNode: true
cordonNode: true
uncordonNode: true

delete:
types:
Expand Down
Loading