Move the setting to an explicit thing, or if there are zero nodes (which shouldn't matter anyway but be nicer to the scheduler).
This commit is contained in:
		
							parent
							
								
									9f58185a6a
								
							
						
					
					
						commit
						eea5fd589c
					
				|  | @ -42,15 +42,16 @@ type PostgresSpec struct { | ||||||
| 	// load balancers' source ranges are the same for master and replica services
 | 	// load balancers' source ranges are the same for master and replica services
 | ||||||
| 	AllowedSourceRanges []string `json:"allowedSourceRanges"` | 	AllowedSourceRanges []string `json:"allowedSourceRanges"` | ||||||
| 
 | 
 | ||||||
| 	NumberOfInstances    int32                `json:"numberOfInstances"` | 	NumberOfInstances     int32                `json:"numberOfInstances"` | ||||||
| 	Users                map[string]UserFlags `json:"users"` | 	Users                 map[string]UserFlags `json:"users"` | ||||||
| 	MaintenanceWindows   []MaintenanceWindow  `json:"maintenanceWindows,omitempty"` | 	MaintenanceWindows    []MaintenanceWindow  `json:"maintenanceWindows,omitempty"` | ||||||
| 	Clone                CloneDescription     `json:"clone"` | 	Clone                 CloneDescription     `json:"clone"` | ||||||
| 	ClusterName          string               `json:"-"` | 	ClusterName           string               `json:"-"` | ||||||
| 	Databases            map[string]string    `json:"databases,omitempty"` | 	Databases             map[string]string    `json:"databases,omitempty"` | ||||||
| 	Tolerations          []v1.Toleration      `json:"tolerations,omitempty"` | 	Tolerations           []v1.Toleration      `json:"tolerations,omitempty"` | ||||||
| 	Sidecars             []Sidecar            `json:"sidecars,omitempty"` | 	Sidecars              []Sidecar            `json:"sidecars,omitempty"` | ||||||
| 	PodPriorityClassName string               `json:"pod_priority_class_name,omitempty"` | 	PodPriorityClassName  string               `json:"pod_priority_class_name,omitempty"` | ||||||
|  | 	AllowMasterDisruption bool                 `json:"allow_master_disruption,omitempty"` | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
 | ||||||
|  |  | ||||||
|  | @ -1052,8 +1052,8 @@ func (c *Cluster) generateCloneEnvironment(description *acidv1.CloneDescription) | ||||||
| func (c *Cluster) generatePodDisruptionBudget() *policybeta1.PodDisruptionBudget { | func (c *Cluster) generatePodDisruptionBudget() *policybeta1.PodDisruptionBudget { | ||||||
| 	minAvailable := intstr.FromInt(1) | 	minAvailable := intstr.FromInt(1) | ||||||
| 
 | 
 | ||||||
| 	// Avoid creating an unsatisfyable budget.
 | 	// Is master disruption is enabled or if there is no master, set the budget to 0.
 | ||||||
| 	if c.Spec.NumberOfInstances <= 1 { | 	if c.Spec.AllowMasterDisruption || c.Spec.NumberOfInstances <= 0 { | ||||||
| 		minAvailable = intstr.FromInt(0) | 		minAvailable = intstr.FromInt(0) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -114,14 +114,37 @@ func TestGeneratePodDisruptionBudget(t *testing.T) { | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 		// With a single instance.
 | 		// With zero instances.
 | ||||||
| 		{ | 		{ | ||||||
| 			New( | 			New( | ||||||
| 				Config{OpConfig: config.Config{Resources: config.Resources{ClusterNameLabel: "cluster-name", PodRoleLabel: "spilo-role"}, PDBNameFormat: "postgres-{cluster}-pdb"}}, | 				Config{OpConfig: config.Config{Resources: config.Resources{ClusterNameLabel: "cluster-name", PodRoleLabel: "spilo-role"}, PDBNameFormat: "postgres-{cluster}-pdb"}}, | ||||||
| 				k8sutil.KubernetesClient{}, | 				k8sutil.KubernetesClient{}, | ||||||
| 				acidv1.Postgresql{ | 				acidv1.Postgresql{ | ||||||
| 					ObjectMeta: metav1.ObjectMeta{Name: "myapp-database", Namespace: "myapp"}, | 					ObjectMeta: metav1.ObjectMeta{Name: "myapp-database", Namespace: "myapp"}, | ||||||
| 					Spec:       acidv1.PostgresSpec{TeamID: "myapp", NumberOfInstances: 1}}, | 					Spec:       acidv1.PostgresSpec{TeamID: "myapp", NumberOfInstances: 0}}, | ||||||
|  | 				logger), | ||||||
|  | 			policyv1beta1.PodDisruptionBudget{ | ||||||
|  | 				ObjectMeta: metav1.ObjectMeta{ | ||||||
|  | 					Name:      "postgres-myapp-database-pdb", | ||||||
|  | 					Namespace: "myapp", | ||||||
|  | 					Labels:    map[string]string{"team": "myapp", "cluster-name": "myapp-database"}, | ||||||
|  | 				}, | ||||||
|  | 				Spec: policyv1beta1.PodDisruptionBudgetSpec{ | ||||||
|  | 					MinAvailable: toIntStr(0), | ||||||
|  | 					Selector: &metav1.LabelSelector{ | ||||||
|  | 						MatchLabels: map[string]string{"spilo-role": "master", "cluster-name": "myapp-database"}, | ||||||
|  | 					}, | ||||||
|  | 				}, | ||||||
|  | 			}, | ||||||
|  | 		}, | ||||||
|  | 		// With AllowMasterDisruption.
 | ||||||
|  | 		{ | ||||||
|  | 			New( | ||||||
|  | 				Config{OpConfig: config.Config{Resources: config.Resources{ClusterNameLabel: "cluster-name", PodRoleLabel: "spilo-role"}, PDBNameFormat: "postgres-{cluster}-pdb"}}, | ||||||
|  | 				k8sutil.KubernetesClient{}, | ||||||
|  | 				acidv1.Postgresql{ | ||||||
|  | 					ObjectMeta: metav1.ObjectMeta{Name: "myapp-database", Namespace: "myapp"}, | ||||||
|  | 					Spec:       acidv1.PostgresSpec{TeamID: "myapp", NumberOfInstances: 3, AllowMasterDisruption: true}}, | ||||||
| 				logger), | 				logger), | ||||||
| 			policyv1beta1.PodDisruptionBudget{ | 			policyv1beta1.PodDisruptionBudget{ | ||||||
| 				ObjectMeta: metav1.ObjectMeta{ | 				ObjectMeta: metav1.ObjectMeta{ | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue