From 9aedbd3831d8162d3347cb5a08019c75ebc59c2b Mon Sep 17 00:00:00 2001 From: Kazuhito MATSUDA Date: Wed, 11 Nov 2020 16:00:51 +0900 Subject: [PATCH] Use --defaults-extra-file option to exec mysql command. Signed-off-by: Kazuhito MATSUDA --- cmd/kubectl-moco/cmd/mysql.go | 8 +++----- controllers/mysqlcluster_controller_test.go | 1 - 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/cmd/kubectl-moco/cmd/mysql.go b/cmd/kubectl-moco/cmd/mysql.go index c3dbad99a..76d4eda08 100644 --- a/cmd/kubectl-moco/cmd/mysql.go +++ b/cmd/kubectl-moco/cmd/mysql.go @@ -2,6 +2,7 @@ package cmd import ( "context" + "fmt" "os" "time" @@ -54,12 +55,9 @@ func runMySQLCommand(ctx context.Context, clusterName string, cmd *cobra.Command if err != nil { return err } - password, err := getPassword(ctx, moco.UniqueName(cluster), mysqlConfig.user) - if err != nil { - return err - } - commands := append([]string{podName, "--", "mysql", "-u", mysqlConfig.user, "-p" + password}, args...) + myCnfPath := fmt.Sprintf("%s/%s-my.cnf", moco.MyCnfSecretPath, mysqlConfig.user) + commands := append([]string{podName, "--", "mysql", "--defaults-extra-file=" + myCnfPath}, args...) argsLenAtDash := 2 options := &cmdexec.ExecOptions{ StreamOptions: cmdexec.StreamOptions{ diff --git a/controllers/mysqlcluster_controller_test.go b/controllers/mysqlcluster_controller_test.go index 5f6afa899..ca640bedb 100644 --- a/controllers/mysqlcluster_controller_test.go +++ b/controllers/mysqlcluster_controller_test.go @@ -144,7 +144,6 @@ var _ = Describe("MySQLCluster controller", func() { Expect(initSecret.Data).Should(HaveKey(moco.ReplicationPasswordKey)) Expect(initSecret.Data).Should(HaveKey(moco.CloneDonorPasswordKey)) Expect(initSecret.Data).Should(HaveKey(moco.MiscPasswordKey)) - Expect(initSecret.Data).Should(HaveKey(moco.MiscPasswordKey)) ctrlSecret := &corev1.Secret{} err = k8sClient.Get(ctx, client.ObjectKey{Namespace: ctrlSecretNS, Name: ctrlSecretName}, ctrlSecret)