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:
2025-10-11 11:57:25 -05:00
parent 917db648c7
commit 4217811e35
2 changed files with 44 additions and 29 deletions

View File

@@ -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 namespace = args?.namespace
def name = args?.name
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 deployment -n ${namespace} ${name}"
}
}
kubeRolloutRestart(
kind: 'deployment',
namespace: namespace,
name: name,
)
}

View 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}"
}
}
}