commit 5bdc9cd3fcd62f561631c21ca554c701ac9973ae Author: Dustin C. Hatch Date: Wed Mar 12 20:36:04 2025 -0500 kubeRestartDeployment: Add function The `kubeRestartDeployment` function restarts a Kubernetes deployment using `kubectl rollout restart`. This command is run in a dedicated pod, with the `kubectl` binary bind-mounted from the host. diff --git a/vars/kubeRestartDeployment.groovy b/vars/kubeRestartDeployment.groovy new file mode 100644 index 0000000..01e660a --- /dev/null +++ b/vars/kubeRestartDeployment.groovy @@ -0,0 +1,33 @@ +def POD_YAML = '''\ +spec: + containers: + - name: jnlp + volumeMounts: + - name: kubectl + mountPath: /bin/kubectl + readOnly: true + volumes: + - name: kubectl + hostPath: + path: /usr/bin/kubectl + type: File +''' + +def call(args) { + def namespace = args?.namespace + def name = args?.name + + if (name == null) { + name = env.JOB_NAME.split('/')[1] + } + + if (namespace == null) { + namespace = null + } + + podTemplate(yaml: POD_YAML) { + node(POD_LABEL) { + sh "kubectl rollout restart deployment -n ${namespace} ${name}" + } + } +}