From 85ed7abd0c8bb53ded9ef90b3197bca2cb9fb29d Mon Sep 17 00:00:00 2001 From: Arnob Kumar Saha Date: Wed, 15 Nov 2023 19:38:40 +0600 Subject: [PATCH] Make the db-name & table-name common for maria, mongo & mysql (#733) Signed-off-by: Arnob kumar saha --- pkg/data/const.go | 5 ++++- pkg/data/mongodb.go | 17 ++++++++--------- pkg/data/mysql.go | 8 +++----- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/pkg/data/const.go b/pkg/data/const.go index 1332b2ac9..799c5f44d 100644 --- a/pkg/data/const.go +++ b/pkg/data/const.go @@ -17,5 +17,8 @@ limitations under the License. package data const ( - actor = "kubedb-cli" + KubeDBDatabaseName = "kubedb_cli" + actor = KubeDBDatabaseName + KubeDBTableName = "kubedb_table" + KubeDBCollectionName = KubeDBTableName ) diff --git a/pkg/data/mongodb.go b/pkg/data/mongodb.go index 1270dfc84..56c7872e6 100644 --- a/pkg/data/mongodb.go +++ b/pkg/data/mongodb.go @@ -40,10 +40,9 @@ import ( ) const ( - mgCAFile = "/var/run/mongodb/tls/ca.crt" - mgPEMFile = "/var/run/mongodb/tls/client.pem" - mgTempPEMFile = "/tmp/client.pem" - mgCollectionName = "kubedb-testing" + mgCAFile = "/var/run/mongodb/tls/ca.crt" + mgPEMFile = "/var/run/mongodb/tls/client.pem" + mgTempPEMFile = "/tmp/client.pem" ) func InsertMongoDBDataCMD(f cmdutil.Factory) *cobra.Command { @@ -80,7 +79,7 @@ func InsertMongoDBDataCMD(f cmdutil.Factory) *cobra.Command { log.Fatal("rows need to be greater than 0") } - command := fmt.Sprintf("for(var i=1;i<=%d;i++){db[\"%s\"].insert({_id:\"doc\"+i,actor:\"%s\"})}", rows, mgCollectionName, actor) + command := fmt.Sprintf("for(var i=1;i<=%d;i++){db[\"%s\"].insert({_id:\"doc\"+i,actor:\"%s\"})}", rows, KubeDBCollectionName, actor) _, err = opts.executeCommand(command) if err != nil { log.Fatal(err) @@ -127,7 +126,7 @@ func VerifyMongoDBDataCMD(f cmdutil.Factory) *cobra.Command { log.Fatal("rows need to be greater than 0") } - command := fmt.Sprintf("db.runCommand({find:\"%s\",filter:{\"actor\":\"%s\"},batchSize:10000})", mgCollectionName, actor) + command := fmt.Sprintf("db.runCommand({find:\"%s\",filter:{\"actor\":\"%s\"},batchSize:10000})", KubeDBCollectionName, actor) command = fmt.Sprintf("JSON.stringify(%s)", command) out, err := opts.executeCommand(command) @@ -173,7 +172,7 @@ func DropMongoDBDataCMD(f cmdutil.Factory) *cobra.Command { log.Fatalln(err) } - command := fmt.Sprintf("db[\"%s\"].drop()", mgCollectionName) + command := fmt.Sprintf("db[\"%s\"].drop()", KubeDBCollectionName) _, err = opts.executeCommand(command) if err != nil { log.Fatal(err) @@ -345,7 +344,7 @@ func (opts *mongoDBOpts) getShellCommand(command string) (*shell.Session, error) mgCommand = append(mgCommand, c) } else { mgCommand = append(mgCommand, - "test", "--quiet", + KubeDBDatabaseName, "--quiet", fmt.Sprintf("--username=%s", opts.username), fmt.Sprintf("--password=%s", opts.pass), "--authenticationDatabase=admin", @@ -400,7 +399,7 @@ func (opts *mongoDBOpts) handleTLS() ([]interface{}, error) { } mgCommand := []interface{}{ - "mongo", "test", "--quiet", + "mongo", KubeDBDatabaseName, "--quiet", "--tls", fmt.Sprintf("--tlsCAFile=%v", mgCAFile), fmt.Sprintf("--tlsCertificateKeyFile=%v", mgPEMFile), diff --git a/pkg/data/mysql.go b/pkg/data/mysql.go index 6c93ba9dd..2e3050042 100644 --- a/pkg/data/mysql.go +++ b/pkg/data/mysql.go @@ -41,11 +41,9 @@ import ( ) const ( - myCaFile = "/etc/mysql/certs/ca.crt" - myCertFile = "/etc/mysql/certs/client.crt" - myKeyFile = "/etc/mysql/certs/client.key" - KubeDBDatabaseName = "kubedb_cli" - KubeDBTableName = "kubedb_table" + myCaFile = "/etc/mysql/certs/ca.crt" + myCertFile = "/etc/mysql/certs/client.crt" + myKeyFile = "/etc/mysql/certs/client.key" ) func InsertMySQLDataCMD(f cmdutil.Factory) *cobra.Command {