Skip to content

Commit 30f663c

Browse files
authored
Add ignore annotation (#55)
Signed-off-by: Thibault Gérondal <thibault@initia.cloud>
1 parent a62093c commit 30f663c

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ Resume:
2424
kubectl annotate ns/my-namespace k8s-pause/suspend=false --overwrite
2525
```
2626

27+
## `k8s-pause/ignore` annotation
28+
29+
You can define an annotation on a pod to ensure it is ignored by the controller
30+
and so never suspended. Use the following annotation:
31+
32+
```
33+
k8s-pause/ignore: "true"
34+
```
35+
2736
## Resume profiles
2837

2938
It is possible to define a set of pods which are allowed to start while a namespace is not paused.

controllers/namespace_controller.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import (
4141

4242
const (
4343
previousSchedulerName = "k8s-pause/previousScheduler"
44+
ignoreAnnotation = "k8s-pause/ignore"
4445
)
4546

4647
// NamespaceReconciler reconciles a Namespace object
@@ -145,6 +146,10 @@ func (r *NamespaceReconciler) resume(ctx context.Context, ns corev1.Namespace, p
145146
}
146147

147148
for _, pod := range list.Items {
149+
if ignore, ok := pod.Annotations[ignoreAnnotation]; ok && ignore == "true" {
150+
continue
151+
}
152+
148153
if profile != nil {
149154
if !matchesResumeProfile(pod, *profile) {
150155
continue
@@ -226,6 +231,10 @@ func (r *NamespaceReconciler) suspend(ctx context.Context, ns corev1.Namespace,
226231
}
227232

228233
for _, pod := range list.Items {
234+
if ignore, ok := pod.Annotations[ignoreAnnotation]; ok && ignore == "true" {
235+
continue
236+
}
237+
229238
if err := r.suspendPod(ctx, pod, logger); err != nil {
230239
logger.Error(err, "failed to suspend pod", "pod", pod.Name)
231240
continue

0 commit comments

Comments
 (0)