mirror of
https://github.com/redhat-developer/odo.git
synced 2025-10-19 03:06:19 +03:00
Use Redis operator to test odo service create with parameters (#5142)
* Do not install PG operator * Rewrite tests with Redis operator
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
install_postgres_operator(){
|
||||
oc create -f - <<EOF
|
||||
apiVersion: operators.coreos.com/v1
|
||||
kind: OperatorGroup
|
||||
metadata:
|
||||
generateName: ${1}-
|
||||
namespace: ${1}
|
||||
spec:
|
||||
targetNamespaces:
|
||||
- ${1}
|
||||
EOF
|
||||
|
||||
oc create -f - <<EOF
|
||||
apiVersion: operators.coreos.com/v1alpha1
|
||||
kind: Subscription
|
||||
metadata:
|
||||
name: postgresql-operator-dev4devs-com
|
||||
namespace: ${1}
|
||||
spec:
|
||||
channel: alpha
|
||||
name: postgresql-operator-dev4devs-com
|
||||
source: community-operators
|
||||
sourceNamespace: openshift-marketplace
|
||||
installPlanApproval: "Automatic"
|
||||
EOF
|
||||
}
|
||||
@@ -5,27 +5,20 @@ set -x
|
||||
LIBDIR="./scripts/configure-cluster"
|
||||
LIBCOMMON="$LIBDIR/common"
|
||||
SETUP_OPERATORS="$LIBCOMMON/setup-operators.sh"
|
||||
SETUP_POSTGRES_OPERATOR="$LIBCOMMON/setup-postgres-operator.sh"
|
||||
AUTH_SCRIPT="$LIBCOMMON/auth.sh"
|
||||
KUBEADMIN_SCRIPT="$LIBCOMMON/kubeconfigandadmin.sh"
|
||||
POSTGRES_OPERATOR_PROJECT="odo-operator-test"
|
||||
|
||||
# list of namespace to create
|
||||
IMAGE_TEST_NAMESPACES="openjdk-11-rhel8 nodejs-12-rhel7 nodejs-12 openjdk-11 nodejs-14"
|
||||
|
||||
. $KUBEADMIN_SCRIPT
|
||||
|
||||
. $SETUP_POSTGRES_OPERATOR
|
||||
|
||||
# Setup the cluster for Operator tests
|
||||
sh $SETUP_OPERATORS
|
||||
|
||||
oc new-project $POSTGRES_OPERATOR_PROJECT
|
||||
# Let developer user have access to the project
|
||||
oc adm policy add-role-to-user edit developer
|
||||
|
||||
install_postgres_operator $POSTGRES_OPERATOR_PROJECT
|
||||
|
||||
# OperatorHub setup complete
|
||||
|
||||
# Create the namespace for e2e image test apply pull secret to the namespace
|
||||
|
||||
@@ -22,7 +22,6 @@ export ARTIFACTS_DIR="`pwd`/artifacts"
|
||||
export CUSTOM_HOMEDIR=$ARTIFACT_DIR
|
||||
LIBDIR="./scripts/configure-cluster"
|
||||
LIBCOMMON="$LIBDIR/common"
|
||||
SETUP_POSTGRES_OPERATOR="$LIBCOMMON/setup-postgres-operator.sh"
|
||||
|
||||
# This si one of the variables injected by ci-firewall. Its purpose is to allow scripts to handle uniqueness as needed
|
||||
SCRIPT_IDENTITY=${SCRIPT_IDENTITY:-"def-id"}
|
||||
@@ -92,7 +91,6 @@ export REDHAT_OPENJDK11_UBI8_PROJECT="${SCRIPT_IDENTITY}$(cat /dev/urandom | tr
|
||||
export REDHAT_NODEJS12_RHEL7_PROJECT="${SCRIPT_IDENTITY}$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 4 | head -n 1)"
|
||||
export REDHAT_NODEJS12_UBI8_PROJECT="${SCRIPT_IDENTITY}$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 4 | head -n 1)"
|
||||
export REDHAT_NODEJS14_UBI8_PROJECT="${SCRIPT_IDENTITY}$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 4 | head -n 1)"
|
||||
export REDHAT_POSTGRES_OPERATOR_PROJECT="${SCRIPT_IDENTITY}$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 4 | head -n 1)"
|
||||
|
||||
# Create the namespace for e2e image test apply pull secret to the namespace
|
||||
for i in `echo "$REDHAT_OPENJDK11_RHEL8_PROJECT $REDHAT_NODEJS12_RHEL7_PROJECT $REDHAT_NODEJS12_UBI8_PROJECT $REDHAT_OPENJDK11_UBI8_PROJECT $REDHAT_NODEJS14_UBI8_PROJECT $REDHAT_POSTGRES_OPERATOR_PROJECT"`; do
|
||||
@@ -104,15 +102,6 @@ for i in `echo "$REDHAT_OPENJDK11_RHEL8_PROJECT $REDHAT_NODEJS12_RHEL7_PROJECT $
|
||||
oc adm policy add-role-to-user edit developer
|
||||
done
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
|
||||
# Install namespace specific operators
|
||||
|
||||
. $SETUP_POSTGRES_OPERATOR
|
||||
|
||||
install_postgres_operator $REDHAT_POSTGRES_OPERATOR_PROJECT
|
||||
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
|
||||
shout "Logging into 4x cluster as developer (logs hidden)"
|
||||
|
||||
@@ -46,83 +46,6 @@ var _ = Describe("odo service command tests for OperatorHub", func() {
|
||||
Expect(stdOut).To(ContainSubstring("service can be created/deleted from a valid component directory only"))
|
||||
})
|
||||
|
||||
Context("a namespace specific operator is installed", func() {
|
||||
|
||||
var postgresOperator string
|
||||
var postgresDatabase string
|
||||
var projectName string
|
||||
|
||||
BeforeEach(func() {
|
||||
if os.Getenv("KUBERNETES") == "true" {
|
||||
Skip("This is a OpenShift specific scenario, skipping")
|
||||
}
|
||||
projectName = util.GetEnvWithDefault("REDHAT_POSTGRES_OPERATOR_PROJECT", "odo-operator-test")
|
||||
helper.GetCliRunner().SetProject(projectName)
|
||||
operators := helper.Cmd("odo", "catalog", "list", "services").ShouldPass().Out()
|
||||
postgresOperator = regexp.MustCompile(`postgresql-operator\.*[a-z][0-9]\.[0-9]\.[0-9]`).FindString(operators)
|
||||
postgresDatabase = fmt.Sprintf("%s/Database", postgresOperator)
|
||||
})
|
||||
|
||||
When("a nodejs component is created", func() {
|
||||
|
||||
BeforeEach(func() {
|
||||
helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context)
|
||||
// change the app name to avoid conflicts
|
||||
appName := helper.RandString(5)
|
||||
helper.Cmd("odo", "create", "nodejs", "--app", appName, "--context", commonVar.Context, "--devfile", helper.GetExamplePath("source", "devfiles", "nodejs", "devfile-registry.yaml")).ShouldPass().Out()
|
||||
helper.Cmd("odo", "config", "set", "Memory", "300M", "-f", "--context", commonVar.Context).ShouldPass()
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
// we do this because for these specific tests we dont delete the project
|
||||
helper.Cmd("odo", "delete", "--all", "-f", "--context", commonVar.Context).ShouldPass().Out()
|
||||
})
|
||||
|
||||
It("should try to create a service in dry run mode with some provided params", func() {
|
||||
serviceName := helper.RandString(10)
|
||||
output := helper.Cmd("odo", "service", "create", postgresDatabase, serviceName, "-p",
|
||||
"databaseName=odo", "-p", "size=1", "-p", "databaseUser=odo", "-p",
|
||||
"databaseStorageRequest=1Gi", "-p", "databasePassword=odopasswd", "--dry-run", "--context", commonVar.Context).ShouldPass().Out()
|
||||
helper.MatchAllInOutput(output, []string{fmt.Sprintf("name: %s", serviceName), "odo", "odopasswd", "1Gi"})
|
||||
})
|
||||
|
||||
When("creating a postgres operand with params", func() {
|
||||
var operandName string
|
||||
|
||||
BeforeEach(func() {
|
||||
operandName = helper.RandString(10)
|
||||
helper.Cmd("odo", "service", "create", postgresDatabase, operandName, "-p",
|
||||
"databaseName=odo", "-p", "size=1", "-p", "databaseUser=odo", "-p",
|
||||
"databaseStorageRequest=1Gi", "-p", "databasePassword=odopasswd", "--context", commonVar.Context).ShouldPass().Out()
|
||||
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
helper.Cmd("odo", "service", "delete", fmt.Sprintf("Database/%s", operandName), "-f", "--context", commonVar.Context).ShouldPass().Out()
|
||||
helper.Cmd("odo", "push", "--context", commonVar.Context).ShouldPass().Out()
|
||||
})
|
||||
|
||||
When("odo push is executed", func() {
|
||||
BeforeEach(func() {
|
||||
helper.Cmd("odo", "push", "--context", commonVar.Context).ShouldPass().Out()
|
||||
})
|
||||
|
||||
It("should create pods in running state and list the service", func() {
|
||||
commonVar.CliRunner.PodsShouldBeRunning(projectName, fmt.Sprintf(`%s-.[\-a-z0-9]*`, operandName))
|
||||
// TODO(feloy) These 2 tests cannot run in parallel on the same namespace. Rollback when using a multi-namespace operator
|
||||
// })
|
||||
//
|
||||
// It("should list the service", func() {
|
||||
stdOut := helper.Cmd("odo", "service", "list", "--context", commonVar.Context).ShouldPass().Out()
|
||||
Expect(stdOut).To(ContainSubstring(fmt.Sprintf("Database/%s", operandName)))
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
Context("a specific operator is installed", func() {
|
||||
var redisOperator string
|
||||
var redisCluster string
|
||||
@@ -209,6 +132,55 @@ var _ = Describe("odo service command tests for OperatorHub", func() {
|
||||
"-p", "securityContext.runAsUser=1000").ShouldPass()
|
||||
})
|
||||
|
||||
It("should try to create a service in dry run mode with some provided params", func() {
|
||||
serviceName := helper.RandString(10)
|
||||
output := helper.Cmd("odo", "service", "create", fmt.Sprintf("%s/Redis", redisOperator), serviceName,
|
||||
"-p", "kubernetesConfig.image=quay.io/opstree/redis:v6.2.5",
|
||||
"-p", "redisExporter.image=quay.io/opstree/redis-exporter:1.0",
|
||||
"-p", "kubernetesConfig.serviceType=ClusterIP",
|
||||
"-p", "kubernetesConfig.resources.requests.cpu=100m",
|
||||
"-p", "kubernetesConfig.resources.requests.memory=128Mi",
|
||||
"--dry-run", "--context", commonVar.Context).ShouldPass().Out()
|
||||
helper.MatchAllInOutput(output, []string{fmt.Sprintf("name: %s", serviceName), "quay.io/opstree/redis:v6.2.5", "ClusterIP", "100m", "128Mi"})
|
||||
})
|
||||
|
||||
When("creating a postgres operand with params", func() {
|
||||
var operandName string
|
||||
|
||||
BeforeEach(func() {
|
||||
operandName = helper.RandString(10)
|
||||
helper.Cmd("odo", "service", "create", fmt.Sprintf("%s/Redis", redisOperator), operandName,
|
||||
"-p", "kubernetesConfig.image=quay.io/opstree/redis:v6.2.5",
|
||||
"-p", "redisExporter.image=quay.io/opstree/redis-exporter:1.0",
|
||||
"-p", "kubernetesConfig.serviceType=ClusterIP",
|
||||
"-p", "kubernetesConfig.resources.requests.cpu=100m",
|
||||
"-p", "kubernetesConfig.resources.requests.memory=128Mi",
|
||||
"--context", commonVar.Context).ShouldPass().Out()
|
||||
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
helper.Cmd("odo", "service", "delete", fmt.Sprintf("Redis/%s", operandName), "-f", "--context", commonVar.Context).ShouldPass().Out()
|
||||
helper.Cmd("odo", "push", "--context", commonVar.Context).ShouldPass().Out()
|
||||
})
|
||||
|
||||
When("odo push is executed", func() {
|
||||
BeforeEach(func() {
|
||||
helper.Cmd("odo", "push", "--context", commonVar.Context).ShouldPass().Out()
|
||||
})
|
||||
|
||||
It("should create pods in running state", func() {
|
||||
commonVar.CliRunner.PodsShouldBeRunning(commonVar.Project, fmt.Sprintf(`%s-0`, operandName))
|
||||
})
|
||||
|
||||
It("should list the service", func() {
|
||||
stdOut := helper.Cmd("odo", "service", "list", "--context", commonVar.Context).ShouldPass().Out()
|
||||
Expect(stdOut).To(ContainSubstring(fmt.Sprintf("Redis/%s", operandName)))
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
When("odo push is executed", func() {
|
||||
BeforeEach(func() {
|
||||
helper.Cmd("odo", "push").ShouldPass()
|
||||
|
||||
Reference in New Issue
Block a user