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

cnf-tests: Skip test if multinetpolicy CRD is not present #1294

Merged
merged 1 commit into from
Oct 24, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ var _ = Describe("[sriov] [multinetworkpolicy] MultiNetworkPolicy integration",
sctpEnabled := false
sriovEnabled := false

BeforeEach(func() {
// Tests can be triggered by setting `FEATURE=sriov` and can fail because the
// feature is not enabled.
crdPresent, err := np.IsMultiEnabled()
Expect(err).ToNot(HaveOccurred())
if !crdPresent {
Fail("feature [multinetworkpolicy] not enabled on cluster. run FEATURES=multinetworkpolicy make feature-deploy to enable it.")
}
})

execute.BeforeAll(func() {
sriovEnabled = networks.IsSriovOperatorInstalled()
if !sriovEnabled {
Expand Down
19 changes: 19 additions & 0 deletions cnf-tests/testsuites/pkg/networkpolicy/multinetworkpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,33 @@ package networkpolicy

import (
"context"
"fmt"

"github.com/onsi/gomega"
apiext "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"

multinetpolicyv1 "github.com/k8snetworkplumbingwg/multi-networkpolicy/pkg/apis/k8s.cni.cncf.io/v1beta1"
client "github.com/openshift-kni/cnf-features-deploy/cnf-tests/testsuites/pkg/client"
)

func IsMultiEnabled() (bool, error) {
crd := &apiext.CustomResourceDefinition{}
err := client.Client.Get(context.TODO(), runtimeclient.ObjectKey{Name: "multi-networkpolicies.k8s.cni.cncf.io"}, crd)
if k8serrors.IsNotFound(err) {
return false, nil
}

if err != nil {
return false, fmt.Errorf("can't get CRD `multi-networkpolicies.k8s.cni.cncf.io` on cluster: %w", err)
}

return true, nil
}

type MultiNetworkPolicyOpt func(*multinetpolicyv1.MultiNetworkPolicy)

func MakeMultiNetworkPolicy(targetNetwork string, opts ...MultiNetworkPolicyOpt) *multinetpolicyv1.MultiNetworkPolicy {
Expand Down
5 changes: 3 additions & 2 deletions cnf-tests/testsuites/validationsuite/cluster/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
sriovtestclient "github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/client"
testclient "github.com/openshift-kni/cnf-features-deploy/cnf-tests/testsuites/pkg/client"
"github.com/openshift-kni/cnf-features-deploy/cnf-tests/testsuites/pkg/namespaces"
"github.com/openshift-kni/cnf-features-deploy/cnf-tests/testsuites/pkg/networkpolicy"
"github.com/openshift-kni/cnf-features-deploy/cnf-tests/testsuites/pkg/networks"
utilNodes "github.com/openshift-kni/cnf-features-deploy/cnf-tests/testsuites/pkg/nodes"
"github.com/openshift-kni/cnf-features-deploy/cnf-tests/testsuites/pkg/utils"
Expand Down Expand Up @@ -503,9 +504,9 @@ var _ = Describe("validation", func() {

Context("[multineworkpolicy]", func() {
It("should have MultiNetworkPolicy CRD available in the cluster", func() {
crd := &apiext.CustomResourceDefinition{}
err := testclient.Client.Get(context.TODO(), goclient.ObjectKey{Name: "multi-networkpolicies.k8s.cni.cncf.io"}, crd)
crdPresent, err := networkpolicy.IsMultiEnabled()
Expect(err).ToNot(HaveOccurred())
Expect(crdPresent).To(BeTrue())
})

It("should have the daemonset in running state", func() {
Expand Down