@@ -25,8 +25,6 @@ import (
2525 "strings"
2626 "time"
2727
28- lib "github.com/aerospike/aerospike-management-lib"
29-
3028 "github.com/go-logr/logr"
3129 admissionv1 "k8s.io/api/admission/v1"
3230 corev1 "k8s.io/api/core/v1"
@@ -72,6 +70,13 @@ func (ew *EvictionWebhook) isAerospikePod(pod *corev1.Pod) bool {
7270
7371// setEvictionBlockedAnnotation sets an annotation on the pod indicating eviction was blocked
7472func (ew * EvictionWebhook ) setEvictionBlockedAnnotation (ctx context.Context , pod * corev1.Pod ) error {
73+ // Check if annotation already exists, no update needed
74+ if pod .Annotations != nil {
75+ if _ , exists := pod .Annotations [EvictionBlockedAnnotation ]; exists {
76+ return nil
77+ }
78+ }
79+
7580 // Create a patch to add the annotation
7681 patch := client .MergeFrom (pod .DeepCopy ())
7782
@@ -128,14 +133,6 @@ func (ew *EvictionWebhook) Handle(w http.ResponseWriter, r *http.Request) {
128133 return
129134 }
130135
131- // Check namespace filtering
132- if ! ew .shouldEvaluateNamespace (admissionReview .Request .Namespace ) {
133- log .V (1 ).Info ("Namespace not in watch list, allowing eviction" , "namespace" , admissionReview .Request .Namespace )
134- ew .sendResponse (w , admissionReview , & response )
135-
136- return
137- }
138-
139136 // Process eviction request
140137 evictionResult := ew .processEvictionRequest (admissionReview , log )
141138 if evictionResult != nil {
@@ -167,23 +164,6 @@ func (ew *EvictionWebhook) isWebhookEnabled() bool {
167164 return found && strings .EqualFold (enable , "true" )
168165}
169166
170- // shouldEvaluateNamespace checks if the namespace should be evaluated
171- func (ew * EvictionWebhook ) shouldEvaluateNamespace (namespace string ) bool {
172- watchNs , err := asdbv1 .GetWatchNamespace ()
173- if err != nil {
174- ew .Log .Error (err , "Failed to get watch namespaces" )
175- return false
176- }
177-
178- if watchNs == "" {
179- return true // No namespace filtering
180- }
181-
182- nsList := strings .Split (watchNs , "," )
183-
184- return lib .ContainsString (nsList , namespace )
185- }
186-
187167// processEvictionRequest processes the eviction request and returns the response
188168func (ew * EvictionWebhook ) processEvictionRequest (admissionReview * admissionv1.AdmissionReview ,
189169 log logr.Logger ) * admissionv1.AdmissionResponse {
@@ -229,6 +209,7 @@ func (ew *EvictionWebhook) processEvictionRequest(admissionReview *admissionv1.A
229209 log .Info ("Blocking eviction of Aerospike pod" , "pod" , eviction .Name )
230210
231211 // Set annotation asynchronously (non-blocking)
212+ // TODO: do we really want async here?
232213 go ew .setEvictionBlockedAnnotationAsync (pod )
233214
234215 return & admissionv1.AdmissionResponse {
0 commit comments