Files
jenkins-libs/vars/kubeRolloutRestart.groovy
Dustin C. Hatch 4217811e35 kubeRolloutRestart: Add generic restart function
As its name implies, the `kubeRestartDeployment` function would only
restart pods managed by a Deployment.  In order to restart pods managed
by other controllers, such as StatefulSets or DaemonSets, I've created a
new function, `kubeRolloutRestart`.  To preserve backward compatibility,
the `kubeRestartDeployment` function delegates to this new function.
2025-10-11 12:38:12 -05:00

40 lines
712 B
Groovy

@groovy.transform.Field
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 kind = args?.kind
def namespace = args?.namespace
def name = args?.name
if (kind == null) {
kind = 'deployment'
}
if (name == null) {
name = env.JOB_NAME.split('/')[1]
}
if (namespace == null) {
namespace = name
}
podTemplate(yaml: POD_YAML) {
node(POD_LABEL) {
sh "kubectl rollout restart ${kind} -n ${namespace} ${name}"
}
}
}