Skip to content
Open
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
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ else
endif

# Default image repo
QUAY_REGISTRY ?= quay.io/opencloudio
QUAY_REGISTRY ?= quay.io/luzarragaben
ICR_REIGSTRY ?= icr.io/cpopen

ifeq ($(BUILD_LOCALLY),0)
Expand Down Expand Up @@ -268,8 +268,8 @@ build-operator-image: $(CONFIG_DOCKER_TARGET) ## Build the operator image.
--build-arg GOARCH=$(LOCAL_ARCH) -f Dockerfile .

build-operator-dev-image: ## Build the operator dev image.
@echo "Building the $(DEV_REGISTRY)/$(OPERATOR_IMAGE_NAME) docker image..."
@docker build -t $(DEV_REGISTRY)/$(OPERATOR_IMAGE_NAME):$(VERSION) \
@echo "Building the $(QUAY_REGISTRY)/$(OPERATOR_IMAGE_NAME) docker image..."
@docker build -t $(QUAY_REGISTRY)/$(OPERATOR_IMAGE_NAME):$(VERSION) \
--build-arg VCS_REF=$(VCS_REF) --build-arg RELEASE_VERSION=$(RELEASE_VERSION) \
--build-arg GOARCH=$(LOCAL_ARCH) -f Dockerfile .

Expand Down
173 changes: 173 additions & 0 deletions controllers/operandconfignoolm/operandconfig_controller_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
//
// Copyright 2022 IBM Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

package operandconfignoolm

import (
"context"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
olmv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
"k8s.io/apimachinery/pkg/types"

operatorv1alpha1 "github.com/IBM/operand-deployment-lifecycle-manager/v4/api/v1alpha1"
testutil "github.com/IBM/operand-deployment-lifecycle-manager/v4/controllers/testutil"
)

// +kubebuilder:docs-gen:collapse=Imports

