@@ -33,7 +33,6 @@ import (
33
33
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
34
34
"k8s.io/apimachinery/pkg/util/intstr"
35
35
"sigs.k8s.io/controller-runtime/pkg/client"
36
- logf "sigs.k8s.io/controller-runtime/pkg/log"
37
36
38
37
"github.com/percona/percona-server-mysql-operator/pkg/naming"
39
38
"github.com/percona/percona-server-mysql-operator/pkg/platform"
@@ -93,6 +92,7 @@ const (
93
92
MinSafeProxySize = 2
94
93
MinSafeGRSize = 3
95
94
MaxSafeGRSize = 9
95
+ MinSafeAsyncSize = 2
96
96
)
97
97
98
98
// Checks if the provided ClusterType is valid.
@@ -526,7 +526,6 @@ func (cr *PerconaServerMySQL) SetVersion() {
526
526
527
527
// CheckNSetDefaults validates and sets default values for the PerconaServerMySQL custom resource.
528
528
func (cr * PerconaServerMySQL ) CheckNSetDefaults (ctx context.Context , serverVersion * platform.ServerVersion ) error {
529
- log := logf .FromContext (ctx ).WithName ("CheckNSetDefaults" )
530
529
if len (cr .Spec .MySQL .ClusterType ) == 0 {
531
530
cr .Spec .MySQL .ClusterType = ClusterTypeAsync
532
531
}
@@ -691,38 +690,66 @@ func (cr *PerconaServerMySQL) CheckNSetDefaults(ctx context.Context, serverVersi
691
690
cr .Spec .MySQL .reconcileAffinityOpts ()
692
691
cr .Spec .Orchestrator .reconcileAffinityOpts ()
693
692
694
- if oSize := int ( cr .Spec .Orchestrator .Size ); cr . OrchestratorEnabled () && ( oSize < 3 || oSize % 2 == 0 ) && oSize != 0 && ! cr . Spec . Unsafe . OrchestratorSize {
695
- return errors . New ( "Orchestrator size must be 3 or greater and an odd number for raft setup. Enable spec.unsafeFlags.orchestratorSize to bypass this check" )
693
+ if cr .Spec .MySQL .Size == 1 {
694
+ cr . Spec . UpdateStrategy = appsv1 . RollingUpdateStatefulSetStrategyType
696
695
}
697
696
698
- if cr .Spec .MySQL .ClusterType == ClusterTypeGR && cr .Spec .Proxy .Router == nil {
699
- return errors .New ("router section is needed for group replication" )
697
+ if cr .Spec .MySQL .ClusterType == ClusterTypeGR {
698
+ if ! cr .Spec .Proxy .Router .Enabled && ! cr .Spec .Proxy .HAProxy .Enabled && ! cr .Spec .Unsafe .Proxy {
699
+ return errors .New ("MySQL Router or HAProxy must be enabled for Group Replication. Enable spec.unsafeFlags.proxy to bypass this check" )
700
+ }
701
+
702
+ if cr .RouterEnabled () && ! cr .Spec .Unsafe .ProxySize {
703
+ if cr .Spec .Proxy .Router .Size < MinSafeProxySize {
704
+ return errors .Errorf ("Router size should be %d or greater. Enable spec.unsafeFlags.proxySize to set a lower size" , MinSafeProxySize )
705
+ }
706
+ }
707
+
708
+ if ! cr .Spec .Unsafe .MySQLSize {
709
+ if cr .Spec .MySQL .Size < MinSafeGRSize {
710
+ return errors .Errorf ("MySQL size should be %d or greater for Group Replication. Enable spec.unsafeFlags.mysqlSize to set a lower size" , MinSafeGRSize )
711
+ }
712
+
713
+ if cr .Spec .MySQL .Size > MaxSafeGRSize {
714
+ return errors .Errorf ("MySQL size should be %d or lower for Group Replication. Enable spec.unsafeFlags.mysqlSize to set a higher size" , MaxSafeGRSize )
715
+ }
716
+
717
+ if cr .Spec .MySQL .Size % 2 == 0 {
718
+ return errors .New ("MySQL size should be an odd number for Group Replication. Enable spec.unsafeFlags.mysqlSize to set an even number" )
719
+ }
720
+ }
700
721
}
701
722
702
- if cr .Spec .MySQL .ClusterType == ClusterTypeGR && ! cr .Spec .Unsafe .MySQLSize {
703
- if cr .Spec .MySQL .Size < MinSafeGRSize {
704
- return errors .Errorf ("MySQL size should be %d or greater for Group Replication. Enable spec.unsafeFlags.mysqlSize to set a lower size" , MinSafeGRSize )
723
+ if cr .Spec .MySQL .ClusterType == ClusterTypeAsync {
724
+ if ! cr .Spec .Unsafe .MySQLSize && cr .Spec .MySQL .Size < MinSafeAsyncSize {
725
+ return errors .Errorf ("MySQL size should be %d or greater for asynchronous replication. Enable spec.unsafeFlags.mysqlSize to set a lower size" , MinSafeAsyncSize )
726
+ }
727
+
728
+ if ! cr .Spec .Unsafe .Orchestrator && ! cr .Spec .Orchestrator .Enabled {
729
+ return errors .New ("Orchestrator must be enabled for asynchronous replication. Enable spec.unsafeFlags.orchestrator to bypass this check" )
730
+ }
731
+
732
+ if oSize := int (cr .Spec .Orchestrator .Size ); cr .OrchestratorEnabled () && (oSize < 3 || oSize % 2 == 0 ) && oSize != 0 && ! cr .Spec .Unsafe .OrchestratorSize {
733
+ return errors .New ("Orchestrator size must be 3 or greater and an odd number for raft setup. Enable spec.unsafeFlags.orchestratorSize to bypass this check" )
734
+ }
735
+
736
+ if ! cr .Spec .Orchestrator .Enabled && cr .Spec .UpdateStrategy == SmartUpdateStatefulSetStrategyType {
737
+ return errors .Errorf ("Orchestrator must be enabled to use SmartUpdate. Either enable Orchestrator or set spec.updateStrategy to %s" , appsv1 .RollingUpdateStatefulSetStrategyType )
705
738
}
706
739
707
- if cr .Spec .MySQL . Size > MaxSafeGRSize {
708
- return errors .Errorf ( "MySQL size should be %d or lower for Group Replication . Enable spec.unsafeFlags.mysqlSize to set a higher size" , MaxSafeGRSize )
740
+ if ! cr .Spec .Unsafe . Proxy && ! cr . HAProxyEnabled () {
741
+ return errors .New ( "HAProxy must be enabled for asynchronous replication . Enable spec.unsafeFlags.proxy to bypass this check" )
709
742
}
710
743
711
- if cr .Spec . MySQL . Size % 2 == 0 {
712
- return errors .New ("MySQL size should be an odd number for Group Replication. Enable spec.unsafeFlags.mysqlSize to set an even number " )
744
+ if cr .RouterEnabled () {
745
+ return errors .New ("MySQL Router can't be enabled for asynchronous replication " )
713
746
}
714
747
}
715
748
716
749
if cr .RouterEnabled () && cr .HAProxyEnabled () {
717
750
return errors .New ("MySQL Router and HAProxy can't be enabled at the same time" )
718
751
}
719
752
720
- if cr .RouterEnabled () && ! cr .Spec .Unsafe .ProxySize {
721
- if cr .Spec .Proxy .Router .Size < MinSafeProxySize {
722
- return errors .Errorf ("Router size should be %d or greater. Enable spec.unsafeFlags.proxySize to set a lower size" , MinSafeProxySize )
723
- }
724
- }
725
-
726
753
if cr .Spec .Proxy .HAProxy == nil {
727
754
cr .Spec .Proxy .HAProxy = new (HAProxySpec )
728
755
}
@@ -733,18 +760,6 @@ func (cr *PerconaServerMySQL) CheckNSetDefaults(ctx context.Context, serverVersi
733
760
}
734
761
}
735
762
736
- if cr .Spec .MySQL .ClusterType != ClusterTypeGR && ! cr .OrchestratorEnabled () {
737
- switch cr .Generation {
738
- case 1 :
739
- if cr .Spec .MySQL .Size > 1 {
740
- return errors .New ("mysql size should be 1 when orchestrator is disabled" )
741
- }
742
- default :
743
- cr .Spec .Orchestrator .Enabled = true
744
- log .Info ("orchestrator can't be disabled on an existing cluster" )
745
- }
746
- }
747
-
748
763
if cr .Spec .PMM == nil {
749
764
cr .Spec .PMM = new (PMMSpec )
750
765
}
@@ -764,12 +779,6 @@ func (cr *PerconaServerMySQL) CheckNSetDefaults(ctx context.Context, serverVersi
764
779
cr .Spec .SSLSecretName = cr .Name + "-ssl"
765
780
}
766
781
767
- if cr .Spec .UpdateStrategy == SmartUpdateStatefulSetStrategyType &&
768
- ! cr .HAProxyEnabled () &&
769
- ! cr .RouterEnabled () {
770
- return errors .Errorf ("MySQL Router or HAProxy should be enabled if SmartUpdate set" )
771
- }
772
-
773
782
return nil
774
783
}
775
784
@@ -960,19 +969,11 @@ func (pmm *PMMSpec) HasSecret(secret *corev1.Secret) bool {
960
969
961
970
// RouterEnabled checks if the router is enabled, considering the MySQL configuration.
962
971
func (cr * PerconaServerMySQL ) RouterEnabled () bool {
963
- if cr .MySQLSpec ().IsAsync () {
964
- return false
965
- }
966
-
967
972
return cr .Spec .Proxy .Router != nil && cr .Spec .Proxy .Router .Enabled
968
973
}
969
974
970
975
// HAProxyEnabled verifies if HAProxy is enabled based on MySQL configuration and safety settings.
971
976
func (cr * PerconaServerMySQL ) HAProxyEnabled () bool {
972
- if cr .MySQLSpec ().IsAsync () && ! cr .Spec .Unsafe .Proxy {
973
- return true
974
- }
975
-
976
977
return cr .Spec .Proxy .HAProxy != nil && cr .Spec .Proxy .HAProxy .Enabled
977
978
}
978
979
0 commit comments