Skip to content

Commit b0954ab

Browse files
Merge pull request #276 from dciabrin/replicas-webhook
Allow intermediate replicas to ease operation
2 parents 4666731 + 330405b commit b0954ab

File tree

5 files changed

+28
-12
lines changed

5 files changed

+28
-12
lines changed

api/bases/mariadb.openstack.org_galeras.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,9 @@ spec:
6969
replicas:
7070
default: 1
7171
description: Size of the galera cluster deployment
72-
enum:
73-
- 1
74-
- 3
7572
format: int32
76-
minimum: 1
73+
maximum: 3
74+
minimum: 0
7775
type: integer
7876
secret:
7977
description: Name of the secret to look for password keys

api/v1beta1/galera_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ type GaleraSpecCore struct {
5757
// Storage size allocated for the mariadb databases
5858
// +kubebuilder:validation:Required
5959
StorageRequest string `json:"storageRequest"`
60-
// +kubebuilder:validation:Minimum=1
60+
// +kubebuilder:validation:Minimum=0
61+
// +kubebuilder:validation:Maximum=3
6162
// +kubebuilder:default=1
62-
// +kubebuilder:validation:Enum=1;3
6363
// Size of the galera cluster deployment
6464
Replicas *int32 `json:"replicas"`
6565
// +kubebuilder:validation:Optional

api/v1beta1/galera_webhook.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,20 +120,28 @@ func (spec *GaleraSpecCore) ValidateCreate(basePath *field.Path) (admission.Warn
120120
warn, _ := common_webhook.ValidateStorageRequest(basePath, spec.StorageRequest, storageRequestProdMin, false)
121121
allWarn = append(allWarn, warn...)
122122

123+
warn = spec.ValidateGaleraReplicas(basePath)
124+
allWarn = append(allWarn, warn...)
125+
123126
return allWarn, allErrs
124127
}
125128

126129
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
127130
func (r *Galera) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
131+
allWarn := []string{}
128132
galeralog.Info("validate update", "name", r.Name)
129133

130134
oldGalera, ok := old.(*Galera)
131135
if !ok || oldGalera == nil {
132136
return nil, apierrors.NewInternalError(fmt.Errorf("unable to convert existing object"))
133137
}
134138

139+
basePath := field.NewPath("spec")
140+
warn := r.Spec.ValidateGaleraReplicas(basePath)
141+
allWarn = append(allWarn, warn...)
142+
135143
// TODO(user): fill in your validation logic upon object update.
136-
return nil, nil
144+
return allWarn, nil
137145
}
138146

139147
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
@@ -149,3 +157,15 @@ func SetupGaleraDefaults(defaults GaleraDefaults) {
149157
galeraDefaults = defaults
150158
galeralog.Info("Galera defaults initialized", "defaults", defaults)
151159
}
160+
161+
// SetupGaleraDefaults - Check whether replica count is valid for quorum
162+
func (spec *GaleraSpecCore) ValidateGaleraReplicas(basePath *field.Path) admission.Warnings {
163+
replicas := int(*spec.Replicas)
164+
if replicas > 0 && (replicas%2 == 0) {
165+
res := fmt.Sprintf("%s: %d is not appropriate for quorum! Use an odd value!",
166+
basePath.Child("replicas").String(), replicas)
167+
return []string{res}
168+
} else {
169+
return nil
170+
}
171+
}

config/crd/bases/mariadb.openstack.org_galeras.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,9 @@ spec:
6969
replicas:
7070
default: 1
7171
description: Size of the galera cluster deployment
72-
enum:
73-
- 1
74-
- 3
7572
format: int32
76-
minimum: 1
73+
maximum: 3
74+
minimum: 0
7775
type: integer
7876
secret:
7977
description: Name of the secret to look for password keys

controllers/galera_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ func (r *GaleraReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res
819819
}
820820

821821
// Check if we have enough info to bootstrap the cluster now
822-
if !found {
822+
if !found && int(*instance.Spec.Replicas) > 0 {
823823
node, found = findBestCandidate(instance)
824824
}
825825
if found {

0 commit comments

Comments
 (0)