Default galera recovery minClusterSize to 1

This commit is contained in:
mmontes11
2024-08-23 15:15:32 +02:00
committed by Martin Montes
parent c5cffd41ca
commit e9c1b5b858
5 changed files with 80 additions and 21 deletions

View File

@ -169,9 +169,9 @@ type GaleraRecovery struct {
// +optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:booleanSwitch"}
Enabled bool `json:"enabled"`
// MinClusterSize is the minimum number of replicas to consider the cluster healthy. It can be either a number of replicas (3) or a percentage (50%).
// MinClusterSize is the minimum number of replicas to consider the cluster healthy. It can be either a number of replicas (1) or a percentage (50%).
// If Galera consistently reports less replicas than this value for the given 'ClusterHealthyTimeout' interval, a cluster recovery is iniated.
// It defaults to '50%' of the replicas specified by the MariaDB object.
// It defaults to '1' replica.
// +optional
// +operator-sdk:csv:customresourcedefinitions:type=spec
MinClusterSize *intstr.IntOrString `json:"minClusterSize,omitempty"`
@ -237,7 +237,7 @@ func (g *GaleraRecovery) Validate(mdb *MariaDB) error {
// SetDefaults sets reasonable defaults.
func (g *GaleraRecovery) SetDefaults(mdb *MariaDB) {
if g.MinClusterSize == nil {
g.MinClusterSize = ptr.To(intstr.FromString("50%"))
g.MinClusterSize = ptr.To(intstr.FromInt(1))
}
if g.ClusterMonitorInterval == nil {
g.ClusterMonitorInterval = ptr.To(metav1.Duration{Duration: 10 * time.Second})
@ -258,7 +258,7 @@ func (g *GaleraRecovery) SetDefaults(mdb *MariaDB) {
// HasMinClusterSize returns whether the current cluster has the minimum number of replicas. If not, a cluster recovery will be performed.
func (g *GaleraRecovery) HasMinClusterSize(currentSize int, mdb *MariaDB) (bool, error) {
minClusterSize := ptr.Deref(g.MinClusterSize, intstr.FromString("50%"))
minClusterSize := ptr.Deref(g.MinClusterSize, intstr.FromInt(1))
scaled, err := intstr.GetScaledValueFromIntOrPercent(&minClusterSize, int(mdb.Spec.Replicas), true)
if err != nil {
return false, err

View File

@ -79,7 +79,7 @@ var _ = Describe("MariaDB Galera types", func() {
},
Recovery: &GaleraRecovery{
Enabled: true,
MinClusterSize: ptr.To(intstr.FromString("50%")),
MinClusterSize: ptr.To(intstr.FromInt(1)),
ClusterMonitorInterval: ptr.To(metav1.Duration{Duration: 10 * time.Second}),
ClusterHealthyTimeout: ptr.To(metav1.Duration{Duration: 30 * time.Second}),
ClusterBootstrapTimeout: ptr.To(metav1.Duration{Duration: 10 * time.Minute}),
@ -344,6 +344,7 @@ var _ = Describe("MariaDB Galera types", func() {
Galera: &Galera{
GaleraSpec: GaleraSpec{
Recovery: &GaleraRecovery{
Enabled: true,
MinClusterSize: ptr.To(intstr.FromString("foo")),
},
},
@ -354,7 +355,7 @@ var _ = Describe("MariaDB Galera types", func() {
true,
),
Entry(
"Zero replicas",
"Less than min fixed size",
0,
&MariaDB{
Spec: MariaDBSpec{
@ -362,7 +363,8 @@ var _ = Describe("MariaDB Galera types", func() {
Galera: &Galera{
GaleraSpec: GaleraSpec{
Recovery: &GaleraRecovery{
MinClusterSize: ptr.To(intstr.FromString("50%")),
Enabled: true,
MinClusterSize: ptr.To(intstr.FromInt(1)),
},
},
},
@ -372,7 +374,7 @@ var _ = Describe("MariaDB Galera types", func() {
false,
),
Entry(
"Less than min size",
"Exact min fixed size",
1,
&MariaDB{
Spec: MariaDBSpec{
@ -380,6 +382,45 @@ var _ = Describe("MariaDB Galera types", func() {
Galera: &Galera{
GaleraSpec: GaleraSpec{
Recovery: &GaleraRecovery{
Enabled: true,
MinClusterSize: ptr.To(intstr.FromInt(1)),
},
},
},
},
},
true,
false,
),
Entry(
"More than min fixed size",
3,
&MariaDB{
Spec: MariaDBSpec{
Replicas: 3,
Galera: &Galera{
GaleraSpec: GaleraSpec{
Recovery: &GaleraRecovery{
Enabled: true,
MinClusterSize: ptr.To(intstr.FromInt(2)),
},
},
},
},
},
true,
false,
),
Entry(
"Less than min relative size",
1,
&MariaDB{
Spec: MariaDBSpec{
Replicas: 3,
Galera: &Galera{
GaleraSpec: GaleraSpec{
Recovery: &GaleraRecovery{
Enabled: true,
MinClusterSize: ptr.To(intstr.FromString("50%")),
},
},
@ -390,7 +431,7 @@ var _ = Describe("MariaDB Galera types", func() {
false,
),
Entry(
"Exact min size",
"Exact min relative size",
2,
&MariaDB{
Spec: MariaDBSpec{
@ -398,6 +439,7 @@ var _ = Describe("MariaDB Galera types", func() {
Galera: &Galera{
GaleraSpec: GaleraSpec{
Recovery: &GaleraRecovery{
Enabled: true,
MinClusterSize: ptr.To(intstr.FromString("50%")),
},
},
@ -408,7 +450,7 @@ var _ = Describe("MariaDB Galera types", func() {
false,
),
Entry(
"More than min size",
"More than min relative size",
3,
&MariaDB{
Spec: MariaDBSpec{
@ -445,6 +487,24 @@ var _ = Describe("MariaDB Galera types", func() {
true,
false,
),
Entry(
"Default min cluster size",
1,
&MariaDB{
Spec: MariaDBSpec{
Replicas: 3,
Galera: &Galera{
GaleraSpec: GaleraSpec{
Recovery: &GaleraRecovery{
Enabled: true,
},
},
},
},
},
true,
false,
),
)
DescribeTable(
@ -498,8 +558,7 @@ var _ = Describe("MariaDB Galera types", func() {
Galera: &Galera{
GaleraSpec: GaleraSpec{
Recovery: &GaleraRecovery{
Enabled: false,
MinClusterSize: ptr.To(intstr.FromString("foo")),
Enabled: false,
},
},
},

View File

@ -401,8 +401,8 @@ var _ = Describe("MariaDB webhook", func() {
ObjectMeta: meta,
Spec: MariaDBSpec{
PodDisruptionBudget: &PodDisruptionBudget{
MaxUnavailable: func() *intstr.IntOrString { i := intstr.FromString("50%"); return &i }(),
MinAvailable: func() *intstr.IntOrString { i := intstr.FromString("50%"); return &i }(),
MaxUnavailable: ptr.To(intstr.FromString("50%")),
MinAvailable: ptr.To(intstr.FromString("50%")),
},
Storage: Storage{
Size: ptr.To(resource.MustParse("100Mi")),
@ -417,7 +417,7 @@ var _ = Describe("MariaDB webhook", func() {
ObjectMeta: meta,
Spec: MariaDBSpec{
PodDisruptionBudget: &PodDisruptionBudget{
MaxUnavailable: func() *intstr.IntOrString { i := intstr.FromString("50%"); return &i }(),
MaxUnavailable: ptr.To(intstr.FromString("50%")),
},
Storage: Storage{
Size: ptr.To(resource.MustParse("100Mi")),

View File

@ -309,8 +309,8 @@ var _ = Describe("MaxScale webhook", func() {
Module: MonitorModuleMariadb,
},
PodDisruptionBudget: &PodDisruptionBudget{
MaxUnavailable: func() *intstr.IntOrString { i := intstr.FromString("50%"); return &i }(),
MinAvailable: func() *intstr.IntOrString { i := intstr.FromString("50%"); return &i }(),
MaxUnavailable: ptr.To(intstr.FromString("50%")),
MinAvailable: ptr.To(intstr.FromString("50%")),
},
},
},
@ -336,7 +336,7 @@ var _ = Describe("MaxScale webhook", func() {
},
},
PodDisruptionBudget: &PodDisruptionBudget{
MaxUnavailable: func() *intstr.IntOrString { i := intstr.FromString("50%"); return &i }(),
MaxUnavailable: ptr.To(intstr.FromString("50%")),
},
},
},
@ -366,7 +366,7 @@ var _ = Describe("MaxScale webhook", func() {
Module: MonitorModuleMariadb,
},
PodDisruptionBudget: &PodDisruptionBudget{
MaxUnavailable: func() *intstr.IntOrString { i := intstr.FromString("50%"); return &i }(),
MaxUnavailable: ptr.To(intstr.FromString("50%")),
},
},
},

View File

@ -7222,9 +7222,9 @@ spec:
- type: integer
- type: string
description: |-
MinClusterSize is the minimum number of replicas to consider the cluster healthy. It can be either a number of replicas (3) or a percentage (50%).
MinClusterSize is the minimum number of replicas to consider the cluster healthy. It can be either a number of replicas (1) or a percentage (50%).
If Galera consistently reports less replicas than this value for the given 'ClusterHealthyTimeout' interval, a cluster recovery is iniated.
It defaults to '50%' of the replicas specified by the MariaDB object.
It defaults to '1' replica.
x-kubernetes-int-or-string: true
podRecoveryTimeout:
description: PodRecoveryTimeout is the time limit for recevorying