Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed image values for MongoDB and PostgresDB charts in integration tests #1831

Merged
merged 1 commit into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Removed image values for MongoDB and PostgresDB charts in integration…
… tests

- removed usage of kanister images while installing MongoDB and PostgresDB
helm charts
- fixed minor issues in formatting
  • Loading branch information
shahpratikr committed Jan 4, 2023
commit 742008bca106d86f85362ea7bb378a1f8d84ae87
14 changes: 6 additions & 8 deletions pkg/app/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ func NewMongoDB(name string) HelmApp {
Chart: "mongodb",
Values: map[string]string{
"architecture": "replicaset",
"image.registry": "ghcr.io",
"image.repository": "kanisterio/mongodb",
"image.tag": "v9.99.9-dev",
viveksinghggits marked this conversation as resolved.
Show resolved Hide resolved
"image.pullPolicy": "Always",
},
},
Expand Down Expand Up @@ -153,15 +150,15 @@ func (mongo *MongoDB) GetClusterScopedResources(ctx context.Context) []crv1alpha

func (mongo *MongoDB) Ping(ctx context.Context) error {
log.Print("Pinging the application.", field.M{"app": mongo.name})
pingCMD := []string{"sh", "-c", fmt.Sprintf("mongo admin --authenticationDatabase admin -u %s -p $MONGODB_ROOT_PASSWORD --quiet --eval \"rs.secondaryOk(); db\"", mongo.username)}
pingCMD := []string{"sh", "-c", fmt.Sprintf("mongosh admin --authenticationDatabase admin -u %s -p $MONGODB_ROOT_PASSWORD --quiet --eval \"db\"", mongo.username)}
_, stderr, err := mongo.execCommand(ctx, pingCMD)
if err != nil {
return errors.Wrapf(err, "Error while pinging the mongodb application %s", stderr)
}

// even after ping is successful, it takes some time for primary pod to becomd the master
// we will have to wait for that so that the write subsequent write requests wont fail.
isMasterCMD := []string{"sh", "-c", fmt.Sprintf(" mongo admin --authenticationDatabase admin -u %s -p $MONGODB_ROOT_PASSWORD --quiet --eval \"JSON.stringify(db.isMaster())\"", mongo.username)}
isMasterCMD := []string{"sh", "-c", fmt.Sprintf("mongosh admin --authenticationDatabase admin -u %s -p $MONGODB_ROOT_PASSWORD --quiet --eval \"JSON.stringify(db.isMaster())\"", mongo.username)}
stdout, stderr, err := mongo.execCommand(ctx, isMasterCMD)
if err != nil {
return errors.Wrapf(err, "Error %s checking if the pod is master.", stderr)
Expand All @@ -183,7 +180,7 @@ func (mongo *MongoDB) Ping(ctx context.Context) error {

func (mongo *MongoDB) Insert(ctx context.Context) error {
log.Print("Inserting documents into collection.", field.M{"app": mongo.name})
insertCMD := []string{"sh", "-c", fmt.Sprintf("mongo admin --authenticationDatabase admin -u %s -p $MONGODB_ROOT_PASSWORD --quiet --eval \"db.restaurants.insert({'_id': '%s','name' : 'Tom', 'cuisine' : 'Hawaiian', 'id' : '8675309'})\"", mongo.username, uuid.New())}
insertCMD := []string{"sh", "-c", fmt.Sprintf("mongosh admin --authenticationDatabase admin -u %s -p $MONGODB_ROOT_PASSWORD --quiet --eval \"db.restaurants.insertOne({'_id': '%s','name' : 'Tom', 'cuisine' : 'Hawaiian', 'id' : '8675309'})\"", mongo.username, uuid.New())}
_, stderr, err := mongo.execCommand(ctx, insertCMD)
if err != nil {
return errors.Wrapf(err, "Error %s while inserting data data into mongodb collection.", stderr)
Expand All @@ -192,9 +189,10 @@ func (mongo *MongoDB) Insert(ctx context.Context) error {
log.Print("Insertion of documents into collection was successful.", field.M{"app": mongo.name})
return nil
}

func (mongo *MongoDB) Count(ctx context.Context) (int, error) {
log.Print("Counting documents of collection.", field.M{"app": mongo.name})
countCMD := []string{"sh", "-c", fmt.Sprintf("mongo admin --authenticationDatabase admin -u %s -p $MONGODB_ROOT_PASSWORD --quiet --eval \"rs.secondaryOk(); db.restaurants.count()\"", mongo.username)}
countCMD := []string{"sh", "-c", fmt.Sprintf("mongosh admin --authenticationDatabase admin -u %s -p $MONGODB_ROOT_PASSWORD --quiet --eval \"db.restaurants.countDocuments()\"", mongo.username)}
stdout, stderr, err := mongo.execCommand(ctx, countCMD)
if err != nil {
return 0, errors.Wrapf(err, "Error %s while counting the data in mongodb collection.", stderr)
Expand All @@ -213,7 +211,7 @@ func (mongo *MongoDB) Reset(ctx context.Context) error {
// delete all the entries from the restaurants collection
// we are not deleting the database because we are dealing with admin database here
// and deletion admin database is prohibited
deleteDBCMD := []string{"sh", "-c", fmt.Sprintf("mongo admin --authenticationDatabase admin -u %s -p $MONGODB_ROOT_PASSWORD --quiet --eval \"db.restaurants.drop()\"", mongo.username)}
deleteDBCMD := []string{"sh", "-c", fmt.Sprintf("mongosh admin --authenticationDatabase admin -u %s -p $MONGODB_ROOT_PASSWORD --quiet --eval \"db.restaurants.drop()\"", mongo.username)}
stdout, stderr, err := mongo.execCommand(ctx, deleteDBCMD)
return errors.Wrapf(err, "Error %s, resetting the mongodb application. stdout is %s", stderr, stdout)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/postgresql-deploymentconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (pgres *PostgreSQLDepConfig) Count(ctx context.Context) (int, error) {

out := strings.Fields(stdout)
if len(out) < 4 {
return 0, fmt.Errorf("Unknown response for count query")
return 0, fmt.Errorf("unknown response for count query")
shahpratikr marked this conversation as resolved.
Show resolved Hide resolved
}
count, err := strconv.Atoi(out[2])
if err != nil {
Expand Down
27 changes: 10 additions & 17 deletions pkg/app/postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,10 @@ func NewPostgresDB(name string, subPath string) App {
RepoURL: helm.BitnamiRepoURL,
Chart: "postgresql",
Values: map[string]string{
"image.registry": "ghcr.io",
"image.repository": "kanisterio/postgresql",
"image.tag": "v9.99.9-dev",
"image.pullPolicy": "Always",
"postgresqlPassword": "test@54321",
"postgresqlExtendedConf.archiveCommand": "envdir /bitnami/postgresql/data/env wal-e wal-push %p",
"postgresqlExtendedConf.archiveMode": "true",
"postgresqlExtendedConf.archiveTimeout": "60",
"postgresqlExtendedConf.walLevel": "archive",
"volumePermissions.enabled": "true",
"persistence.subPath": subPath,
"image.pullPolicy": "Always",
"auth.postgresPassword": "test@54321",
"volumePermissions.enabled": "true",
"persistence.subPath": subPath,
},
},
}
Expand Down Expand Up @@ -143,7 +136,7 @@ func (pdb *PostgresDB) Ping(ctx context.Context) error {
}

func (pdb PostgresDB) Insert(ctx context.Context) error {
cmd := "PGPASSWORD=${POSTGRES_PASSWORD} psql -d test -c \"INSERT INTO COMPANY (NAME,AGE,CREATED_AT) VALUES ('foo', 32, now());\""
cmd := "PGPASSWORD=${POSTGRES_PASSWORD} psql -U postgres -d test -c \"INSERT INTO COMPANY (NAME,AGE,CREATED_AT) VALUES ('foo', 32, now());\""
_, stderr, err := pdb.execCommand(ctx, []string{"sh", "-c", cmd})
if err != nil {
return errors.Wrapf(err, "Failed to create db in postgresql. %s", stderr)
Expand All @@ -153,15 +146,15 @@ func (pdb PostgresDB) Insert(ctx context.Context) error {
}

func (pdb PostgresDB) Count(ctx context.Context) (int, error) {
cmd := "PGPASSWORD=${POSTGRES_PASSWORD} psql -d test -c 'SELECT COUNT(*) FROM company;'"
cmd := "PGPASSWORD=${POSTGRES_PASSWORD} psql -U postgres -d test -c 'SELECT COUNT(*) FROM company;'"
stdout, stderr, err := pdb.execCommand(ctx, []string{"sh", "-c", cmd})
if err != nil {
return 0, errors.Wrapf(err, "Failed to count db entries in postgresql. %s ", stderr)
}

out := strings.Fields(stdout)
if len(out) < 4 {
return 0, fmt.Errorf("Unknown response for count query")
return 0, fmt.Errorf("unknown response for count query")
}
count, err := strconv.Atoi(out[2])
if err != nil {
Expand All @@ -173,7 +166,7 @@ func (pdb PostgresDB) Count(ctx context.Context) (int, error) {

func (pdb PostgresDB) Reset(ctx context.Context) error {
// Delete database if exists
cmd := "PGPASSWORD=${POSTGRES_PASSWORD} psql -c 'DROP DATABASE IF EXISTS test;'"
cmd := "PGPASSWORD=${POSTGRES_PASSWORD} psql -U postgres -c 'DROP DATABASE IF EXISTS test;'"
_, stderr, err := pdb.execCommand(ctx, []string{"sh", "-c", cmd})
if err != nil {
return errors.Wrapf(err, "Failed to drop db from postgresql. %s ", stderr)
Expand All @@ -186,14 +179,14 @@ func (pdb PostgresDB) Reset(ctx context.Context) error {
// Initialize is used to initialize the database or create schema
func (pdb PostgresDB) Initialize(ctx context.Context) error {
// Create database
cmd := "PGPASSWORD=${POSTGRES_PASSWORD} psql -c 'CREATE DATABASE test;'"
cmd := "PGPASSWORD=${POSTGRES_PASSWORD} psql -U postgres -c 'CREATE DATABASE test;'"
_, stderr, err := pdb.execCommand(ctx, []string{"sh", "-c", cmd})
if err != nil {
return errors.Wrapf(err, "Failed to create db in postgresql. %s ", stderr)
}

// Create table
cmd = "PGPASSWORD=${POSTGRES_PASSWORD} psql -d test -c 'CREATE TABLE COMPANY(ID SERIAL PRIMARY KEY NOT NULL, NAME TEXT NOT NULL, AGE INT NOT NULL, CREATED_AT TIMESTAMP);'"
cmd = "PGPASSWORD=${POSTGRES_PASSWORD} psql -U postgres -d test -c 'CREATE TABLE COMPANY(ID SERIAL PRIMARY KEY NOT NULL, NAME TEXT NOT NULL, AGE INT NOT NULL, CREATED_AT TIMESTAMP);'"
_, stderr, err = pdb.execCommand(ctx, []string{"sh", "-c", cmd})
if err != nil {
return errors.Wrapf(err, "Failed to create table in postgresql. %s ", stderr)
Expand Down
6 changes: 3 additions & 3 deletions pkg/app/rds_postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (pdb *RDSPostgresDB) Init(ctx context.Context) error {
if pdb.region == "" {
pdb.region, ok = os.LookupEnv(aws.Region)
if !ok {
return fmt.Errorf("Env var %s is not set", aws.Region)
return fmt.Errorf("env var %s is not set", aws.Region)
shahpratikr marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand All @@ -107,11 +107,11 @@ func (pdb *RDSPostgresDB) Init(ctx context.Context) error {

pdb.accessID, ok = os.LookupEnv(aws.AccessKeyID)
if !ok {
return fmt.Errorf("Env var %s is not set", aws.AccessKeyID)
return fmt.Errorf("env var %s is not set", aws.AccessKeyID)
shahpratikr marked this conversation as resolved.
Show resolved Hide resolved
}
pdb.secretKey, ok = os.LookupEnv(aws.SecretAccessKey)
if !ok {
return fmt.Errorf("Env var %s is not set", aws.SecretAccessKey)
return fmt.Errorf("env var %s is not set", aws.SecretAccessKey)
shahpratikr marked this conversation as resolved.
Show resolved Hide resolved
}
return nil
}
Expand Down