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.
This commit is contained in:
@@ -1,34 +1,10 @@
|
|||||||
@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 call(args) {
|
||||||
def namespace = args?.namespace
|
def namespace = args?.namespace
|
||||||
def name = args?.name
|
def name = args?.name
|
||||||
|
|
||||||
if (name == null) {
|
kubeRolloutRestart(
|
||||||
name = env.JOB_NAME.split('/')[1]
|
kind: 'deployment',
|
||||||
}
|
namespace: namespace,
|
||||||
|
name: name,
|
||||||
if (namespace == null) {
|
)
|
||||||
namespace = name
|
|
||||||
}
|
|
||||||
|
|
||||||
podTemplate(yaml: POD_YAML) {
|
|
||||||
node(POD_LABEL) {
|
|
||||||
sh "kubectl rollout restart deployment -n ${namespace} ${name}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
39
vars/kubeRolloutRestart.groovy
Normal file
39
vars/kubeRolloutRestart.groovy
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
@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}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user