Skip to content

Commit 5107f97

Browse files
committed
Merge branch 'main' into K8SPS-73-self-healing
2 parents 85fe299 + 27dd044 commit 5107f97

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1053
-296
lines changed

api/v1alpha1/perconaservermysql_types.go

+28-18
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/percona/percona-server-mysql-operator/pkg/version"
3030

3131
"github.com/pkg/errors"
32+
appsv1 "k8s.io/api/apps/v1"
3233
corev1 "k8s.io/api/core/v1"
3334
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3435
"k8s.io/apimachinery/pkg/util/intstr"
@@ -41,23 +42,24 @@ import (
4142

4243
// PerconaServerMySQLSpec defines the desired state of PerconaServerMySQL
4344
type PerconaServerMySQLSpec struct {
44-
CRVersion string `json:"crVersion,omitempty"`
45-
Pause bool `json:"pause,omitempty"`
46-
SecretsName string `json:"secretsName,omitempty"`
47-
SSLSecretName string `json:"sslSecretName,omitempty"`
48-
SSLInternalSecretName string `json:"sslInternalSecretName,omitempty"`
49-
AllowUnsafeConfig bool `json:"allowUnsafeConfigurations,omitempty"`
50-
InitImage string `json:"initImage,omitempty"`
51-
IgnoreAnnotations []string `json:"ignoreAnnotations,omitempty"`
52-
IgnoreLabels []string `json:"ignoreLabels,omitempty"`
53-
MySQL MySQLSpec `json:"mysql,omitempty"`
54-
Orchestrator OrchestratorSpec `json:"orchestrator,omitempty"`
55-
PMM *PMMSpec `json:"pmm,omitempty"`
56-
Backup *BackupSpec `json:"backup,omitempty"`
57-
Proxy ProxySpec `json:"proxy,omitempty"`
58-
TLS *TLSSpec `json:"tls,omitempty"`
59-
Toolkit *ToolkitSpec `json:"toolkit,omitempty"`
60-
UpgradeOptions UpgradeOptions `json:"upgradeOptions,omitempty"`
45+
CRVersion string `json:"crVersion,omitempty"`
46+
Pause bool `json:"pause,omitempty"`
47+
SecretsName string `json:"secretsName,omitempty"`
48+
SSLSecretName string `json:"sslSecretName,omitempty"`
49+
SSLInternalSecretName string `json:"sslInternalSecretName,omitempty"`
50+
AllowUnsafeConfig bool `json:"allowUnsafeConfigurations,omitempty"`
51+
InitImage string `json:"initImage,omitempty"`
52+
IgnoreAnnotations []string `json:"ignoreAnnotations,omitempty"`
53+
IgnoreLabels []string `json:"ignoreLabels,omitempty"`
54+
MySQL MySQLSpec `json:"mysql,omitempty"`
55+
Orchestrator OrchestratorSpec `json:"orchestrator,omitempty"`
56+
PMM *PMMSpec `json:"pmm,omitempty"`
57+
Backup *BackupSpec `json:"backup,omitempty"`
58+
Proxy ProxySpec `json:"proxy,omitempty"`
59+
TLS *TLSSpec `json:"tls,omitempty"`
60+
Toolkit *ToolkitSpec `json:"toolkit,omitempty"`
61+
UpgradeOptions UpgradeOptions `json:"upgradeOptions,omitempty"`
62+
UpdateStrategy appsv1.StatefulSetUpdateStrategyType `json:"updateStrategy,omitempty"`
6163
}
6264

6365
type TLSSpec struct {
@@ -410,7 +412,6 @@ const (
410412
UserOperator SystemUser = "operator"
411413
UserOrchestrator SystemUser = "orchestrator"
412414
UserPMMServerKey SystemUser = "pmmserverkey"
413-
UserProxyAdmin SystemUser = "proxyadmin"
414415
UserReplication SystemUser = "replication"
415416
UserRoot SystemUser = "root"
416417
UserXtraBackup SystemUser = "xtrabackup"
@@ -675,6 +676,12 @@ func (cr *PerconaServerMySQL) CheckNSetDefaults(ctx context.Context, serverVersi
675676
cr.Spec.SSLSecretName = cr.Name + "-ssl"
676677
}
677678

679+
if cr.Spec.UpdateStrategy == SmartUpdateStatefulSetStrategyType &&
680+
!cr.HAProxyEnabled() &&
681+
!cr.RouterEnabled() {
682+
return errors.Errorf("MySQL Router or HAProxy should be enabled if SmartUpdate set")
683+
}
684+
678685
return nil
679686
}
680687

@@ -894,6 +901,9 @@ func init() {
894901
SchemeBuilder.Register(&PerconaServerMySQL{}, &PerconaServerMySQLList{})
895902
}
896903

904+
// SmartUpdateStatefulSetStrategyType
905+
const SmartUpdateStatefulSetStrategyType appsv1.StatefulSetUpdateStrategyType = "SmartUpdate"
906+
897907
type UpgradeOptions struct {
898908
VersionServiceEndpoint string `json:"versionServiceEndpoint,omitempty"`
899909
Apply string `json:"apply,omitempty"`

build/ps-entrypoint.sh

+18-13
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
275275
# no, we don't care if read finds a terminating character in this heredoc
276276
# https://unix.stackexchange.com/questions/265149/why-is-set-o-errexit-breaking-this-read-heredoc-expression/265151#265151
277277
read -r -d '' rootCreate <<-EOSQL || true
278-
CREATE USER 'root'@'${MYSQL_ROOT_HOST}' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' ;
278+
CREATE USER 'root'@'${MYSQL_ROOT_HOST}' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' PASSWORD EXPIRE NEVER;
279279
GRANT ALL ON *.* TO 'root'@'${MYSQL_ROOT_HOST}' WITH GRANT OPTION ;
280280
EOSQL
281281
fi
@@ -288,9 +288,20 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
288288
file_env 'OPERATOR_ADMIN_PASSWORD' '' 'operator'
289289
file_env 'XTRABACKUP_PASSWORD' '' 'xtrabackup'
290290
file_env 'HEARTBEAT_PASSWORD' '' 'heartbeat'
291+
291292
read -r -d '' monitorConnectGrant <<-EOSQL || true
292293
GRANT SERVICE_CONNECTION_ADMIN ON *.* TO 'monitor'@'${MONITOR_HOST}';
293294
EOSQL
295+
296+
if [ "$CLUSTER_TYPE" == 'async' ]; then
297+
read -r -d '' replicationCreate <<-EOSQL || true
298+
CREATE USER 'replication'@'%' IDENTIFIED BY '${REPLICATION_PASSWORD}' PASSWORD EXPIRE NEVER;
299+
GRANT DELETE, INSERT, UPDATE ON mysql.* TO 'replication'@'%' WITH GRANT OPTION;
300+
GRANT SELECT ON performance_schema.threads to 'replication'@'%';
301+
GRANT SYSTEM_USER, REPLICATION SLAVE, BACKUP_ADMIN, GROUP_REPLICATION_STREAM, CLONE_ADMIN, CONNECTION_ADMIN, CREATE USER, EXECUTE, FILE, GROUP_REPLICATION_ADMIN, PERSIST_RO_VARIABLES_ADMIN, PROCESS, RELOAD, REPLICATION CLIENT, REPLICATION_APPLIER, REPLICATION_SLAVE_ADMIN, ROLE_ADMIN, SELECT, SHUTDOWN, SYSTEM_VARIABLES_ADMIN ON *.* TO 'replication'@'%' WITH GRANT OPTION;
302+
EOSQL
303+
fi
304+
294305
"${mysql[@]}" <<-EOSQL
295306
-- What's done in this file shouldn't be replicated
296307
-- or products like mysql-fabric won't work
@@ -302,35 +313,29 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
302313
${rootCreate}
303314
/*!80016 REVOKE SYSTEM_USER ON *.* FROM root */;
304315
305-
CREATE USER 'operator'@'${MYSQL_ROOT_HOST}' IDENTIFIED BY '${OPERATOR_ADMIN_PASSWORD}' ;
316+
CREATE USER 'operator'@'${MYSQL_ROOT_HOST}' IDENTIFIED BY '${OPERATOR_ADMIN_PASSWORD}' PASSWORD EXPIRE NEVER;
306317
GRANT ALL ON *.* TO 'operator'@'${MYSQL_ROOT_HOST}' WITH GRANT OPTION ;
307318
308-
CREATE USER 'xtrabackup'@'localhost' IDENTIFIED BY '${XTRABACKUP_PASSWORD}';
319+
CREATE USER 'xtrabackup'@'localhost' IDENTIFIED BY '${XTRABACKUP_PASSWORD}' PASSWORD EXPIRE NEVER;
309320
GRANT SYSTEM_USER, BACKUP_ADMIN, PROCESS, RELOAD, GROUP_REPLICATION_ADMIN, REPLICATION_SLAVE_ADMIN, LOCK TABLES, REPLICATION CLIENT ON *.* TO 'xtrabackup'@'localhost';
310321
GRANT SELECT ON performance_schema.replication_group_members TO 'xtrabackup'@'localhost';
311322
GRANT SELECT ON performance_schema.log_status TO 'xtrabackup'@'localhost';
312323
GRANT SELECT ON performance_schema.keyring_component_status TO 'xtrabackup'@'localhost';
313324
314-
CREATE USER 'monitor'@'${MONITOR_HOST}' IDENTIFIED BY '${MONITOR_PASSWORD}' WITH MAX_USER_CONNECTIONS 100;
325+
CREATE USER 'monitor'@'${MONITOR_HOST}' IDENTIFIED BY '${MONITOR_PASSWORD}' WITH MAX_USER_CONNECTIONS 100 PASSWORD EXPIRE NEVER;
315326
GRANT SYSTEM_USER, SELECT, PROCESS, SUPER, REPLICATION CLIENT, RELOAD, BACKUP_ADMIN ON *.* TO 'monitor'@'${MONITOR_HOST}';
316327
GRANT SELECT ON performance_schema.* TO 'monitor'@'${MONITOR_HOST}';
317328
${monitorConnectGrant}
318329
319-
CREATE USER 'replication'@'%' IDENTIFIED BY '${REPLICATION_PASSWORD}';
320-
GRANT DELETE, INSERT, UPDATE ON mysql.* TO 'replication'@'%' WITH GRANT OPTION;
321-
GRANT SELECT ON performance_schema.threads to 'replication'@'%';
322-
GRANT SYSTEM_USER, REPLICATION SLAVE, BACKUP_ADMIN, GROUP_REPLICATION_STREAM, CLONE_ADMIN, CONNECTION_ADMIN, CREATE USER, EXECUTE, FILE, GROUP_REPLICATION_ADMIN, PERSIST_RO_VARIABLES_ADMIN, PROCESS, RELOAD, REPLICATION CLIENT, REPLICATION_APPLIER, REPLICATION_SLAVE_ADMIN, ROLE_ADMIN, SELECT, SHUTDOWN, SYSTEM_VARIABLES_ADMIN ON *.* TO 'replication'@'%' WITH GRANT OPTION;
323-
GRANT ALTER, ALTER ROUTINE, CREATE, CREATE ROUTINE, CREATE TEMPORARY TABLES, CREATE VIEW, DELETE, DROP, EVENT, EXECUTE, INDEX, INSERT, LOCK TABLES, REFERENCES, SHOW VIEW, TRIGGER, UPDATE ON mysql_innodb_cluster_metadata.* TO 'replication'@'%' WITH GRANT OPTION;
324-
GRANT ALTER, ALTER ROUTINE, CREATE, CREATE ROUTINE, CREATE TEMPORARY TABLES, CREATE VIEW, DELETE, DROP, EVENT, EXECUTE, INDEX, INSERT, LOCK TABLES, REFERENCES, SHOW VIEW, TRIGGER, UPDATE ON mysql_innodb_cluster_metadata_bkp.* TO 'replication'@'%' WITH GRANT OPTION;
325-
GRANT ALTER, ALTER ROUTINE, CREATE, CREATE ROUTINE, CREATE TEMPORARY TABLES, CREATE VIEW, DELETE, DROP, EVENT, EXECUTE, INDEX, INSERT, LOCK TABLES, REFERENCES, SHOW VIEW, TRIGGER, UPDATE ON mysql_innodb_cluster_metadata_previous.* TO 'replication'@'%' WITH GRANT OPTION;
330+
${replicationCreate}
326331
327-
CREATE USER 'orchestrator'@'%' IDENTIFIED BY '${ORC_TOPOLOGY_PASSWORD}';
332+
CREATE USER 'orchestrator'@'%' IDENTIFIED BY '${ORC_TOPOLOGY_PASSWORD}' PASSWORD EXPIRE NEVER;
328333
GRANT SYSTEM_USER, SUPER, PROCESS, REPLICATION SLAVE, REPLICATION CLIENT, RELOAD ON *.* TO 'orchestrator'@'%';
329334
GRANT SELECT ON mysql.slave_master_info TO 'orchestrator'@'%';
330335
GRANT SELECT ON sys_operator.* TO 'orchestrator'@'%';
331336
332337
CREATE DATABASE IF NOT EXISTS sys_operator;
333-
CREATE USER 'heartbeat'@'localhost' IDENTIFIED BY '${HEARTBEAT_PASSWORD}';
338+
CREATE USER 'heartbeat'@'localhost' IDENTIFIED BY '${HEARTBEAT_PASSWORD}' PASSWORD EXPIRE NEVER;
334339
GRANT SYSTEM_USER, REPLICATION CLIENT ON *.* TO 'heartbeat'@'localhost';
335340
GRANT SELECT, CREATE, DELETE, UPDATE, INSERT ON sys_operator.heartbeat TO 'heartbeat'@'localhost';
336341

cmd/bootstrap/async_replication.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func bootstrapAsyncReplication(ctx context.Context) error {
8787
return errors.Wrapf(err, "get %s password", apiv1alpha1.UserOperator)
8888
}
8989

90-
db, err := replicator.NewReplicator(ctx, "operator", operatorPass, podIp, mysql.DefaultAdminPort)
90+
db, err := replicator.NewReplicator(ctx, apiv1alpha1.UserOperator, operatorPass, podIp, mysql.DefaultAdminPort)
9191
if err != nil {
9292
return errors.Wrap(err, "connect to db")
9393
}
@@ -142,7 +142,7 @@ func bootstrapAsyncReplication(ctx context.Context) error {
142142

143143
timer.Start("clone")
144144
log.Printf("Cloning from %s", donor)
145-
err = db.Clone(ctx, donor, "operator", operatorPass, mysql.DefaultAdminPort)
145+
err = db.Clone(ctx, donor, string(apiv1alpha1.UserOperator), operatorPass, mysql.DefaultAdminPort)
146146
timer.Stop("clone")
147147
if err != nil && !errors.Is(err, replicator.ErrRestartAfterClone) {
148148
return errors.Wrapf(err, "clone from donor %s", donor)
@@ -204,7 +204,7 @@ func getTopology(ctx context.Context, peers sets.Set[string]) (string, []string,
204204
}
205205

206206
for _, peer := range sets.List(peers) {
207-
db, err := replicator.NewReplicator(ctx, "operator", operatorPass, peer, mysql.DefaultAdminPort)
207+
db, err := replicator.NewReplicator(ctx, apiv1alpha1.UserOperator, operatorPass, peer, mysql.DefaultAdminPort)
208208
if err != nil {
209209
return "", nil, errors.Wrapf(err, "connect to %s", peer)
210210
}
@@ -251,7 +251,7 @@ func selectDonor(ctx context.Context, fqdn, primary string, replicas []string) (
251251
}
252252

253253
for _, replica := range replicas {
254-
db, err := replicator.NewReplicator(ctx, "operator", operatorPass, replica, mysql.DefaultAdminPort)
254+
db, err := replicator.NewReplicator(ctx, apiv1alpha1.UserOperator, operatorPass, replica, mysql.DefaultAdminPort)
255255
if err != nil {
256256
continue
257257
}

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

+2
Original file line numberDiff line numberDiff line change
@@ -7135,6 +7135,8 @@ spec:
71357135
required:
71367136
- image
71377137
type: object
7138+
updateStrategy:
7139+
type: string
71387140
upgradeOptions:
71397141
properties:
71407142
apply:

deploy/bundle.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -8747,6 +8747,8 @@ spec:
87478747
required:
87488748
- image
87498749
type: object
8750+
updateStrategy:
8751+
type: string
87508752
upgradeOptions:
87518753
properties:
87528754
apply:

deploy/cr.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ spec:
1111
crVersion: 0.6.0
1212
secretsName: cluster1-secrets
1313
sslSecretName: cluster1-ssl
14+
updateStrategy: SmartUpdate
1415
upgradeOptions:
1516
versionServiceEndpoint: https://check.percona.com
1617
apply: disabled

deploy/crd.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -8747,6 +8747,8 @@ spec:
87478747
required:
87488748
- image
87498749
type: object
8750+
updateStrategy:
8751+
type: string
87508752
upgradeOptions:
87518753
properties:
87528754
apply:

e2e-tests/run-distro.csv

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ gr-one-pod
99
gr-scaling
1010
gr-self-healing
1111
gr-tls-cert-manager
12+
gr-users
1213
haproxy
1314
init-deploy
1415
monitoring
@@ -18,5 +19,6 @@ scaling
1819
self-healing
1920
service-per-pod
2021
sidecars
22+
smart-update
2123
tls-cert-manager
2224
users

e2e-tests/run-minikube.csv

+2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ gr-one-pod
99
gr-scaling
1010
gr-self-healing
1111
gr-tls-cert-manager
12+
gr-users
1213
haproxy
1314
init-deploy
1415
one-pod
1516
operator-self-healing
1617
self-healing
1718
sidecars
19+
smart-update
1820
tls-cert-manager
1921
users
2022
version-service

e2e-tests/run-pr.csv

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ gr-one-pod
1212
gr-scaling
1313
gr-self-healing
1414
gr-tls-cert-manager
15+
gr-users
1516
haproxy
1617
init-deploy
1718
limits
@@ -22,6 +23,7 @@ scaling
2223
self-healing
2324
service-per-pod
2425
sidecars
26+
smart-update
2527
tls-cert-manager
2628
users
2729
version-service

e2e-tests/run-release.csv

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ gr-one-pod
1111
gr-scaling
1212
gr-self-healing
1313
gr-tls-cert-manager
14+
gr-users
1415
haproxy
1516
init-deploy
1617
limits
@@ -21,6 +22,7 @@ scaling
2122
self-healing
2223
service-per-pod
2324
sidecars
25+
smart-update
2426
tls-cert-manager
2527
users
2628
version-service
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestAssert
3+
timeout: 120
4+
---
5+
apiVersion: apiextensions.k8s.io/v1
6+
kind: CustomResourceDefinition
7+
metadata:
8+
name: perconaservermysqls.ps.percona.com
9+
spec:
10+
group: ps.percona.com
11+
names:
12+
kind: PerconaServerMySQL
13+
listKind: PerconaServerMySQLList
14+
plural: perconaservermysqls
15+
shortNames:
16+
- ps
17+
singular: perconaservermysql
18+
scope: Namespaced
19+
---
20+
apiVersion: apps/v1
21+
kind: Deployment
22+
metadata:
23+
name: percona-server-mysql-operator
24+
status:
25+
availableReplicas: 1
26+
observedGeneration: 1
27+
readyReplicas: 1
28+
replicas: 1
29+
updatedReplicas: 1
30+
---
31+
apiVersion: v1
32+
kind: Pod
33+
metadata:
34+
name: mysql-client
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestStep
3+
timeout: 10
4+
commands:
5+
- script: |-
6+
set -o errexit
7+
set -o xtrace
8+
9+
source ../../functions
10+
11+
deploy_operator
12+
deploy_non_tls_cluster_secrets
13+
deploy_tls_cluster_secrets
14+
deploy_client
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestAssert
3+
timeout: 420
4+
---
5+
apiVersion: apps/v1
6+
kind: StatefulSet
7+
metadata:
8+
generation: 1
9+
name: gr-users-mysql
10+
status:
11+
observedGeneration: 1
12+
replicas: 3
13+
readyReplicas: 3
14+
---
15+
apiVersion: apps/v1
16+
kind: Deployment
17+
metadata:
18+
generation: 1
19+
name: gr-users-router
20+
status:
21+
observedGeneration: 1
22+
readyReplicas: 3
23+
replicas: 3
24+
updatedReplicas: 3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestStep
3+
timeout: 10
4+
commands:
5+
- script: |-
6+
set -o errexit
7+
set -o xtrace
8+
9+
source ../../functions
10+
11+
get_cr \
12+
| yq eval '.spec.mysql.clusterType="group-replication"' - \
13+
| yq eval '.spec.mysql.size=3' - \
14+
| yq eval '.spec.proxy.haproxy.enabled=false' - \
15+
| yq eval '.spec.proxy.router.enabled=true' - \
16+
| yq eval '.spec.proxy.router.size=3' - \
17+
| kubectl -n "${NAMESPACE}" apply -f -

0 commit comments

Comments
 (0)