Skip to content

Commit

Permalink
Register different versions (3.11, 4.4, 4.5) of kanister OCP apps (#753)
Browse files Browse the repository at this point in the history
* Register different versions (3.11, 4.4, 4.5) of kanister OCP apps

* re-trigger

* Refactor the code a bit

* Export db version type

* Remove env var from mysql dep conf app

* Fix CI issue

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
viveksinghggits and mergify[bot] committed Sep 10, 2020
1 parent 7736794 commit 33fb9f7
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 27 deletions.
5 changes: 3 additions & 2 deletions Makefile
Expand Up @@ -41,7 +41,8 @@ DOCKER_CONFIG ?= "$(HOME)/.docker"

# Mention the vm-driver that should be used to install OpenShift
vm-driver ?= "kvm"

# The OCP version in which the OpenShift apps are going to run by default
ocp_version ?= "4.5"
###
### These variables should not need tweaking.
###
Expand Down Expand Up @@ -160,7 +161,7 @@ integration-test: build-dirs
@$(MAKE) run CMD='-c "./build/integration-test.sh short"'

openshift-test:
@/bin/bash ./build/integration-test.sh openshift
@/bin/bash ./build/integration-test.sh openshift $(ocp_version)

golint:
@$(MAKE) run CMD='-c "./build/golint.sh"'
Expand Down
28 changes: 24 additions & 4 deletions build/integration-test.sh
Expand Up @@ -27,7 +27,9 @@ TEST_OPTIONS="-tags=integration -timeout ${TEST_TIMEOUT} -check.suitep ${DOP}"
# Regex to match apps to run in short mode
SHORT_APPS="^PostgreSQL$|^PITRPostgreSQL|MySQL|Elasticsearch|^MongoDB$"
# OCAPPS has all the apps that are to be tested against openshift cluster
OC_APPS="MysqlDBDepConfig|MongoDBDepConfig|PostgreSQLDepConfig"
OC_APPS3_11="MysqlDBDepConfig$|MongoDBDepConfig$|PostgreSQLDepConfig$"
OC_APPS4_4="MysqlDBDepConfig4_4|MongoDBDepConfig4_4|PostgreSQLDepConfig4_4"
OC_APPS4_5="MysqlDBDepConfig4_5|MongoDBDepConfig4_5|PostgreSQLDepConfig4_5"

check_dependencies() {
# Check if minio is already deployed
Expand All @@ -49,7 +51,7 @@ Usage: ${0} <app-type>
Where app-type is one of [short|all]:
short: Runs e2e integration tests for part of apps
all: Runs e2e integration tests for all apps
oc: Runs e2e integration tests for apps that are to be tetsed against openshift cluster
openshift ocp_version=<ocp_version>: Runs e2e integration tests for apps that are to be tetsed against openshift cluster, OCP version can be provided using ocp_version argument
OR
You can also provide regex to match apps you want to run.
EOM
Expand All @@ -66,8 +68,26 @@ case "${1}" in
TEST_APPS=${SHORT_APPS}
;;
openshift)
# Run only openshift apps
TEST_APPS=${OC_APPS}
# TODO:// make sure the argument is named ocp_version
if [[ ${#@} == 1 ]]; then
usage
fi

case "${2}" in
"3.11")
TEST_APPS=${OC_APPS3_11}
;;
"4.4")
TEST_APPS=${OC_APPS4_4}
;;
"4.5")
TEST_APPS=${OC_APPS4_5}
;;
*)
echo "Only 3.11, 4.4 and 4.5 OCP versions are supported"
usage
;;
esac
;;
*)
TEST_APPS=${1}
Expand Down
11 changes: 7 additions & 4 deletions pkg/app/mongodb-deploymentconfig.go
Expand Up @@ -46,17 +46,20 @@ type MongoDBDepConfig struct {
osClient openshift.OSClient
params map[string]string
storageType storage
// dbTemplateVersion will most probably match with the OCP version
dbTemplateVersion DBTemplate
}

