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.
40 lines
712 B
Groovy
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}"
|
|
}
|
|
}
|
|
}
|