Skip to content

Commit 5dcf1a0

Browse files
authored
Merge branch 'main' into K8SPS-417
2 parents e36bf12 + 076a985 commit 5dcf1a0

File tree

6 files changed

+44
-18
lines changed

6 files changed

+44
-18
lines changed

build/ps-pre-stop.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ fi
88

99
LOG_FILE=/var/lib/mysql/pre-stop.log
1010
NAMESPACE=$(</var/run/secrets/kubernetes.io/serviceaccount/namespace)
11-
OPERATOR_PASSWORD=$(</etc/mysql/mysql-users-secret/operator)
11+
OPERATOR_PASSWORD=$(perl -MURI::Escape -e 'print uri_escape($ARGV[0]);' "$(</etc/mysql/mysql-users-secret/operator)")
1212
FQDN="${HOSTNAME}.${SERVICE_NAME}.${NAMESPACE}"
1313
POD_IP=$(hostname -I | awk '{print $1}')
1414

1515
echo "$(date +%Y-%m-%dT%H:%M:%S%Z): Removing ${FQDN} from cluster" >>${LOG_FILE}
16-
mysqlsh --js -i -h "${POD_IP}" -P 33062 -u operator -p"${OPERATOR_PASSWORD}" -e "dba.getCluster().removeInstance('${FQDN}:3306')" >>${LOG_FILE} 2>&1
16+
17+
mysqlsh --js -i \
18+
-h "${POD_IP}" -P 33062 \
19+
-u operator -p"${OPERATOR_PASSWORD}" \
20+
-e "dba.getCluster().removeInstance('${FQDN}:3306')" >>${LOG_FILE} 2>&1

cmd/bootstrap/group_replication.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@ func (m *mysqlsh) getURI() string {
5555
if err != nil {
5656
return ""
5757
}
58-
escapedPass := url.QueryEscape(operatorPass)
5958

60-
return fmt.Sprintf("%s:%s@%s", apiv1alpha1.UserOperator, escapedPass, m.host)
59+
return fmt.Sprintf("%s:%s@%s", apiv1alpha1.UserOperator, url.QueryEscape(operatorPass), m.host)
6160
}
6261

6362
func (m *mysqlsh) run(ctx context.Context, cmd string) (bytes.Buffer, bytes.Buffer, error) {

pkg/controller/ps/controller.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"crypto/md5"
2222
"encoding/json"
2323
"fmt"
24-
"net/url"
2524
"reflect"
2625
"slices"
2726
"strconv"
@@ -222,7 +221,7 @@ func (r *PerconaServerMySQLReconciler) deleteMySQLPods(ctx context.Context, cr *
222221
return errors.Wrap(err, "get operator password")
223222
}
224223

225-
firstPodUri := fmt.Sprintf("%s:%s@%s", apiv1alpha1.UserOperator, url.QueryEscape(operatorPass), mysql.PodFQDN(cr, &firstPod))
224+
firstPodUri := getMySQLURI(apiv1alpha1.UserOperator, operatorPass, mysql.PodFQDN(cr, &firstPod))
226225

227226
um := database.NewReplicationManager(&firstPod, r.ClientCmd, apiv1alpha1.UserOperator, operatorPass, mysql.PodFQDN(cr, &firstPod))
228227

@@ -269,7 +268,7 @@ func (r *PerconaServerMySQLReconciler) deleteMySQLPods(ctx context.Context, cr *
269268
continue
270269
}
271270

272-
podUri := fmt.Sprintf("%s:%s@%s", apiv1alpha1.UserOperator, operatorPass, podFQDN)
271+
podUri := getMySQLURI(apiv1alpha1.UserOperator, operatorPass, podFQDN)
273272

274273
log.Info("Removing member from GR", "member", pod.Name, "memberState", state)
275274
err = mysh.RemoveInstanceWithExec(ctx, cr.InnoDBClusterName(), podUri)
@@ -571,7 +570,6 @@ func (r *PerconaServerMySQLReconciler) reconcileDatabase(ctx context.Context, cr
571570
return errors.Wrap(err, "get statefulset")
572571
}
573572
if cr.Spec.UpdateStrategy == apiv1alpha1.SmartUpdateStatefulSetStrategyType {
574-
log.Info("Performing smart update for StatefulSet")
575573
return r.smartUpdate(ctx, sts, cr)
576574
}
577575

@@ -781,7 +779,7 @@ func (r *PerconaServerMySQLReconciler) reconcileOrchestrator(ctx context.Context
781779
if err != nil {
782780
return nil
783781
}
784-
g, gCtx := errgroup.WithContext(context.Background())
782+
g, gCtx := errgroup.WithContext(ctx)
785783

786784
if len(raftNodes) > len(existingNodes) {
787785
newPeers := util.Difference(raftNodes, existingNodes)
@@ -793,7 +791,9 @@ func (r *PerconaServerMySQLReconciler) reconcileOrchestrator(ctx context.Context
793791
})
794792
}
795793

796-
log.Error(g.Wait(), "Orchestrator add peers", "peers", newPeers)
794+
if err := g.Wait(); err != nil && !cr.Spec.Pause {
795+
log.Error(err, "Orchestrator add peers", "peers", newPeers)
796+
}
797797
} else {
798798
oldPeers := util.Difference(existingNodes, raftNodes)
799799

@@ -804,7 +804,9 @@ func (r *PerconaServerMySQLReconciler) reconcileOrchestrator(ctx context.Context
804804
})
805805
}
806806

