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

Use oc in integration tests #5

Merged
merged 2 commits into from
Dec 7, 2020
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
19 changes: 15 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ else
GOBIN=$(shell go env GOBIN)
endif

# Check if oc or kubectl are installed and determine which of the two to use
ifeq (,$(shell which kubectl))
ifeq (,$(shell which oc))
$(error oc or kubectl is required to proceed)
else
K8S_CLI := oc
endif
else
K8S_CLI := kubectl
endif

all: manager

# Run tests
Expand All @@ -48,17 +59,17 @@ run: generate fmt vet manifests

# Install CRDs into a cluster
install: manifests kustomize
$(KUSTOMIZE) build config/crd | kubectl apply -f -
$(KUSTOMIZE) build config/crd | $(K8S_CLI) apply -f -

# Uninstall operator and CRDs from a cluster
uninstall: manifests kustomize
$(KUSTOMIZE) build config/default | kubectl delete -f -
#$(KUSTOMIZE) build config/crd | kubectl delete -f -
$(KUSTOMIZE) build config/default | $(K8S_CLI) delete -f -
#$(KUSTOMIZE) build config/crd | $(K8S_CLI) delete -f -

# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: manifests kustomize
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default | kubectl apply -f -
$(KUSTOMIZE) build config/default | $(K8S_CLI) apply -f -

# Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import (
"github.com/devfile/registry-operator/tests/integration/pkg/config"
)

// KubectlApplyResource applies resources on the cluster, corresponding to the specified file(s)
func (w *K8sClient) KubectlApplyResource(filePath string) (err error) {
cmd := exec.Command("kubectl", "apply", "--namespace", config.Namespace, "-f", filePath)
// OcApplyResource applies resources on the cluster, corresponding to the specified file(s)
func (w *K8sClient) OcApplyResource(filePath string) (err error) {
cmd := exec.Command("oc", "apply", "--namespace", config.Namespace, "-f", filePath)
outBytes, err := cmd.CombinedOutput()
output := string(outBytes)
if err != nil && !strings.Contains(output, "AlreadyExists") {
Expand All @@ -31,9 +31,9 @@ func (w *K8sClient) KubectlApplyResource(filePath string) (err error) {
return err
}

// KubectlDeleteResource deletes the resources from the cluster that the specified file(s) correspond to
func (w *K8sClient) KubectlDeleteResource(filePath string) (err error) {
cmd := exec.Command("kubectl", "delete", "--namespace", config.Namespace, "-f", filePath)
// OcDeleteResource deletes the resources from the cluster that the specified file(s) correspond to
func (w *K8sClient) OcDeleteResource(filePath string) (err error) {
cmd := exec.Command("oc", "delete", "--namespace", config.Namespace, "-f", filePath)
outBytes, err := cmd.CombinedOutput()
output := string(outBytes)
if err != nil && !strings.Contains(output, "AlreadyExists") {
Expand Down
14 changes: 7 additions & 7 deletions tests/integration/pkg/tests/devfileregistry_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var _ = ginkgo.Describe("[Create Devfile Registry resource]", func() {
label := "devfileregistry_cr=" + crName

// Deploy the devfileregistry resource for this test case and wait for the pod to be running
err := K8sClient.KubectlApplyResource("tests/integration/examples/create/devfileregistry.yaml")
err := K8sClient.OcApplyResource("tests/integration/examples/create/devfileregistry.yaml")
if err != nil {
ginkgo.Fail("Failed to create devfileregistry instance: " + err.Error())
return
Expand All @@ -55,7 +55,7 @@ var _ = ginkgo.Describe("[Create Devfile Registry resource]", func() {
})

var _ = ginkgo.AfterEach(func() {
K8sClient.KubectlDeleteResource("tests/integration/examples/create/devfileregistry.yaml")
K8sClient.OcDeleteResource("tests/integration/examples/create/devfileregistry.yaml")
})
})

Expand All @@ -65,7 +65,7 @@ var _ = ginkgo.Describe("[Create Devfile Registry resource with TLS enabled]", f
label := "devfileregistry_cr=" + crName

// Deploy the devfileregistry resource for this test case and wait for the pod to be running
err := K8sClient.KubectlApplyResource("tests/integration/examples/create/devfileregistry-tls.yaml")
err := K8sClient.OcApplyResource("tests/integration/examples/create/devfileregistry-tls.yaml")
if err != nil {
ginkgo.Fail("Failed to create devfileregistry instance: " + err.Error())
return
Expand All @@ -91,7 +91,7 @@ var _ = ginkgo.Describe("[Create Devfile Registry resource with TLS enabled]", f
})

var _ = ginkgo.AfterEach(func() {
K8sClient.KubectlDeleteResource("tests/integration/examples/create/devfileregistry-tls.yaml")
K8sClient.OcDeleteResource("tests/integration/examples/create/devfileregistry-tls.yaml")
})
})

Expand All @@ -101,7 +101,7 @@ var _ = ginkgo.Describe("[Update Devfile Registry resource]", func() {
label := "devfileregistry_cr=" + crName

// Deploy the devfileregistry resource for this test case and wait for the pod to be running
err := K8sClient.KubectlApplyResource("tests/integration/examples/update/devfileregistry-old.yaml")
err := K8sClient.OcApplyResource("tests/integration/examples/update/devfileregistry-old.yaml")
if err != nil {
ginkgo.Fail("Failed to create devfileregistry instance: " + err.Error())
return
Expand All @@ -123,7 +123,7 @@ var _ = ginkgo.Describe("[Update Devfile Registry resource]", func() {
gomega.Expect(err).NotTo(gomega.HaveOccurred())

// Update the devfileregistry resource for this test case
err = K8sClient.KubectlApplyResource("tests/integration/examples/update/devfileregistry-new.yaml")
err = K8sClient.OcApplyResource("tests/integration/examples/update/devfileregistry-new.yaml")
if err != nil {
ginkgo.Fail("Failed to create devfileregistry instance: " + err.Error())
return
Expand All @@ -140,6 +140,6 @@ var _ = ginkgo.Describe("[Update Devfile Registry resource]", func() {
})

var _ = ginkgo.AfterEach(func() {
K8sClient.KubectlDeleteResource("tests/integration/examples/update/devfileregistry-new.yaml")
K8sClient.OcDeleteResource("tests/integration/examples/update/devfileregistry-new.yaml")
})
})