Skip to content

Commit 42f84db

Browse files
authored
Merge pull request #997 from percona/K8SPS-265
K8SPS-265 and K8SPS-357
2 parents 34a864f + bb076fa commit 42f84db

File tree

6 files changed

+37
-15
lines changed

6 files changed

+37
-15
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: 3 additions & 5 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"
@@ -221,7 +220,7 @@ func (r *PerconaServerMySQLReconciler) deleteMySQLPods(ctx context.Context, cr *
221220
return errors.Wrap(err, "get operator password")
222221
}
223222

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

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

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

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

273272
log.Info("Removing member from GR", "member", pod.Name, "memberState", state)
274273
err = mysh.RemoveInstanceWithExec(ctx, cr.InnoDBClusterName(), podUri)
@@ -579,7 +578,6 @@ func (r *PerconaServerMySQLReconciler) reconcileDatabase(ctx context.Context, cr
579578
}
580579

581580
if cr.Spec.UpdateStrategy == apiv1alpha1.SmartUpdateStatefulSetStrategyType {
582-
log.Info("Performing smart update for StatefulSet")
583581
return r.smartUpdate(ctx, sts, cr)
584582
}
585583

@@ -1102,7 +1100,7 @@ func (r *PerconaServerMySQLReconciler) rescanClusterIfNeeded(ctx context.Context
11021100
return errors.Wrap(err, "get operator password")
11031101
}
11041102

1105-
uri := fmt.Sprintf("%s:%s@%s", apiv1alpha1.UserOperator, operatorPass, mysql.PodFQDN(cr, pod))
1103+
uri := getMySQLURI(apiv1alpha1.UserOperator, operatorPass, mysql.PodFQDN(cr, pod))
11061104

11071105
msh, err := mysqlsh.NewWithExec(r.ClientCmd, pod, uri)
11081106
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)