@@ -104,7 +104,7 @@ type priorityReservation struct {
104104func newTierPriorityTracker () * tierPriorityTracker {
105105 return & tierPriorityTracker {
106106 pendingPriorities : make (map [int32 ]* priorityReservation ),
107- validationTimeout : 30 * time .Second , // timeout for waiting for other validations
107+ validationTimeout : 5 * time .Second , // timeout for waiting for other validations
108108 creationTimeout : 60 * time .Second , // timeout for waiting for actual K8s creation
109109 }
110110}
@@ -120,7 +120,7 @@ func (t *tierPriorityTracker) reservePriorityForValidation(priority int32, tierN
120120 if existing , exists := t .pendingPriorities [priority ]; exists {
121121 // Check if the existing reservation has timed out
122122 if time .Since (existing .createdAt ) > t .creationTimeout {
123- klog .Warningf ( "Tier priority %d reservation for %s has timed out, allowing new reservation" , priority , existing .tierName )
123+ klog .V ( 2 ). InfoS ( "Tier priority reservation for has timed out, allowing new reservation" , " priority" , priority , "tier" , existing .tierName )
124124 close (existing .waitChan )
125125 delete (t .pendingPriorities , priority )
126126 } else {
@@ -281,12 +281,22 @@ func NewNetworkPolicyValidator(networkPolicyController *NetworkPolicyController)
281281 vr .RegisterGroupValidator (& gv )
282282 vr .RegisterAdminNetworkPolicyValidator (& av )
283283
284- // Start cleanup routine for expired reservations from the tierValidator
285- go tv .startCleanupRoutine ()
286-
284+ // Set up Tier event handlers to notify validator when Tiers are actually created/deleted
285+ networkPolicyController .SetupTierEventHandlersForValidator (& vr )
287286 return & vr
288287}
289288
289+ // Run starts the background routines for the NetworkPolicyValidator.
290+ func (v * NetworkPolicyValidator ) Run (stopCh <- chan struct {}) {
291+ // Start cleanup routine for expired reservations from the tierValidator
292+ for _ , val := range v .tierValidators {
293+ if tv , ok := val .(* tierValidator ); ok {
294+ go tv .startCleanupRoutine (stopCh )
295+ break
296+ }
297+ }
298+ }
299+
290300// Validate function validates a Group, ClusterGroup, Tier or Antrea Policy object
291301func (v * NetworkPolicyValidator ) Validate (ar * admv1.AdmissionReview ) * admv1.AdmissionResponse {
292302 var result * metav1.Status
@@ -627,7 +637,7 @@ func (v *NetworkPolicyValidator) validateTier(curTier, oldTier *crdv1beta1.Tier,
627637}
628638
629639// startCleanupRoutine starts a background routine to clean up expired priority reservations
630- func (t * tierValidator ) startCleanupRoutine () {
640+ func (t * tierValidator ) startCleanupRoutine (stopCh <- chan struct {} ) {
631641 if t .priorityTracker == nil {
632642 klog .ErrorS (nil , "Priority tracker is nil, cannot start cleanup routine" )
633643 return
@@ -636,8 +646,14 @@ func (t *tierValidator) startCleanupRoutine() {
636646 ticker := time .NewTicker (30 * time .Second ) // Check every 30 seconds
637647 defer ticker .Stop ()
638648
639- for range ticker .C {
640- t .priorityTracker .cleanupExpiredReservations ()
649+ for {
650+ select {
651+ case <- ticker .C :
652+ t .priorityTracker .cleanupExpiredReservations ()
653+ case <- stopCh :
654+ klog .InfoS ("Stopping Tier priority tracker cleanup routine" )
655+ return
656+ }
641657 }
642658}
643659
0 commit comments