Skip to content

Commit

Permalink
Add ignore annotation (#55)
Browse files Browse the repository at this point in the history
Signed-off-by: Thibault Gérondal <[email protected]>
  • Loading branch information
Tycale authored Jun 12, 2024
1 parent a62093c commit 30f663c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ Resume:
kubectl annotate ns/my-namespace k8s-pause/suspend=false --overwrite
```

## `k8s-pause/ignore` annotation

You can define an annotation on a pod to ensure it is ignored by the controller
and so never suspended. Use the following annotation:

```
k8s-pause/ignore: "true"
```

## Resume profiles

It is possible to define a set of pods which are allowed to start while a namespace is not paused.
Expand Down
9 changes: 9 additions & 0 deletions controllers/namespace_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (

const (
previousSchedulerName = "k8s-pause/previousScheduler"
ignoreAnnotation = "k8s-pause/ignore"
)

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

for _, pod := range list.Items {
if ignore, ok := pod.Annotations[ignoreAnnotation]; ok && ignore == "true" {
continue
}

if profile != nil {
if !matchesResumeProfile(pod, *profile) {
continue
Expand Down Expand Up @@ -226,6 +231,10 @@ func (r *NamespaceReconciler) suspend(ctx context.Context, ns corev1.Namespace,
}

for _, pod := range list.Items {
if ignore, ok := pod.Annotations[ignoreAnnotation]; ok && ignore == "true" {
continue
}

if err := r.suspendPod(ctx, pod, logger); err != nil {
logger.Error(err, "failed to suspend pod", "pod", pod.Name)
continue
Expand Down

0 comments on commit 30f663c

Please sign in to comment.