807-
log.Error(g.Wait(), "Orchestrator remove peers", "peers", oldPeers)
807+
if err := g.Wait(); err != nil && !cr.Spec.Pause {
808+
log.Error(err, "Orchestrator remove peers", "peers", oldPeers)
809+
}
808810
}
809811

810812
return nil
@@ -1063,7 +1065,7 @@ func (r *PerconaServerMySQLReconciler) rescanClusterIfNeeded(ctx context.Context
10631065
return errors.Wrap(err, "get operator password")
10641066
}
10651067

1066-
uri := fmt.Sprintf("%s:%s@%s", apiv1alpha1.UserOperator, operatorPass, mysql.PodFQDN(cr, pod))
1068+
uri := getMySQLURI(apiv1alpha1.UserOperator, operatorPass, mysql.PodFQDN(cr, pod))
10671069

10681070
msh, err := mysqlsh.NewWithExec(r.ClientCmd, pod, uri)
10691071
if err != nil {

pkg/controller/ps/crash_recovery.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import (
44
"bytes"
55
"context"
66
"fmt"
7-
"net/url"
87
"strings"
8+
"time"
99

1010
"github.com/pkg/errors"
1111
corev1 "k8s.io/api/core/v1"
1212
"k8s.io/apimachinery/pkg/labels"
13+
"k8s.io/apimachinery/pkg/util/wait"
14+
"k8s.io/client-go/util/retry"
1315
"sigs.k8s.io/controller-runtime/pkg/client"
1416
logf "sigs.k8s.io/controller-runtime/pkg/log"
1517

@@ -74,8 +76,8 @@ func (r *PerconaServerMySQLReconciler) reconcileFullClusterCrash(ctx context.Con
7476
return errors.Wrap(err, "get operator password")
7577
}
7678

77-
podFQDN := fmt.Sprintf("%s.%s.%s", pod.Name, mysql.ServiceName(cr), cr.Namespace)
78-
podUri := fmt.Sprintf("%s:%s@%s", apiv1alpha1.UserOperator, url.QueryEscape(operatorPass), podFQDN)
79+
podFQDN := mysql.PodFQDN(cr, &pod)
80+
podUri := getMySQLURI(apiv1alpha1.UserOperator, operatorPass, podFQDN)
7981

8082
mysh, err := mysqlsh.NewWithExec(r.ClientCmd, &pod, podUri)
8183
if err != nil {
@@ -103,7 +105,22 @@ func (r *PerconaServerMySQLReconciler) reconcileFullClusterCrash(ctx context.Con
103105
break
104106
}
105107

106-
primary, err := r.getPrimaryPod(ctx, cr)
108+
var primary *corev1.Pod
109+
err = retry.OnError(wait.Backoff{
110+
Duration: 10 * time.Second,
111+
Factor: 1.5,
112+
Steps: 10,
113+
}, func(err error) bool { return true }, func() error {
114+
var err error
115+
116+
primary, err = r.getPrimaryPod(ctx, cr)
117+
if err != nil {
118+
log.V(1).Error(err, "failed to get primary pod")
119+
return err
120+
}
121+
122+
return nil
123+
})
107124
if err != nil {
108125
log.Error(err, "failed to get primary pod")
109126
break

pkg/controller/ps/status.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"context"
66
"fmt"
7-
"net/url"
87
"strings"
98

109
"github.com/pkg/errors"
@@ -252,7 +251,7 @@ func (r *PerconaServerMySQLReconciler) isGRReady(ctx context.Context, cr *apiv1a
252251
return false, nil
253252
}
254253

255-
uri := fmt.Sprintf("%s:%s@%s", apiv1alpha1.UserOperator, url.QueryEscape(operatorPass), mysql.PodFQDN(cr, pod))
254+
uri := getMySQLURI(apiv1alpha1.UserOperator, operatorPass, mysql.PodFQDN(cr, pod))
256255

257256
msh, err := mysqlsh.NewWithExec(r.ClientCmd, pod, uri)
258257
if err != nil {

pkg/controller/ps/user.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"context"
66
"fmt"
7+
"net/url"
78
"strings"
89

910
"github.com/pkg/errors"
@@ -448,3 +449,7 @@ func (r *PerconaServerMySQLReconciler) passwordsPropagated(ctx context.Context,
448449
log.Info("Updated password propagated")
449450
return nil
450451
}
452+
453+
func getMySQLURI(user apiv1alpha1.SystemUser, password, host string) string {
454+
return fmt.Sprintf("%s:%s@%s", user, url.QueryEscape(password), host)
455+
}

0 commit comments

Comments
 (0)