@@ -24,7 +24,7 @@ func ReconcileRedisPodDisruptionBudget(ctx context.Context, cr *rcvb2.RedisClust
2424 labels := getRedisLabels (cr .Name , cluster , role , cr .GetLabels ())
2525 annotations := generateStatefulSetsAnots (cr .ObjectMeta , cr .Spec .KubernetesConfig .IgnoreAnnotations )
2626 pdbMeta := generateObjectMetaInformation (pdbName , cr .Namespace , labels , annotations )
27- pdbDef := generatePodDisruptionBudgetDef (ctx , cr , role , pdbMeta , cr . Spec . RedisLeader . PodDisruptionBudget )
27+ pdbDef := generatePodDisruptionBudgetDef (ctx , cr , role , pdbMeta , pdbParams )
2828 return CreateOrUpdatePodDisruptionBudget (ctx , pdbDef , cl )
2929 } else {
3030 // Check if one exists, and delete it.
@@ -97,14 +97,14 @@ func generatePodDisruptionBudgetDef(ctx context.Context, cr *rcvb2.RedisCluster,
9797 Selector : lblSelector ,
9898 },
9999 }
100- if pdbParams .MinAvailable != nil {
101- pdbTemplate .Spec .MinAvailable = & intstr.IntOrString {Type : intstr .Int , IntVal : (* pdbParams .MinAvailable )}
102- }
100+ // PodDisruptionBudget spec allows either MinAvailable OR MaxUnavailable, but not both
101+ // Priority: MaxUnavailable > MinAvailable > default quorum
103102 if pdbParams .MaxUnavailable != nil {
104103 pdbTemplate .Spec .MaxUnavailable = & intstr.IntOrString {Type : intstr .Int , IntVal : * pdbParams .MaxUnavailable }
105- }
106- // If we don't have a value for either, assume quorum: (N/2)+1
107- if pdbTemplate .Spec .MaxUnavailable == nil && pdbTemplate .Spec .MinAvailable == nil {
104+ } else if pdbParams .MinAvailable != nil {
105+ pdbTemplate .Spec .MinAvailable = & intstr.IntOrString {Type : intstr .Int , IntVal : (* pdbParams .MinAvailable )}
106+ } else {
107+ // If we don't have a value for either, assume quorum: (N/2)+1
108108 pdbTemplate .Spec .MinAvailable = & intstr.IntOrString {Type : intstr .Int , IntVal : (* cr .Spec .ClusterSize / 2 ) + 1 }
109109 }
110110 AddOwnerRefToObject (pdbTemplate , redisClusterAsOwner (cr ))
@@ -124,14 +124,14 @@ func generateReplicationPodDisruptionBudgetDef(ctx context.Context, cr *rrvb2.Re
124124 Selector : lblSelector ,
125125 },
126126 }
127- if pdbParams .MinAvailable != nil {
128- pdbTemplate .Spec .MinAvailable = & intstr.IntOrString {Type : intstr .Int , IntVal : * pdbParams .MinAvailable }
129- }
127+ // PodDisruptionBudget spec allows either MinAvailable OR MaxUnavailable, but not both
128+ // Priority: MaxUnavailable > MinAvailable > default quorum
130129 if pdbParams .MaxUnavailable != nil {
131130 pdbTemplate .Spec .MaxUnavailable = & intstr.IntOrString {Type : intstr .Int , IntVal : * pdbParams .MaxUnavailable }
132- }
133- // If we don't have a value for either, assume quorum: (N/2)+1
134- if pdbTemplate .Spec .MaxUnavailable == nil && pdbTemplate .Spec .MinAvailable == nil {
131+ } else if pdbParams .MinAvailable != nil {
132+ pdbTemplate .Spec .MinAvailable = & intstr.IntOrString {Type : intstr .Int , IntVal : * pdbParams .MinAvailable }
133+ } else {
134+ // If we don't have a value for either, assume quorum: (N/2)+1
135135 pdbTemplate .Spec .MinAvailable = & intstr.IntOrString {Type : intstr .Int , IntVal : (* cr .Spec .Size / 2 ) + 1 }
136136 }
137137 AddOwnerRefToObject (pdbTemplate , redisReplicationAsOwner (cr ))
@@ -151,14 +151,14 @@ func generateSentinelPodDisruptionBudgetDef(ctx context.Context, cr *rsvb2.Redis
151151 Selector : lblSelector ,
152152 },
153153 }
154- if pdbParams .MinAvailable != nil {
155- pdbTemplate .Spec .MinAvailable = & intstr.IntOrString {Type : intstr .Int , IntVal : * pdbParams .MinAvailable }
156- }
154+ // PodDisruptionBudget spec allows either MinAvailable OR MaxUnavailable, but not both
155+ // Priority: MaxUnavailable > MinAvailable > default quorum
157156 if pdbParams .MaxUnavailable != nil {
158157 pdbTemplate .Spec .MaxUnavailable = & intstr.IntOrString {Type : intstr .Int , IntVal : * pdbParams .MaxUnavailable }
159- }
160- // If we don't have a value for either, assume quorum: (N/2)+1
161- if pdbTemplate .Spec .MaxUnavailable == nil && pdbTemplate .Spec .MinAvailable == nil {
158+ } else if pdbParams .MinAvailable != nil {
159+ pdbTemplate .Spec .MinAvailable = & intstr.IntOrString {Type : intstr .Int , IntVal : * pdbParams .MinAvailable }
160+ } else {
161+ // If we don't have a value for either, assume quorum: (N/2)+1
162162 pdbTemplate .Spec .MinAvailable = & intstr.IntOrString {Type : intstr .Int , IntVal : (* cr .Spec .Size / 2 ) + 1 }
163163 }
164164 AddOwnerRefToObject (pdbTemplate , redisSentinelAsOwner (cr ))
0 commit comments