Skip to content

Commit 005ed30

Browse files
committed
removing namespace filtering from eviction webhook handle, relying on configurations.
1 parent 02fc47b commit 005ed30

File tree

4 files changed

+26
-44
lines changed

4 files changed

+26
-44
lines changed

api/v1/utils.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -664,18 +664,3 @@ func IsPathParentOrSame(dir1, dir2 string) bool {
664664
// Paths are unrelated.
665665
return false
666666
}
667-
668-
// GetWatchNamespace returns the Namespace the operator should be watching for changes
669-
func GetWatchNamespace() (string, error) {
670-
// WatchNamespaceEnvVar is the constant for env variable WATCH_NAMESPACE
671-
// which specifies the Namespace to watch.
672-
// An empty value means the operator is running with cluster scope.
673-
var watchNamespaceEnvVar = "WATCH_NAMESPACE"
674-
675-
ns, found := os.LookupEnv(watchNamespaceEnvVar)
676-
if !found {
677-
return "", fmt.Errorf("%s must be set", watchNamespaceEnvVar)
678-
}
679-
680-
return ns, nil
681-
}

cmd/main.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"crypto/tls"
55
"flag"
6+
"fmt"
67
"os"
78
"path/filepath"
89
"strconv"
@@ -199,7 +200,7 @@ func main() {
199200
})
200201
}
201202

202-
watchNs, err := asdbv1.GetWatchNamespace()
203+
watchNs, err := getWatchNamespace()
203204
if err != nil {
204205
setupLog.Error(err, "Failed to get watch namespace")
205206
os.Exit(1)
@@ -397,6 +398,21 @@ func main() {
397398
eventBroadcaster.Shutdown()
398399
}
399400

401+
// getWatchNamespace returns the Namespace the operator should be watching for changes
402+
func getWatchNamespace() (string, error) {
403+
// WatchNamespaceEnvVar is the constant for env variable WATCH_NAMESPACE
404+
// which specifies the Namespace to watch.
405+
// An empty value means the operator is running with cluster scope.
406+
var watchNamespaceEnvVar = "WATCH_NAMESPACE"
407+
408+
ns, found := os.LookupEnv(watchNamespaceEnvVar)
409+
if !found {
410+
return "", fmt.Errorf("%s must be set", watchNamespaceEnvVar)
411+
}
412+
413+
return ns, nil
414+
}
415+
400416
// getEventBurstSize returns the burst size of events that can be handled in the cluster
401417
func getEventBurstSize() int {
402418
// EventBurstSizeEnvVar is the constant for env variable EVENT_BURST_SIZE

internal/webhook/general/eviction_webhook.go

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -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
7472
func (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
188168
func (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{

test/cluster/podspec_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ var _ = Describe(
523523
},
524524
)
525525

526-
FIt(
526+
It(
527527
"Should fail adding reserved annotations",
528528
func() {
529529
aeroCluster := createDummyAerospikeCluster(

0 commit comments

Comments
 (0)