Skip to content

Commit

Permalink
Make the db-name & table-name common for maria, mongo & mysql (#733)
Browse files Browse the repository at this point in the history
Signed-off-by: Arnob kumar saha <[email protected]>
  • Loading branch information
ArnobKumarSaha authored Nov 15, 2023
1 parent 41dbfff commit 85ed7ab
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
5 changes: 4 additions & 1 deletion pkg/data/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ limitations under the License.
package data

const (
actor = "kubedb-cli"
KubeDBDatabaseName = "kubedb_cli"
actor = KubeDBDatabaseName
KubeDBTableName = "kubedb_table"
KubeDBCollectionName = KubeDBTableName
)
17 changes: 8 additions & 9 deletions pkg/data/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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),
Expand Down
8 changes: 3 additions & 5 deletions pkg/data/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 85ed7ab

Please sign in to comment.