Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions pkg/apis/pxc/v1/pxc_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1588,8 +1588,15 @@ func (cr *PerconaXtraDBCluster) CompareVersionWith(ver string) int {

// CompareMySQLVersion compares given version to current MySQL version.
// Returns -1, 0, or 1 if given version is smaller, equal, or larger than the current version, respectively.
func (cr *PerconaXtraDBCluster) CompareMySQLVersion(ver string) int {
return v.Must(v.NewVersion(cr.Status.PXC.Version)).Compare(v.Must(v.NewVersion(ver)))
func (cr *PerconaXtraDBCluster) CompareMySQLVersion(ver string) (int, error) {
if cr.Status.PXC.Version == "" {
return -1, errors.New("pxc version is empty")
}
statusVer, err := v.NewVersion(cr.Status.PXC.Version)
if err != nil {
return -1, errors.Wrap(err, "failed to parse pxc version")
}
return statusVer.Compare(v.Must(v.NewVersion(ver))), nil
}

// ConfigHasKey check if cr.Spec.PXC.Configuration has given key in given section
Expand Down
26 changes: 20 additions & 6 deletions pkg/controller/pxc/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (r *ReconcilePerconaXtraDBCluster) reconcileReplication(ctx context.Context
sfs := statefulset.NewNode(cr)

listRaw := corev1.PodList{}
err := r.client.List(context.TODO(),
err := r.client.List(ctx,
&listRaw,
&client.ListOptions{
Namespace: cr.Namespace,
Expand Down Expand Up @@ -159,8 +159,12 @@ func (r *ReconcilePerconaXtraDBCluster) reconcileReplication(ctx context.Context
if err != nil {
return errors.Wrap(err, "failed to get current db version")
}
parsedDBVer, err := version.NewVersion(dbVer)
if err != nil {
return errors.Wrapf(err, "failed to parse version: %s", dbVer)
}

if version.Must(version.NewVersion(dbVer)).Compare(minReplicationVersion) < 0 {
if parsedDBVer.Compare(minReplicationVersion) < 0 {
return nil
}

Expand Down Expand Up @@ -200,7 +204,7 @@ func (r *ReconcilePerconaXtraDBCluster) reconcileReplication(ctx context.Context
}
log.V(1).Info("Remove replication label from pod", "pod", pod.Name)
delete(pod.Labels, replicationPodLabel)
err = r.client.Update(context.TODO(), &pod)
err = r.client.Update(ctx, &pod)
if err != nil {
return errors.Wrap(err, "failed to remove primary label from secondary pod")
}
Expand All @@ -209,15 +213,15 @@ func (r *ReconcilePerconaXtraDBCluster) reconcileReplication(ctx context.Context

if _, ok := primaryPod.Labels[replicationPodLabel]; !ok {
primaryPod.Labels[replicationPodLabel] = "true"
err = r.client.Update(context.TODO(), primaryPod)
err = r.client.Update(ctx, primaryPod)
if err != nil {
return errors.Wrap(err, "add label to main replica pod")
}
log.Info("Replication pod has changed", "new replication pod", primaryPod.Name)
}

sysUsersSecretObj := corev1.Secret{}
err = r.client.Get(context.TODO(),
err = r.client.Get(ctx,
types.NamespacedName{
Namespace: cr.Namespace,
Name: internalSecretsPrefix + cr.Name,
Expand All @@ -236,7 +240,17 @@ func (r *ReconcilePerconaXtraDBCluster) reconcileReplication(ctx context.Context
}

authPluginVar := "default_authentication_plugin"
if cr.CompareMySQLVersion("8.4.0") >= 0 {
is840 := false
if cr.Status.PXC.Version != "" {
compare840, err := cr.CompareMySQLVersion("8.4.0")
if err != nil {
return errors.Wrap(err, "failed to compare mysql version")
}
is840 = compare840 >= 0
} else {
is840 = parsedDBVer.Compare(version.Must(version.NewVersion("8.4.0"))) >= 0
}
if is840 {
authPluginVar = "authentication_policy"
}

Expand Down
Loading