var _ = Describe("OperandConfig controller", func() {
const (
name = "common-service"
namespace = "ibm-common-services"
requestName = "ibm-cloudpak-name"
requestNamespace = "ibm-cloudpak"
operatorNamespace = "ibm-operators"
)

var (
ctx context.Context

namespaceName string
operatorNamespaceName string
requestNamespaceName string

registry *operatorv1alpha1.OperandRegistry
config *operatorv1alpha1.OperandConfig
request *operatorv1alpha1.OperandRequest
catalogSource *olmv1alpha1.CatalogSource
configKey types.NamespacedName
)

BeforeEach(func() {
ctx = context.Background()
namespaceName = testutil.CreateNSName(namespace)
operatorNamespaceName = testutil.CreateNSName(operatorNamespace)
requestNamespaceName = testutil.CreateNSName(requestNamespace)
registry = testutil.OperandRegistryObj(name, namespaceName, operatorNamespaceName)
config = testutil.OperandConfigObj(name, namespaceName)
request = testutil.OperandRequestObj(name, namespaceName, requestName, requestNamespaceName)
catalogSource = testutil.CatalogSource("community-operators", "openshift-marketplace")
configKey = types.NamespacedName{Name: name, Namespace: namespaceName}

By("Creating the Namespace")
Expect(k8sClient.Create(ctx, testutil.NamespaceObj(namespaceName))).Should(Succeed())
Expect(k8sClient.Create(ctx, testutil.NamespaceObj(operatorNamespaceName))).Should(Succeed())
Expect(k8sClient.Create(ctx, testutil.NamespaceObj(requestNamespaceName))).Should(Succeed())
Expect(k8sClient.Create(ctx, testutil.NamespaceObj("openshift-marketplace")))

By("Creating the CatalogSource")
Expect(k8sClient.Create(ctx, catalogSource)).Should(Succeed())
catalogSource.Status = testutil.CatalogSourceStatus()
Expect(k8sClient.Status().Update(ctx, catalogSource)).Should(Succeed())
By("Creating the OperandRegistry")
Expect(k8sClient.Create(ctx, registry)).Should(Succeed())
By("Creating the OperandConfig")
Expect(k8sClient.Create(ctx, config)).Should(Succeed())
})

AfterEach(func() {
By("Deleting the CatalogSource")
Expect(k8sClient.Delete(ctx, catalogSource)).Should(Succeed())
By("Deleting the OperandRequest")
Expect(k8sClient.Delete(ctx, request)).Should(Succeed())
By("Deleting the OperandConfig")
Expect(k8sClient.Delete(ctx, config)).Should(Succeed())
By("Deleting the OperandRegistry")
Expect(k8sClient.Delete(ctx, registry)).Should(Succeed())
})

Context("Initializing OperandConfig Status", func() {
It("Should the status of OperandConfig be Running", func() {

By("Checking status of the OperandConfig")
Eventually(func() operatorv1alpha1.ServicePhase {
configInstance := &operatorv1alpha1.OperandConfig{}
Expect(k8sClient.Get(ctx, configKey, configInstance)).Should(Succeed())

return configInstance.Status.Phase
}, timeout, interval).Should(Equal(operatorv1alpha1.ServiceInit))

By("Creating the OperandRequest")
Expect(k8sClient.Create(ctx, request)).Should(Succeed())

By("Setting status of the Subscriptions")
jaegerSub := testutil.Subscription("jaeger", operatorNamespaceName)
Eventually(func() error {
k8sClient.Get(ctx, types.NamespacedName{Name: "jaeger", Namespace: operatorNamespaceName}, jaegerSub)
jaegerSub.Status = testutil.SubscriptionStatus("jaeger", operatorNamespaceName, "0.0.1")
return k8sClient.Status().Update(ctx, jaegerSub)
}, timeout, interval).Should(Succeed())

mongodbSub := testutil.Subscription("mongodb-atlas-kubernetes", operatorNamespaceName)
Eventually(func() error {
k8sClient.Get(ctx, types.NamespacedName{Name: "mongodb-atlas-kubernetes", Namespace: operatorNamespaceName}, mongodbSub)
mongodbSub.Status = testutil.SubscriptionStatus("mongodb-atlas-kubernetes", operatorNamespaceName, "0.0.1")
return k8sClient.Status().Update(ctx, mongodbSub)
}, timeout, interval).Should(Succeed())

By("Creating and Setting status of the ClusterServiceVersions")
jaegerCSV := testutil.ClusterServiceVersion("jaeger-csv.v0.0.1", "jaeger", operatorNamespaceName, testutil.JaegerExample)
Expect(k8sClient.Create(ctx, jaegerCSV)).Should(Succeed())
Eventually(func() error {
k8sClient.Get(ctx, types.NamespacedName{Name: "jaeger-csv.v0.0.1", Namespace: operatorNamespaceName}, jaegerCSV)
jaegerCSV.Status = testutil.ClusterServiceVersionStatus()
return k8sClient.Status().Update(ctx, jaegerCSV)
}, timeout, interval).Should(Succeed())

mongodbCSV := testutil.ClusterServiceVersion("mongodb-atlas-kubernetes-csv.v0.0.1", "mongodb-atlas-kubernetes", operatorNamespaceName, testutil.MongodbExample)
Expect(k8sClient.Create(ctx, mongodbCSV)).Should(Succeed())
Eventually(func() error {
k8sClient.Get(ctx, types.NamespacedName{Name: "mongodb-atlas-kubernetes-csv.v0.0.1", Namespace: operatorNamespaceName}, mongodbCSV)
mongodbCSV.Status = testutil.ClusterServiceVersionStatus()
return k8sClient.Status().Update(ctx, mongodbCSV)
}, timeout, interval).Should(Succeed())

By("Creating and Setting status of the InstallPlan")
jaegerIP := testutil.InstallPlan("jaeger-install-plan", operatorNamespaceName)
Expect(k8sClient.Create(ctx, jaegerIP)).Should(Succeed())
Eventually(func() error {
k8sClient.Get(ctx, types.NamespacedName{Name: "jaeger-install-plan", Namespace: operatorNamespaceName}, jaegerIP)
jaegerIP.Status = testutil.InstallPlanStatus()
return k8sClient.Status().Update(ctx, jaegerIP)
}, timeout, interval).Should(Succeed())

mongodbIP := testutil.InstallPlan("mongodb-atlas-kubernetes-install-plan", operatorNamespaceName)
Expect(k8sClient.Create(ctx, mongodbIP)).Should(Succeed())
Eventually(func() error {
k8sClient.Get(ctx, types.NamespacedName{Name: "mongodb-atlas-kubernetes-install-plan", Namespace: operatorNamespaceName}, mongodbIP)
mongodbIP.Status = testutil.InstallPlanStatus()
return k8sClient.Status().Update(ctx, mongodbIP)
}, timeout, interval).Should(Succeed())

By("Checking status of the OperandConfig")
Eventually(func() operatorv1alpha1.ServicePhase {
configInstance := &operatorv1alpha1.OperandConfig{}
Expect(k8sClient.Get(ctx, configKey, configInstance)).Should(Succeed())
return configInstance.Status.Phase
}, timeout, interval).Should(Equal(operatorv1alpha1.ServiceRunning))

By("Cleaning up olm resources")
Expect(k8sClient.Delete(ctx, jaegerSub)).Should(Succeed())
Expect(k8sClient.Delete(ctx, mongodbSub)).Should(Succeed())
Expect(k8sClient.Delete(ctx, jaegerCSV)).Should(Succeed())
Expect(k8sClient.Delete(ctx, mongodbCSV)).Should(Succeed())
Expect(k8sClient.Delete(ctx, jaegerIP)).Should(Succeed())
Expect(k8sClient.Delete(ctx, mongodbIP)).Should(Succeed())
})
})
})
153 changes: 153 additions & 0 deletions controllers/operandconfignoolm/operandconfig_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
//
// Copyright 2022 IBM Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

