@@ -2386,14 +2386,12 @@ func shouldCreatePDBForNodePool(hnp *HumioNodePool) bool {
2386
2386
func (r * HumioClusterReconciler ) reconcilePodDisruptionBudgets (ctx context.Context , humioNodePools HumioNodePoolList ) (ctrl.Result , error ) {
2387
2387
r .Log .Info ("reconciling pod disruption budgets" )
2388
2388
2389
- // Handle PDBs for all node pools (including the default pool from NodeCount)
2390
2389
for _ , pool := range humioNodePools .Items {
2391
2390
if err := r .reconcileSinglePDB (ctx , pool ); err != nil {
2392
2391
return ctrl.Result {}, fmt .Errorf ("failed to reconcile PDB for node pool %s: %w" , pool .GetNodePoolName (), err )
2393
2392
}
2394
2393
}
2395
2394
2396
- // Clean up any orphaned PDBs
2397
2395
if err := r .cleanupOrphanedPDBs (ctx , humioNodePools ); err != nil {
2398
2396
return ctrl.Result {}, fmt .Errorf ("failed to cleanup orphaned PDBs: %w" , err )
2399
2397
}
@@ -2410,7 +2408,6 @@ func (r *HumioClusterReconciler) reconcileSinglePDB(ctx context.Context, pool *H
2410
2408
return nil
2411
2409
}
2412
2410
2413
- // Check if pods exist for this node pool
2414
2411
pods , err := kubernetes .ListPods (ctx , r , pool .GetNamespace (), pool .GetNodePoolLabels ())
2415
2412
if err != nil {
2416
2413
return fmt .Errorf ("failed to list pods for node pool %s: %w" , pool .GetNodePoolName (), err )
@@ -2422,7 +2419,6 @@ func (r *HumioClusterReconciler) reconcileSinglePDB(ctx context.Context, pool *H
2422
2419
return nil
2423
2420
}
2424
2421
2425
- // Build the desired PDB
2426
2422
desiredPDB , err := r .constructPDB (pool )
2427
2423
if err != nil {
2428
2424
return fmt .Errorf ("failed to construct PDB for node pool %s: %w" , pool .GetNodePoolName (), err )
@@ -2452,7 +2448,6 @@ func (r *HumioClusterReconciler) constructPDB(pool *HumioNodePool) (*policyv1.Po
2452
2448
},
2453
2449
}
2454
2450
2455
- // Apply PDB configuration from the node pool
2456
2451
pdbConfig := pool .GetPodDisruptionBudget ()
2457
2452
if pdbConfig != nil {
2458
2453
if pdbConfig .MinAvailable != nil {
@@ -2469,12 +2464,10 @@ func (r *HumioClusterReconciler) constructPDB(pool *HumioNodePool) (*policyv1.Po
2469
2464
pdb .Spec .UnhealthyPodEvictionPolicy = (* policyv1 .UnhealthyPodEvictionPolicyType )(pdbConfig .UnhealthyPodEvictionPolicy )
2470
2465
}
2471
2466
} else {
2472
- // Set default MinAvailable if no PDB config provided
2473
2467
defaultMin := intstr .FromString (defaultMinAvailable )
2474
2468
pdb .Spec .MinAvailable = & defaultMin
2475
2469
}
2476
2470
2477
- // Set controller reference
2478
2471
clusterRef := & humiov1alpha1.HumioCluster {
2479
2472
ObjectMeta : metav1.ObjectMeta {
2480
2473
Name : pool .GetClusterName (),
@@ -2531,27 +2524,23 @@ func (r *HumioClusterReconciler) cleanupOrphanedPDBs(ctx context.Context, humioN
2531
2524
return nil
2532
2525
}
2533
2526
2534
- // Get cluster details from the first node pool
2535
2527
clusterName := humioNodePools .Items [0 ].GetClusterName ()
2536
2528
namespace := humioNodePools .Items [0 ].GetNamespace ()
2537
2529
2538
- // List all existing PDBs for this cluster
2539
2530
existingPDBs := & policyv1.PodDisruptionBudgetList {}
2540
2531
if err := r .List (ctx , existingPDBs ,
2541
2532
client .InNamespace (namespace ),
2542
2533
client .MatchingLabels (kubernetes .LabelsForHumio (clusterName ))); err != nil {
2543
2534
return fmt .Errorf ("failed to list PDBs: %w" , err )
2544
2535
}
2545
2536
2546
- // Create a map of valid PDB names based on active node pools
2547
2537
validPDBs := make (map [string ]bool )
2548
2538
for _ , pool := range humioNodePools .Items {
2549
2539
if shouldCreatePDBForNodePool (pool ) {
2550
2540
validPDBs [fmt .Sprintf ("%s%s" , pool .GetNodePoolName (), pdbNameSuffix )] = true
2551
2541
}
2552
2542
}
2553
2543
2554
- // Delete orphaned PDBs
2555
2544
for _ , pdb := range existingPDBs .Items {
2556
2545
if ! validPDBs [pdb .Name ] {
2557
2546
r .Log .Info ("deleting orphaned PDB" , "pdbName" , pdb .Name )
0 commit comments