Skip to content

Commit

Permalink
operator: add test for multiple-same-operators (#973)
Browse files Browse the repository at this point in the history
* operator: add positive test for multiple-same-operators

* Add negative test
  • Loading branch information
sebrandon1 authored Nov 4, 2024
1 parent 4f15096 commit e03d6c8
Show file tree
Hide file tree
Showing 13 changed files with 286 additions and 6 deletions.
4 changes: 2 additions & 2 deletions tests/affiliatedcertification/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ func GetCsvByPrefix(prefixCsvName string, namespace string) (*v1alpha1.ClusterSe
return &neededCSV, nil
}

func DeployOperatorSubscription(operatorPackage, channel, namespace, group,
func DeployOperatorSubscription(subscriptionName, operatorPackage, channel, namespace, group,
sourceNamespace, startingCSV string, installApproval v1alpha1.Approval) error {
operatorSubscription := utils.DefineSubscription(
operatorPackage+"-subscription",
subscriptionName+"-subscription",
namespace,
channel,
operatorPackage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ var _ = Describe("Affiliated-certification invalid operator certification,", Ser
By(fmt.Sprintf("Deploy nginx-ingress-operator%s for testing", "."+version))
// nginx-ingress-operator: in certified-operators group and version is certified
err = tshelper.DeployOperatorSubscription(
tsparams.CertifiedOperatorPrefixNginx,
tsparams.CertifiedOperatorPrefixNginx,
channel,
randomNamespace,
Expand Down Expand Up @@ -91,6 +92,7 @@ var _ = Describe("Affiliated-certification invalid operator certification,", Ser

By("Deploy sriov-fec operator with uncertified version")
err = tshelper.DeployOperatorSubscription(
tsparams.UncertifiedOperatorPrefixSriov,
tsparams.UncertifiedOperatorPrefixSriov,
"stable",
randomNamespace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var _ = Describe("Affiliated-certification operator certification,", Serial, fun
By("Deploy cockroachdb for testing")
// cockroachdb: not in certified-operators group in catalog, for negative test cases
err := tshelper.DeployOperatorSubscription(
"cockroachdb",
"cockroachdb",
"stable-v6.x",
randomNamespace,
Expand Down Expand Up @@ -67,6 +68,7 @@ var _ = Describe("Affiliated-certification operator certification,", Serial, fun
By(fmt.Sprintf("Deploy cockroachdb-certified operator %s for testing", "v"+version))
// cockroachdb-certified operator: in certified-operators group and version is certified
err = tshelper.DeployOperatorSubscription(
"cockroachdb-certified",
"cockroachdb-certified",
channel,
randomNamespace,
Expand Down Expand Up @@ -99,6 +101,7 @@ var _ = Describe("Affiliated-certification operator certification,", Serial, fun
By(fmt.Sprintf("Deploy nginx-ingress-operator.v%s for testing", version))
// nginx-ingress-operator: in certified-operators group and version is certified
err = tshelper.DeployOperatorSubscription(
tsparams.CertifiedOperatorPrefixNginx,
tsparams.CertifiedOperatorPrefixNginx,
channel,
randomNamespace,
Expand Down
34 changes: 34 additions & 0 deletions tests/globalhelper/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,40 @@ func DeployRHCertifiedOperatorSource(ocpVersion string) error {
return nil
}

func DeleteCustomOperatorSource() error {
return DeleteCatalogSource("custom-catalog", "openshift-marketplace", "Custom Index")
}

func DeployCustomOperatorSource() error {
err := GetAPIClient().Create(context.TODO(),
&v1alpha1.CatalogSource{
ObjectMeta: metav1.ObjectMeta{
Name: "custom-catalog",
Namespace: "openshift-marketplace",
},
Spec: v1alpha1.CatalogSourceSpec{
SourceType: "grpc",
Image: "quay.io/deliedit/test:catalog-index-test",
DisplayName: "Custom Index",
Publisher: "CertsuiteTeam",
UpdateStrategy: &v1alpha1.UpdateStrategy{
RegistryPoll: &v1alpha1.RegistryPoll{
Interval: &metav1.Duration{
Duration: 30 * time.Minute}},
},
},
},
)

if k8serrors.IsAlreadyExists(err) {
return nil
} else if err != nil {
return fmt.Errorf("can not deploy catalog source %w", err)
}

return nil
}

func DisableCatalogSource(name string) error {
return setCatalogSource(true, name)
}
Expand Down
4 changes: 2 additions & 2 deletions tests/operator/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ func GetCsvByPrefix(prefixCsvName string, namespace string) (*v1alpha1.ClusterSe
return &neededCSV, nil
}

func DeployOperatorSubscription(operatorPackage, channel, namespace, group,
func DeployOperatorSubscription(subscriptionName, operatorPackage, channel, namespace, group,
sourceNamespace, startingCSV string, installApproval v1alpha1.Approval) error {
operatorSubscription := utils.DefineSubscription(
operatorPackage+"-subscription",
subscriptionName+"-subscription",
namespace,
channel,
operatorPackage,
Expand Down
1 change: 1 addition & 0 deletions tests/operator/parameters/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,5 @@ const (
CertsuiteOperatorNonRoot = "operator-run-as-non-root"
CertsuiteOperatorPodAutomountToken = "operator-automount-tokens"
CertsuiteOperatorPodRunAsUserID = "operator-run-as-user-id"
CertsuiteOperatorMultipleInstalled = "operator-multiple-same-operators"
)
1 change: 1 addition & 0 deletions tests/operator/tests/operator_crd_openapi_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var _ = Describe("Operator crd-openapi-schema", func() {

By("Deploy openvino operator for testing")
err = tshelper.DeployOperatorSubscription(
"ovms-operator",
"ovms-operator",
"alpha",
randomNamespace,
Expand Down
1 change: 1 addition & 0 deletions tests/operator/tests/operator_crd_versioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var _ = Describe("Operator crd-versioning,", func() {

By("Deploy openvino operator for testing")
err = tshelper.DeployOperatorSubscription(
"ovms-operator",
"ovms-operator",
"alpha",
randomNamespace,
Expand Down
11 changes: 9 additions & 2 deletions tests/operator/tests/operator_install_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,19 @@ var _ = Describe("Operator install-source,", Serial, func() {

By("Query the packagemanifest for defaultChannel for " + clusterLoggingOperatorName)
channel, err := globalhelper.QueryPackageManifestForDefaultChannel(clusterLoggingOperatorName, randomNamespace)
Expect(err).ToNot(HaveOccurred(), "Error querying package manifest for nginx-ingress-operator")
Expect(err).ToNot(HaveOccurred(), "Error querying package manifest for "+clusterLoggingOperatorName)

fmt.Printf("CHANNEL FOUND: %s\n", channel)

By("Query the packagemanifest for the " + clusterLoggingOperatorName)
version, err := globalhelper.QueryPackageManifestForVersion(clusterLoggingOperatorName, randomNamespace, channel)
Expect(err).ToNot(HaveOccurred(), "Error querying package manifest for nginx-ingress-operator")
Expect(err).ToNot(HaveOccurred(), "Error querying package manifest for "+clusterLoggingOperatorName)

fmt.Printf("VERSION FOUND: %s\n", version)

By("Deploy cluster-logging operator for testing")
err = tshelper.DeployOperatorSubscription(
clusterLoggingOperatorName,
clusterLoggingOperatorName,
channel,
openshiftLoggingNamespace,
Expand Down Expand Up @@ -138,6 +139,7 @@ var _ = Describe("Operator install-source,", Serial, func() {
By(fmt.Sprintf("Deploy nginx-ingress-operator%s for testing", "."+version))
// nginx-ingress-operator: in certified-operators group and version is certified
err = tshelper.DeployOperatorSubscription(
tsparams.CertifiedOperatorPrefixNginx,
tsparams.CertifiedOperatorPrefixNginx,
channel,
randomNamespace,
Expand Down Expand Up @@ -182,6 +184,7 @@ var _ = Describe("Operator install-source,", Serial, func() {
It("one operator not installed with OLM [negative]", func() {
By("Deploy openvino operator for testing")
err := tshelper.DeployOperatorSubscription(
"ovms-operator",
"ovms-operator",
"alpha",
randomNamespace,
Expand Down Expand Up @@ -242,6 +245,7 @@ var _ = Describe("Operator install-source,", Serial, func() {
By(fmt.Sprintf("Deploy nginx-ingress-operator%s for testing", "."+version))
// nginx-ingress-operator: in certified-operators group and version is certified
err = tshelper.DeployOperatorSubscription(
tsparams.CertifiedOperatorPrefixNginx,
tsparams.CertifiedOperatorPrefixNginx,
channel,
randomNamespace,
Expand Down Expand Up @@ -269,6 +273,7 @@ var _ = Describe("Operator install-source,", Serial, func() {

By("Deploy anchore-engine operator for testing")
err = tshelper.DeployOperatorSubscription(
tsparams.OperatorPrefixAnchore,
tsparams.OperatorPrefixAnchore,
"alpha",
randomNamespace,
Expand Down Expand Up @@ -316,6 +321,7 @@ var _ = Describe("Operator install-source,", Serial, func() {
It("two operators, one not installed with OLM [negative]", func() {
By("Deploy openvino operator for testing")
err := tshelper.DeployOperatorSubscription(
"ovms-operator",
"ovms-operator",
"alpha",
randomNamespace,
Expand All @@ -334,6 +340,7 @@ var _ = Describe("Operator install-source,", Serial, func() {

By("Deploy anchore-engine operator for testing")
err = tshelper.DeployOperatorSubscription(
tsparams.OperatorPrefixAnchore,
tsparams.OperatorPrefixAnchore,
"alpha",
randomNamespace,
Expand Down
2 changes: 2 additions & 0 deletions tests/operator/tests/operator_install_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var _ = Describe("Operator install-source,", func() {

By("Deploy cloudbees-ci operator for testing")
err = tshelper.DeployOperatorSubscription(
"cloudbees-ci",
"cloudbees-ci",
"alpha",
randomNamespace,
Expand Down Expand Up @@ -89,6 +90,7 @@ var _ = Describe("Operator install-source,", func() {
// The OpenVINO operator fails quickly due to the fact that it does not support the install mode type
// that it is used (OwnNamespace).
err := tshelper.DeployOperatorSubscription(
"ovms-operator",
"ovms-operator",
"alpha",
randomNamespace,
Expand Down
3 changes: 3 additions & 0 deletions tests/operator/tests/operator_install_status_no_privileges.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var _ = Describe("Operator install-status-no-privileges,", func() {
// cloudbees operator has clusterPermissions but no resourceNames
By("Deploy cloudbees-ci operator for testing")
err = tshelper.DeployOperatorSubscription(
"cloudbees-ci",
"cloudbees-ci",
"alpha",
randomNamespace,
Expand All @@ -57,6 +58,7 @@ var _ = Describe("Operator install-status-no-privileges,", func() {
// quay operator has no clusterPermissions
By("Deploy quay operator for testing")
err = tshelper.DeployOperatorSubscription(
"project-quay",
"project-quay",
"stable-3.11",
randomNamespace,
Expand All @@ -76,6 +78,7 @@ var _ = Describe("Operator install-status-no-privileges,", func() {
// kiali operator has resourceNames under its rules
By("Deploy kiali operator for testing")
err = tshelper.DeployOperatorSubscription(
"kiali",
"kiali",
"alpha",
randomNamespace,
Expand Down
Loading

0 comments on commit e03d6c8

Please sign in to comment.