package operandconfignoolm

import (
"os"
"path/filepath"
"testing"
"time"

jaegerv1 "github.com/jaegertracing/jaeger-operator/apis/v1"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
olmv1 "github.com/operator-framework/api/pkg/operators/v1"
olmv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
operatorsv1 "github.com/operator-framework/operator-lifecycle-manager/pkg/package-server/apis/operators/v1"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/metrics/server"

nssv1 "github.com/IBM/ibm-namespace-scope-operator/api/v1"

apiv1alpha1 "github.com/IBM/operand-deployment-lifecycle-manager/v4/api/v1alpha1"
"github.com/IBM/operand-deployment-lifecycle-manager/v4/controllers/operandregistry"
"github.com/IBM/operand-deployment-lifecycle-manager/v4/controllers/operandrequest"
deploy "github.com/IBM/operand-deployment-lifecycle-manager/v4/controllers/operator"
// +kubebuilder:scaffold:imports
)

// These tests use Ginkgo (BDD-style Go testing framework). Refer to
// http://onsi.github.io/ginkgo/ to learn more about Ginkgo.

const useExistingCluster = "USE_EXISTING_CLUSTER"

var (
cfg *rest.Config
k8sClient client.Client
testEnv *envtest.Environment
// scheme = runtime.NewScheme()

timeout = time.Second * 900
interval = time.Second * 5
)

func TestOperandConfig(t *testing.T) {
RegisterFailHandler(Fail)

RunSpecs(t,
"OperandConfig Controller Suite")
}

var _ = BeforeSuite(func(ctx SpecContext) {
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))

By("bootstrapping test environment")
testEnv = &envtest.Environment{
UseExistingCluster: UseExistingCluster(),
CRDDirectoryPaths: []string{filepath.Join("../..", "config", "crd", "bases"), filepath.Join("../..", "testcrds")},
}

var err error
cfg, err = testEnv.Start()
Expect(err).ToNot(HaveOccurred())
Expect(cfg).ToNot(BeNil())

err = apiv1alpha1.AddToScheme(clientgoscheme.Scheme)
Expect(err).NotTo(HaveOccurred())
// +kubebuilder:scaffold:scheme

err = nssv1.AddToScheme(clientgoscheme.Scheme)
Expect(err).NotTo(HaveOccurred())
err = olmv1alpha1.AddToScheme(clientgoscheme.Scheme)
Expect(err).NotTo(HaveOccurred())
err = olmv1.AddToScheme(clientgoscheme.Scheme)
Expect(err).NotTo(HaveOccurred())
err = jaegerv1.AddToScheme(clientgoscheme.Scheme)
Expect(err).NotTo(HaveOccurred())
err = operatorsv1.AddToScheme(clientgoscheme.Scheme)
Expect(err).NotTo(HaveOccurred())

k8sClient, err = client.New(cfg, client.Options{Scheme: clientgoscheme.Scheme})
Expect(err).ToNot(HaveOccurred())
Expect(k8sClient).ToNot(BeNil())

// Start your controllers test logic
k8sManager, err := ctrl.NewManager(cfg, ctrl.Options{
Scheme: clientgoscheme.Scheme,
Metrics: server.Options{
BindAddress: "0",
},
})
Expect(err).ToNot(HaveOccurred())

// Setup Manager with OperandRegistry Controller
err = (&operandregistry.Reconciler{
ODLMOperator: deploy.NewODLMOperator(k8sManager, "OperandRegistry"),
}).SetupWithManager(k8sManager)
Expect(err).ToNot(HaveOccurred())
// Setup Manager with OperandConfig Controller
err = (&Reconciler{
ODLMOperator: deploy.NewODLMOperator(k8sManager, "OperandConfig"),
}).SetupWithManager(k8sManager)
Expect(err).ToNot(HaveOccurred())
// Setup Manager with OperandRequest Controller
err = (&operandrequest.Reconciler{
ODLMOperator: deploy.NewODLMOperator(k8sManager, "OperandRequest"),
}).SetupWithManager(k8sManager)
Expect(err).ToNot(HaveOccurred())

go func() {
defer GinkgoRecover()
err = k8sManager.Start(ctrl.SetupSignalHandler())
Expect(err).ToNot(HaveOccurred())
}()

// End your controllers test logic

}, NodeTimeout(timeout))

var _ = AfterSuite(func() {
By("tearing down the test environment")
gexec.KillAndWait(5 * time.Second)
err := testEnv.Stop()
Expect(err).ToNot(HaveOccurred())
})

func UseExistingCluster() *bool {
use := false
if os.Getenv(useExistingCluster) != "" && os.Getenv(useExistingCluster) == "true" {
use = true
}
return &use
}
Loading