func NewMongoDBDepConfig(name string, storageType storage) App {
func NewMongoDBDepConfig(name string, templateVersion DBTemplate, storageType storage) App {
return &MongoDBDepConfig{
name: name,
user: "admin",
params: map[string]string{
"MONGODB_ADMIN_PASSWORD": "secretpassword",
},
osClient: openshift.NewOpenShiftClient(),
storageType: storageType,
osClient: openshift.NewOpenShiftClient(),
storageType: storageType,
dbTemplateVersion: templateVersion,
}
}

Expand All @@ -79,7 +82,7 @@ func (mongo *MongoDBDepConfig) Init(context.Context) error {
func (mongo *MongoDBDepConfig) Install(ctx context.Context, namespace string) error {
mongo.namespace = namespace

dbTemplate := getOpenShiftDBTemplate(mongoDepConfigName, mongo.storageType)
dbTemplate := getOpenShiftDBTemplate(mongoDepConfigName, mongo.dbTemplateVersion, mongo.storageType)

_, err := mongo.osClient.NewApp(ctx, mongo.namespace, dbTemplate, nil, mongo.params)

Expand Down
15 changes: 7 additions & 8 deletions pkg/app/mysql-deploymentconfig.go
Expand Up @@ -45,20 +45,19 @@ type MysqlDepConfig struct {
params map[string]string
storageType storage
osClient openshift.OSClient
envVar map[string]string
// dbTemplateVersion will most probably match with the OCP version
dbTemplateVersion DBTemplate
}

func NewMysqlDepConfig(name string, storageType storage) App {
func NewMysqlDepConfig(name string, templateVersion DBTemplate, storageType storage) App {
return &MysqlDepConfig{
name: name,
params: map[string]string{
"MYSQL_ROOT_PASSWORD": "secretpassword",
},
envVar: map[string]string{
"MYSQL_ROOT_PASSWORD": "secretpassword",
},
storageType: storageType,
osClient: openshift.NewOpenShiftClient(),
storageType: storageType,
osClient: openshift.NewOpenShiftClient(),
dbTemplateVersion: templateVersion,
}
}

Expand All @@ -81,7 +80,7 @@ func (mdep *MysqlDepConfig) Init(context.Context) error {
func (mdep *MysqlDepConfig) Install(ctx context.Context, namespace string) error {
mdep.namespace = namespace

dbTemplate := getOpenShiftDBTemplate(mysqlDepConfigName, mdep.storageType)
dbTemplate := getOpenShiftDBTemplate(mysqlDepConfigName, mdep.dbTemplateVersion, mdep.storageType)

oc := openshift.NewOpenShiftClient()
_, err := oc.NewApp(ctx, mdep.namespace, dbTemplate, nil, mdep.params)
Expand Down
9 changes: 6 additions & 3 deletions pkg/app/postgresql-deploymentconfig.go
Expand Up @@ -47,16 +47,19 @@ type PostgreSQLDepConfig struct {
opeshiftClient openshift.OSClient
envVar map[string]string
storageType storage
// dbTemplateVersion will most probably match with the OCP version
dbTemplateVersion DBTemplate
}

func NewPostgreSQLDepConfig(name string, storageType storage) App {
func NewPostgreSQLDepConfig(name string, templateVersion DBTemplate, storageType storage) App {
return &PostgreSQLDepConfig{
name: name,
opeshiftClient: openshift.NewOpenShiftClient(),
envVar: map[string]string{
"POSTGRESQL_ADMIN_PASSWORD": "secretpassword",
},
storageType: storageType,
storageType: storageType,
dbTemplateVersion: templateVersion,
}
}

Expand All @@ -78,7 +81,7 @@ func (pgres *PostgreSQLDepConfig) Init(ctx context.Context) error {
func (pgres *PostgreSQLDepConfig) Install(ctx context.Context, namespace string) error {
pgres.namespace = namespace

dbTemplate := getOpenShiftDBTemplate(postgresDepConfigName, pgres.storageType)
dbTemplate := getOpenShiftDBTemplate(postgresDepConfigName, pgres.dbTemplateVersion, pgres.storageType)

_, err := pgres.opeshiftClient.NewApp(ctx, pgres.namespace, dbTemplate, pgres.envVar, nil)
if err != nil {
Expand Down
15 changes: 12 additions & 3 deletions pkg/app/utils.go
Expand Up @@ -21,16 +21,25 @@ import (
)

const (
dbTemplateURI = "https://raw.githubusercontent.com/openshift/origin/v3.11.0/examples/db-templates/%s-%s-template.json"
dbTemplateURI = "https://raw.githubusercontent.com/openshift/origin/%s/examples/db-templates/%s-%s-template.json"
// PersistentStorage can be used if we want to deploy database with Persistent
PersistentStorage storage = "persistent" // nolint:varcheck

// EphemeralStorage can be used if we don't want to deploy database with Persistent
EphemeralStorage storage = "ephemeral"
// TemplateVersionOCP3_11 stores version of db template 3.11
TemplateVersionOCP3_11 DBTemplate = "release-3.11"
// TemplateVersionOCP4_4 stores version of db template 4.4
TemplateVersionOCP4_4 DBTemplate = "release-4.4"
// TemplateVersionOCP4_5 stored version of db template 4.5
TemplateVersionOCP4_5 DBTemplate = "release-4.5"
)

type storage string

// DBTemplate is type of openshift db template version
type DBTemplate string

// appendRandString, appends a random string to the passed string value
func appendRandString(name string) string {
return fmt.Sprintf("%s-%s", name, rand.String(5))
Expand All @@ -39,8 +48,8 @@ func appendRandString(name string) string {
// getOpenShiftDBTemplate accepts the application name and returns the
// db template for that application
// https://github.com/openshift/origin/tree/master/examples/db-templates
func getOpenShiftDBTemplate(appName string, storageType storage) string {
return fmt.Sprintf(dbTemplateURI, appName, storageType)
func getOpenShiftDBTemplate(appName string, templateVersion DBTemplate, storageType storage) string {
return fmt.Sprintf(dbTemplateURI, templateVersion, appName, storageType)
}

// getLabelOfApp returns label of the passed application this label can be
Expand Down
99 changes: 96 additions & 3 deletions pkg/testing/integration_register.go
Expand Up @@ -188,6 +188,7 @@ var _ = Suite(&RDSPostgreSQLSnap{
},
})

// OpenShift apps for version 3.11
// Mysql Instance that is deployed through DeploymentConfig on OpenShift cluster
type MysqlDBDepConfig struct {
IntegrationSuite
Expand All @@ -197,7 +198,7 @@ var _ = Suite(&MysqlDBDepConfig{
IntegrationSuite{
name: "mysqldc",
namespace: "mysqldc-test",
app: app.NewMysqlDepConfig("mysqldeploymentconfig", app.EphemeralStorage),
app: app.NewMysqlDepConfig("mysqldeploymentconfig", app.TemplateVersionOCP3_11, app.EphemeralStorage),
bp: app.NewBlueprint("mysql-dep-config", ""),
profile: newSecretProfile(),
},
Expand All @@ -212,7 +213,7 @@ var _ = Suite(&MongoDBDepConfig{
IntegrationSuite{
name: "mongodb",
namespace: "mongodb-test",
app: app.NewMongoDBDepConfig("mongodeploymentconfig", app.EphemeralStorage),
app: app.NewMongoDBDepConfig("mongodeploymentconfig", app.TemplateVersionOCP3_11, app.EphemeralStorage),
bp: app.NewBlueprint("mongo-dep-config", ""),
profile: newSecretProfile(),
},
Expand All @@ -227,7 +228,99 @@ var _ = Suite(&PostgreSQLDepConfig{
IntegrationSuite{
name: "postgresdepconf",
namespace: "postgresdepconf-test",
app: app.NewPostgreSQLDepConfig("postgresdepconf", app.EphemeralStorage),
app: app.NewPostgreSQLDepConfig("postgresdepconf", app.TemplateVersionOCP3_11, app.EphemeralStorage),
bp: app.NewBlueprint("postgres-dep-config", ""),
profile: newSecretProfile(),
},
})

// OpenShift apps for version 4.4
// Mysql Instance that is deployed through DeploymentConfig on OpenShift cluster
type MysqlDBDepConfig4_4 struct {
IntegrationSuite
}

var _ = Suite(&MysqlDBDepConfig4_4{
IntegrationSuite{
name: "mysqldc",
namespace: "mysqldc4-4-test",
app: app.NewMysqlDepConfig("mysqldeploymentconfig", app.TemplateVersionOCP4_4, app.EphemeralStorage),
bp: app.NewBlueprint("mysql-dep-config", ""),
profile: newSecretProfile(),
},
})

// MongoDB deployed on openshift cluster
type MongoDBDepConfig4_4 struct {
IntegrationSuite
}

var _ = Suite(&MongoDBDepConfig4_4{
IntegrationSuite{
name: "mongodb",
namespace: "mongodb4-4-test",
app: app.NewMongoDBDepConfig("mongodeploymentconfig", app.TemplateVersionOCP4_4, app.EphemeralStorage),
bp: app.NewBlueprint("mongo-dep-config", ""),
profile: newSecretProfile(),
},
})

// PostgreSQL deployed on openshift cluster
type PostgreSQLDepConfig4_4 struct {
IntegrationSuite
}

var _ = Suite(&PostgreSQLDepConfig4_4{
IntegrationSuite{
name: "postgresdepconf",
namespace: "postgresdepconf4-4-test",
app: app.NewPostgreSQLDepConfig("postgresdepconf", app.TemplateVersionOCP4_4, app.EphemeralStorage),
bp: app.NewBlueprint("postgres-dep-config", ""),
profile: newSecretProfile(),
},
})

// OpenShift apps for version 4.5
// Mysql Instance that is deployed through DeploymentConfig on OpenShift cluster
type MysqlDBDepConfig4_5 struct {
IntegrationSuite
}

var _ = Suite(&MysqlDBDepConfig4_5{
IntegrationSuite{
name: "mysqldc",
namespace: "mysqldc4-5-test",
app: app.NewMysqlDepConfig("mysqldeploymentconfig", app.TemplateVersionOCP4_5, app.EphemeralStorage),
bp: app.NewBlueprint("mysql-dep-config", ""),
profile: newSecretProfile(),
},
})

// MongoDB deployed on openshift cluster
type MongoDBDepConfig4_5 struct {
IntegrationSuite
}

var _ = Suite(&MongoDBDepConfig4_5{
IntegrationSuite{
name: "mongodb",
namespace: "mongodb4-5-test",
app: app.NewMongoDBDepConfig("mongodeploymentconfig", app.TemplateVersionOCP4_5, app.EphemeralStorage),
bp: app.NewBlueprint("mongo-dep-config", ""),
profile: newSecretProfile(),
},
})

// PostgreSQL deployed on openshift cluster
type PostgreSQLDepConfig4_5 struct {
IntegrationSuite
}

var _ = Suite(&PostgreSQLDepConfig4_5{
IntegrationSuite{
name: "postgresdepconf",
namespace: "postgresdepconf4-5-test",
app: app.NewPostgreSQLDepConfig("postgresdepconf", app.TemplateVersionOCP4_5, app.EphemeralStorage),
bp: app.NewBlueprint("postgres-dep-config", ""),
profile: newSecretProfile(),
},
Expand Down
5 changes: 5 additions & 0 deletions pkg/testing/integration_test.go
Expand Up @@ -425,6 +425,11 @@ func (s *IntegrationSuite) TearDownSuite(c *C) {
err := s.app.Uninstall(ctx)
c.Assert(err, IsNil)
}

// Uninstall implementation of the apps doesn't delete namespace
// Delete the namespace separately
err := s.cli.CoreV1().Namespaces().Delete(ctx, s.namespace, metav1.DeleteOptions{})
c.Assert(err, IsNil)
}

func pingAppAndWait(ctx context.Context, a app.DatabaseApp) error {
Expand Down

0 comments on commit 33fb9f7

Please sign in to comment.