Skip to content

Commit 6f7dd41

Browse files
K8SPS-160: SmartUpdate (#405)
* Add UpdateStrategy option. * Apply appropriate updateStrategy to statefulSets. * Implement SmartUpdate feature. * Improve implementation and set updateStrategy to SmartUpdate by default in CR. * Update tests. * Implement check if node is ready (status is active/online). * Fix lint issue. * Fix test. * Update e2e tests. * Update pkg/mysql/mysql.go Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Improved smartUpdate algorithm. * Fix haproxy e2e test. * Add e2e test and improve smart update logic. * Fix updating status, initializing state for the whole duration of sts ugrade. * Update e2e test. * Reorder tests. * Minor refactor. * Delete pod a wait for sts.Status.ReadyReplicas to be updated properly. * Refactor appStatus. --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 7f99389 commit 6f7dd41

27 files changed

+528
-30
lines changed

api/v1alpha1/perconaservermysql_types.go

Lines changed: 28 additions & 17 deletions
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 {
@@ -674,6 +676,12 @@ func (cr *PerconaServerMySQL) CheckNSetDefaults(ctx context.Context, serverVersi
674676
cr.Spec.SSLSecretName = cr.Name + "-ssl"
675677
}
676678

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+
677685
return nil
678686
}
679687

@@ -893,6 +901,9 @@ func init() {
893901
SchemeBuilder.Register(&PerconaServerMySQL{}, &PerconaServerMySQLList{})
894902
}
895903

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

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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ one-pod
1616
scaling
1717
service-per-pod
1818
sidecars
19+
smart-update
1920
tls-cert-manager
2021
users

e2e-tests/run-minikube.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ haproxy
1313
init-deploy
1414
one-pod
1515
sidecars
16+
smart-update
1617
tls-cert-manager
1718
users
1819
version-service

e2e-tests/run-pr.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ one-pod
2020
scaling
2121
service-per-pod
2222
sidecars
23+
smart-update
2324
tls-cert-manager
2425
users
2526
version-service

e2e-tests/run-release.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ one-pod
1919
scaling
2020
service-per-pod
2121
sidecars
22+
smart-update
2223
tls-cert-manager
2324
users
2425
version-service

e2e-tests/tests/haproxy/01-create-cluster.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ commands:
1010
1111
get_cr \
1212
| yq eval '.spec.allowUnsafeConfigurations=false' - \
13+
| yq eval '.spec.updateStrategy="RollingUpdate"' - \
1314
| yq eval '.spec.mysql.clusterType="async"' - \
1415
| yq eval '.spec.orchestrator.enabled=true' - \
1516
| yq eval '.spec.proxy.haproxy.enabled=true' - \

0 commit comments

Comments
 (0)