Skip to content

Commit 336f309

Browse files
egeguneshors
andauthored
K8SPS-186: Add unsafeFlags (#668)
* K8SPS-186: Add unsafeFlags * fix tests * fix haproxy test * comment unsafe flags * fix smart-update test --------- Co-authored-by: Viacheslav Sarzhan <[email protected]>
1 parent 6a28c38 commit 336f309

21 files changed

+182
-81
lines changed

api/v1alpha1/perconaservermysql_types.go

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type PerconaServerMySQLSpec struct {
5050
SecretsName string `json:"secretsName,omitempty"`
5151
SSLSecretName string `json:"sslSecretName,omitempty"`
5252
SSLInternalSecretName string `json:"sslInternalSecretName,omitempty"`
53-
AllowUnsafeConfig bool `json:"allowUnsafeConfigurations,omitempty"`
53+
Unsafe UnsafeFlags `json:"unsafeFlags,omitempty"`
5454
InitImage string `json:"initImage,omitempty"`
5555
IgnoreAnnotations []string `json:"ignoreAnnotations,omitempty"`
5656
IgnoreLabels []string `json:"ignoreLabels,omitempty"`
@@ -65,6 +65,21 @@ type PerconaServerMySQLSpec struct {
6565
UpdateStrategy appsv1.StatefulSetUpdateStrategyType `json:"updateStrategy,omitempty"`
6666
}
6767

68+
type UnsafeFlags struct {
69+
// MySQLSize allows to set MySQL size to a value less than the minimum safe size or higher than the maximum safe size.
70+
MySQLSize bool `json:"mysqlSize,omitempty"`
71+
72+
// Proxy allows to disable proxy.
73+
Proxy bool `json:"proxy,omitempty"`
74+
// ProxySize allows to set proxy (HAProxy / Router) size to a value less than the minimum safe size.
75+
ProxySize bool `json:"proxySize,omitempty"`
76+
77+
// Orchestrator allows to disable Orchestrator.
78+
Orchestrator bool `json:"orchestrator,omitempty"`
79+
// OrchestratorSize allows to set Orchestrator size to a value less than the minimum safe size.
80+
OrchestratorSize bool `json:"orchestratorSize,omitempty"`
81+
}
82+
6883
type TLSSpec struct {
6984
SANs []string `json:"SANs,omitempty"`
7085
IssuerConf *cmmeta.ObjectReference `json:"issuerConf,omitempty"`
@@ -676,48 +691,45 @@ func (cr *PerconaServerMySQL) CheckNSetDefaults(ctx context.Context, serverVersi
676691
cr.Spec.MySQL.reconcileAffinityOpts()
677692
cr.Spec.Orchestrator.reconcileAffinityOpts()
678693

679-
if oSize := int(cr.Spec.Orchestrator.Size); cr.OrchestratorEnabled() && (oSize < 3 || oSize%2 == 0) && oSize != 0 && !cr.Spec.AllowUnsafeConfig {
680-
return errors.New("Orchestrator size must be 3 or greater and an odd number for raft setup")
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")
681696
}
682697

683698
if cr.Spec.MySQL.ClusterType == ClusterTypeGR && cr.Spec.Proxy.Router == nil {
684699
return errors.New("router section is needed for group replication")
685700
}
686701

687-
if cr.Spec.MySQL.ClusterType == ClusterTypeGR && !cr.Spec.AllowUnsafeConfig {
702+
if cr.Spec.MySQL.ClusterType == ClusterTypeGR && !cr.Spec.Unsafe.MySQLSize {
688703
if cr.Spec.MySQL.Size < MinSafeGRSize {
689-
log.Info("Setting safe defaults, updating MySQL cluster size", "oldSize", cr.Spec.MySQL.Size, "newSafeSize", MinSafeGRSize)
690-
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)
691705
}
692706

693707
if cr.Spec.MySQL.Size > MaxSafeGRSize {
694-
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)
695709
}
696710

697711
if cr.Spec.MySQL.Size%2 == 0 {
698-
cr.Spec.MySQL.Size++
712+
return errors.New("MySQL size should be an odd number for Group Replication. Enable spec.unsafeFlags.mysqlSize to set an even number")
699713
}
700714
}
701715

702716
if cr.RouterEnabled() && cr.HAProxyEnabled() {
703717
return errors.New("MySQL Router and HAProxy can't be enabled at the same time")
704718
}
705719

706-
if cr.RouterEnabled() && !cr.Spec.AllowUnsafeConfig {
720+
if cr.RouterEnabled() && !cr.Spec.Unsafe.ProxySize {
707721
if cr.Spec.Proxy.Router.Size < MinSafeProxySize {
708-
log.Info("Setting safe defaults, updating Router size", "oldSize", cr.Spec.Proxy.Router.Size, "newSafeSize", MinSafeProxySize)
709-
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)
710723
}
711724
}
712725

713726
if cr.Spec.Proxy.HAProxy == nil {
714727
cr.Spec.Proxy.HAProxy = new(HAProxySpec)
715728
}
716729

717-
if cr.HAProxyEnabled() && !cr.Spec.AllowUnsafeConfig {
730+
if cr.HAProxyEnabled() && !cr.Spec.Unsafe.ProxySize {
718731
if cr.Spec.Proxy.HAProxy.Size < MinSafeProxySize {
719-
log.Info("Setting safe defaults, updating HAProxy size", "oldSize", cr.Spec.Proxy.HAProxy.Size, "newSafeSize", MinSafeProxySize)
720-
cr.Spec.Proxy.HAProxy.Size = MinSafeProxySize
732+
return errors.Errorf("HAProxy size should be %d or greater. Enable spec.unsafeFlags.proxySize to set a lower size", MinSafeProxySize)
721733
}
722734
}
723735

@@ -957,7 +969,7 @@ func (cr *PerconaServerMySQL) RouterEnabled() bool {
957969

958970
// HAProxyEnabled verifies if HAProxy is enabled based on MySQL configuration and safety settings.
959971
func (cr *PerconaServerMySQL) HAProxyEnabled() bool {
960-
if cr.MySQLSpec().IsAsync() && !cr.Spec.AllowUnsafeConfig {
972+
if cr.MySQLSpec().IsAsync() && !cr.Spec.Unsafe.Proxy {
961973
return true
962974
}
963975

@@ -971,7 +983,7 @@ func (cr *PerconaServerMySQL) OrchestratorEnabled() bool {
971983
return false
972984
}
973985

974-
if cr.MySQLSpec().IsAsync() && !cr.Spec.AllowUnsafeConfig {
986+
if cr.MySQLSpec().IsAsync() && !cr.Spec.Unsafe.Orchestrator {
975987
return true
976988
}
977989

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/ps.percona.com_perconaservermysqls.yaml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ spec:
5353
type: object
5454
spec:
5555
properties:
56-
allowUnsafeConfigurations:
57-
type: boolean
5856
backup:
5957
properties:
6058
backoffLimit:
@@ -8046,6 +8044,19 @@ spec:
80468044
required:
80478045
- image
80488046
type: object
8047+
unsafeFlags:
8048+
properties:
8049+
mysqlSize:
8050+
type: boolean
8051+
orchestrator:
8052+
type: boolean
8053+
orchestratorSize:
8054+
type: boolean
8055+
proxy:
8056+
type: boolean
8057+
proxySize:
8058+
type: boolean
8059+
type: object
80498060
updateStrategy:
80508061
type: string
80518062
upgradeOptions:

config/samples/ps_v2_perconaserverformysql.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ kind: PerconaServerMySQL
33
metadata:
44
name: cluster1
55
spec:
6-
allowUnsafeConfigurations: false
6+
unsafeFlags:
7+
mysqlSize: false
8+
orchestrator: false
9+
orchestratorSize: false
10+
proxy: false
11+
proxySize: false
712
secretsName: cluster1-secrets
813
sslSecretName: cluster1-ssl
914
mysql:
@@ -83,7 +88,7 @@ spec:
8388
storage: 1G
8489
affinity:
8590
antiAffinityTopologyKey: "none"
86-
91+
8792
pmm:
8893
enabled: false
8994
image: percona/pmm-client:2.12.0

deploy/bundle.yaml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,8 +1949,6 @@ spec:
19491949
type: object
19501950
spec:
19511951
properties:
1952-
allowUnsafeConfigurations:
1953-
type: boolean
19541952
backup:
19551953
properties:
19561954
backoffLimit:
@@ -9942,6 +9940,19 @@ spec:
99429940
required:
99439941
- image
99449942
type: object
9943+
unsafeFlags:
9944+
properties:
9945+
mysqlSize:
9946+
type: boolean
9947+
orchestrator:
9948+
type: boolean
9949+
orchestratorSize:
9950+
type: boolean
9951+
proxy:
9952+
type: boolean
9953+
proxySize:
9954+
type: boolean
9955+
type: object
99459956
updateStrategy:
99469957
type: string
99479958
upgradeOptions:

deploy/cr.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ metadata:
66
- percona.com/delete-mysql-pods-in-order
77
# - percona.com/delete-ssl
88
spec:
9-
allowUnsafeConfigurations: false
9+
# unsafeFlags:
10+
# mysqlSize: false
11+
# orchestrator: false
12+
# orchestratorSize: false
13+
# proxy: false
14+
# proxySize: false
1015
# pause: false
1116
crVersion: 0.8.0
1217
secretsName: cluster1-secrets

deploy/crd.yaml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,8 +1949,6 @@ spec:
19491949
type: object
19501950
spec:
19511951
properties:
1952-
allowUnsafeConfigurations:
1953-
type: boolean
19541952
backup:
19551953
properties:
19561954
backoffLimit:
@@ -9942,6 +9940,19 @@ spec:
99429940
required:
99439941
- image
99449942
type: object
9943+
unsafeFlags:
9944+
properties:
9945+
mysqlSize:
9946+
type: boolean
9947+
orchestrator:
9948+
type: boolean
9949+
orchestratorSize:
9950+
type: boolean
9951+
proxy:
9952+
type: boolean
9953+
proxySize:
9954+
type: boolean
9955+
type: object
99459956
updateStrategy:
99469957
type: string
99479958
upgradeOptions:

e2e-tests/tests/gr-demand-backup/02-assert.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ kind: PerconaServerMySQL
2929
metadata:
3030
name: gr-demand-backup
3131
spec:
32-
allowUnsafeConfigurations: false
3332
backup:
3433
backoffLimit: 3
3534
status:

e2e-tests/tests/gr-one-pod/01-assert.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ kind: PerconaServerMySQL
3939
metadata:
4040
name: gr-one-pod
4141
spec:
42-
allowUnsafeConfigurations: true
42+
unsafeFlags:
43+
mysqlSize: true
4344
mysql:
4445
clusterType: group-replication
4546
size: 1

e2e-tests/tests/gr-one-pod/01-create-cluster.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ commands:
1212
| yq eval '.spec.mysql.clusterType="group-replication"' - \
1313
| yq eval '.spec.proxy.router.enabled=true' - \
1414
| yq eval '.spec.proxy.haproxy.enabled=false' - \
15-
| yq eval '.spec.allowUnsafeConfigurations=true' - \
15+
| yq eval '.spec.unsafeFlags.mysqlSize=true' - \
16+
| yq eval '.spec.unsafeFlags.proxySize=true' - \
1617
| yq eval '.spec.mysql.size=1' - \
1718
| yq eval '.spec.proxy.haproxy.enabled=false' - \
1819
| yq eval '.spec.proxy.router.size=1' - \

0 commit comments

Comments
 (0)