Skip to content

Commit

Permalink
Merge pull request #23365 from jianzhangbjz/olm-23440
Browse files Browse the repository at this point in the history
auto olm test case OCP-23440: the end user can use operator resources
  • Loading branch information
openshift-merge-robot committed Jan 6, 2020
2 parents bc855fb + f75af91 commit b600fb9
Show file tree
Hide file tree
Showing 6 changed files with 241 additions and 4 deletions.
2 changes: 1 addition & 1 deletion hack/test-go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ os::cleanup::tmpdir

# Internalize environment variables we consume and default if they're not set
dry_run="${DRY_RUN:-}"
test_timeout="${TIMEOUT:-120s}"
test_timeout="${TIMEOUT:-240s}"
detect_races="${DETECT_RACES:-true}"
coverage_output_dir="${COVERAGE_OUTPUT_DIR:-}"
coverage_spec="${COVERAGE_SPEC:--cover -covermode atomic}"
Expand Down
69 changes: 66 additions & 3 deletions test/extended/operators/olm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package operators

import (
"fmt"
"strings"

g "github.com/onsi/ginkgo"
o "github.com/onsi/gomega"

exutil "github.com/openshift/origin/test/extended/util"
"k8s.io/apimachinery/pkg/util/wait"
e2e "k8s.io/kubernetes/test/e2e/framework"
"path/filepath"
"strings"
"time"
)

var _ = g.Describe("[Feature:Platform] OLM should", func() {
Expand Down Expand Up @@ -106,3 +107,65 @@ var _ = g.Describe("[Feature:Platform] OLM should", func() {
})

})

// This context will cover test case: OCP-23440, author: jiazha@redhat.com
var _ = g.Describe("[Feature:Platform] an end user use OLM", func() {
defer g.GinkgoRecover()

var (
oc = exutil.NewCLI("olm-23440", exutil.KubeConfigPath())
operatorWait = 120 * time.Second

buildPruningBaseDir = exutil.FixturePath("testdata", "olm")
operatorGroup = filepath.Join(buildPruningBaseDir, "operatorgroup.yaml")
etcdSub = filepath.Join(buildPruningBaseDir, "etcd-subscription.yaml")
etcdCluster = filepath.Join(buildPruningBaseDir, "etcd-cluster.yaml")
)

files := []string{operatorGroup, etcdSub}
g.It("can subscribe to the etcd operator", func() {
g.By("Cluster-admin user subscribe the operator resource")
for _, v := range files {
configFile, err := oc.AsAdmin().Run("process").Args("--ignore-unknown-parameters=true", "-f", v, "-p", "NAME=test-operator", fmt.Sprintf("NAMESPACE=%s", oc.Namespace()), "SOURCENAME=community-operators", "SOURCENAMESPACE=openshift-marketplace").OutputToFile("config.json")
o.Expect(err).NotTo(o.HaveOccurred())
err = oc.AsAdmin().WithoutNamespace().Run("create").Args("-f", configFile).Execute()
o.Expect(err).NotTo(o.HaveOccurred())

}
err := wait.Poll(10*time.Second, operatorWait, func() (bool, error) {
output, err := oc.AsAdmin().Run("get").Args("-n", oc.Namespace(), "csv", "etcdoperator.v0.9.4", "-o=jsonpath={.status.phase}").Output()
if err != nil {
e2e.Failf("Failed to deploy etcdoperator.v0.9.4, error:%v", err)
return false, err
}
if strings.Contains(output, "Succeeded") {
return true, nil
}
return false, nil
})
o.Expect(err).NotTo(o.HaveOccurred())

g.By("Switch to common user to create the resources provided by the operator")
etcdClusterName := "example-etcd-cluster"
configFile, err := oc.Run("process").Args("-f", etcdCluster, "-p", fmt.Sprintf("NAME=%s", etcdClusterName), fmt.Sprintf("NAMESPACE=%s", oc.Namespace())).OutputToFile("config.json")
o.Expect(err).NotTo(o.HaveOccurred())
err = oc.Run("create").Args("-f", configFile).Execute()
o.Expect(err).NotTo(o.HaveOccurred())

err = wait.Poll(10*time.Second, operatorWait, func() (bool, error) {
output, err := oc.Run("get").Args("-n", oc.Namespace(), "etcdCluster", etcdClusterName, "-o=jsonpath={.status}").Output()
if err != nil {
e2e.Failf("Failed to get etcdCluster, error:%v", err)
return false, err
}
if strings.Contains(output, "phase:Running") && strings.Contains(output, "currentVersion:3.2.13") && strings.Contains(output, "size:3") {
return true, nil
}
return false, nil
})
o.Expect(err).NotTo(o.HaveOccurred())
output, err := oc.Run("get").Args("pods", "-n", oc.Namespace()).Output()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(output).To(o.ContainSubstring(etcdClusterName))
})
})
118 changes: 118 additions & 0 deletions test/extended/testdata/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions test/extended/testdata/olm/etcd-cluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: Template
metadata:
name: etcdCluster-template
objects:
- apiVersion: etcd.database.coreos.com/v1beta2
kind: EtcdCluster
metadata:
name: "${NAME}"
namespace: "${NAMESPACE}"
spec:
size: 3
version: 3.2.13
parameters:
- name: NAME
- name: NAMESPACE
22 changes: 22 additions & 0 deletions test/extended/testdata/olm/etcd-subscription.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: v1
kind: Template
metadata:
name: subscription-template
objects:
- apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
name: "${NAME}"
namespace: "${NAMESPACE}"
spec:
channel: singlenamespace-alpha
installPlanApproval: Automatic
name: etcd
source: "${SOURCENAME}"
sourceNamespace: "${SOURCENAMESPACE}"
startingCSV: etcdoperator.v0.9.4
parameters:
- name: NAME
- name: NAMESPACE
- name: SOURCENAME
- name: SOURCENAMESPACE
18 changes: 18 additions & 0 deletions test/extended/testdata/olm/operatorgroup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: v1
kind: Template
metadata:
name: operatorgroup-template
objects:
- kind: OperatorGroup
apiVersion: operators.coreos.com/v1
metadata:
name: "${NAME}"
namespace: "${NAMESPACE}"
spec:
targetNamespaces:
- "${NAMESPACE}"

parameters:
- name: NAME
- name: NAMESPACE

0 comments on commit b600fb9

Please sign in to comment.