Skip to content

Commit

Permalink
Required changes to testing for egressFirewall
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Tanenbaum <jtanenba@redhat.com>
  • Loading branch information
JacobTanenbaum committed Jun 22, 2020
1 parent e8aec05 commit bdf5b2d
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 47 deletions.
9 changes: 7 additions & 2 deletions go-controller/pkg/node/gateway_init_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"github.com/coreos/go-iptables/iptables"
"github.com/vishvananda/netlink"

egressfirewallfake "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/crd/egressfirewall/v1/apis/clientset/versioned/fake"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
Expand Down Expand Up @@ -175,9 +177,10 @@ cookie=0x0, duration=8366.597s, table=1, n_packets=10641, n_bytes=10370087, prio
fakeClient := fake.NewSimpleClientset(&v1.NodeList{
Items: []v1.Node{existingNode},
})
egressFirewallFakeClient := &egressfirewallfake.Clientset{}

stop := make(chan struct{})
wf, err := factory.NewWatchFactory(fakeClient)
wf, err := factory.NewWatchFactory(fakeClient, egressFirewallFakeClient)
Expect(err).NotTo(HaveOccurred())
defer func() {
close(stop)
Expand Down Expand Up @@ -361,7 +364,9 @@ var _ = Describe("Gateway Init Operations", func() {
fakeClient := fake.NewSimpleClientset(&v1.NodeList{
Items: []v1.Node{existingNode},
})
wf, err := factory.NewWatchFactory(fakeClient)
egressFirewallFakeClient := &egressfirewallfake.Clientset{}

wf, err := factory.NewWatchFactory(fakeClient, egressFirewallFakeClient)
Expect(err).NotTo(HaveOccurred())
defer wf.Shutdown()

Expand Down
6 changes: 3 additions & 3 deletions go-controller/pkg/ovn/endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ var _ = Describe("OVN Namespace Operations", func() {

testE.addCmds(tExec, serviceT, endpointsT)

fakeOvn.start(ctx,
fakeOvn.start(ctx, nil,
&v1.EndpointsList{
Items: []v1.Endpoints{
endpointsT,
Expand Down Expand Up @@ -224,7 +224,7 @@ var _ = Describe("OVN Namespace Operations", func() {
)
testE.addCmds(tExec, serviceT, endpointsT)

fakeOvn.start(ctx,
fakeOvn.start(ctx, nil,
&v1.EndpointsList{
Items: []v1.Endpoints{
endpointsT,
Expand Down Expand Up @@ -288,7 +288,7 @@ var _ = Describe("OVN Namespace Operations", func() {
testE.addNodePortPortCmds(tExec, serviceT, endpointsT)
testE.addCmds(tExec, serviceT, endpointsT)

fakeOvn.start(ctx,
fakeOvn.start(ctx, nil,
&v1.EndpointsList{
Items: []v1.Endpoints{
endpointsT,
Expand Down
20 changes: 14 additions & 6 deletions go-controller/pkg/ovn/master_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/fake"

egressfirewallfake "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/crd/egressfirewall/v1/apis/clientset/versioned/fake"

"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/config"
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/factory"
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/kube"
Expand Down Expand Up @@ -307,6 +309,7 @@ var _ = Describe("Master Operations", func() {
fakeClient := fake.NewSimpleClientset(&v1.NodeList{
Items: []v1.Node{testNode},
})
egressFirewallFakeClient := &egressfirewallfake.Clientset{}

err := util.SetExec(fexec)
Expect(err).NotTo(HaveOccurred())
Expand All @@ -323,7 +326,7 @@ var _ = Describe("Master Operations", func() {
err = nodeAnnotator.Run()
Expect(err).NotTo(HaveOccurred())

f, err = factory.NewWatchFactory(fakeClient)
f, err = factory.NewWatchFactory(fakeClient, egressFirewallFakeClient)
Expect(err).NotTo(HaveOccurred())

clusterController := NewOvnController(fakeClient, f, stopChan, newFakeAddressSetFactory())
Expand Down Expand Up @@ -390,6 +393,7 @@ var _ = Describe("Master Operations", func() {
fakeClient := fake.NewSimpleClientset(&v1.NodeList{
Items: []v1.Node{testNode},
})
egressFirewallFakeClient := &egressfirewallfake.Clientset{}

err := util.SetExec(fexec)
Expect(err).NotTo(HaveOccurred())
Expand All @@ -406,7 +410,7 @@ var _ = Describe("Master Operations", func() {
err = nodeAnnotator.Run()
Expect(err).NotTo(HaveOccurred())

f, err = factory.NewWatchFactory(fakeClient)
f, err = factory.NewWatchFactory(fakeClient, egressFirewallFakeClient)
Expect(err).NotTo(HaveOccurred())

clusterController := NewOvnController(fakeClient, f, stopChan, newFakeAddressSetFactory())
Expand Down Expand Up @@ -470,6 +474,7 @@ var _ = Describe("Master Operations", func() {
fakeClient := fake.NewSimpleClientset(&v1.NodeList{
Items: []v1.Node{testNode},
})
egressFirewallFakeClient := &egressfirewallfake.Clientset{}

fexec, tcpLBUUID, udpLBUUID, sctpLBUUID := defaultFakeExec(nodeSubnet, nodeName, true)
err := util.SetExec(fexec)
Expand All @@ -491,7 +496,7 @@ var _ = Describe("Master Operations", func() {
err = nodeAnnotator.Run()
Expect(err).NotTo(HaveOccurred())

f, err = factory.NewWatchFactory(fakeClient)
f, err = factory.NewWatchFactory(fakeClient, egressFirewallFakeClient)
Expect(err).NotTo(HaveOccurred())

clusterController := NewOvnController(fakeClient, f, stopChan, newFakeAddressSetFactory())
Expand Down Expand Up @@ -618,6 +623,7 @@ subnet=%s
fakeClient := fake.NewSimpleClientset(&v1.NodeList{
Items: []v1.Node{masterNode},
})
egressFirewallFakeClient := &egressfirewallfake.Clientset{}

err := util.SetExec(fexec)
Expect(err).NotTo(HaveOccurred())
Expand All @@ -635,7 +641,7 @@ subnet=%s
err = nodeAnnotator.Run()
Expect(err).NotTo(HaveOccurred())

f, err = factory.NewWatchFactory(fakeClient)
f, err = factory.NewWatchFactory(fakeClient, egressFirewallFakeClient)
Expect(err).NotTo(HaveOccurred())

clusterController := NewOvnController(fakeClient, f, stopChan, newFakeAddressSetFactory())
Expand Down Expand Up @@ -744,6 +750,7 @@ var _ = Describe("Gateway Init Operations", func() {
fakeClient := fake.NewSimpleClientset(&v1.NodeList{
Items: []v1.Node{testNode},
})
egressFirewallFakeClient := &egressfirewallfake.Clientset{}

fexec := ovntest.NewFakeExec()
err := util.SetExec(fexec)
Expand Down Expand Up @@ -856,7 +863,7 @@ var _ = Describe("Gateway Init Operations", func() {
Output: "169.254.33.2",
})

f, err = factory.NewWatchFactory(fakeClient)
f, err = factory.NewWatchFactory(fakeClient, egressFirewallFakeClient)
Expect(err).NotTo(HaveOccurred())

clusterController := NewOvnController(fakeClient, f, stopChan, newFakeAddressSetFactory())
Expand Down Expand Up @@ -926,6 +933,7 @@ var _ = Describe("Gateway Init Operations", func() {
fakeClient := fake.NewSimpleClientset(&v1.NodeList{
Items: []v1.Node{testNode},
})
egressFirewallFakeClient := &egressfirewallfake.Clientset{}

fexec := ovntest.NewFakeExec()
err := util.SetExec(fexec)
Expand Down Expand Up @@ -1048,7 +1056,7 @@ var _ = Describe("Gateway Init Operations", func() {
Output: "169.254.33.2",
})

f, err = factory.NewWatchFactory(fakeClient)
f, err = factory.NewWatchFactory(fakeClient, egressFirewallFakeClient)
Expect(err).NotTo(HaveOccurred())

clusterController := NewOvnController(fakeClient, f, stopChan, newFakeAddressSetFactory())
Expand Down
6 changes: 3 additions & 3 deletions go-controller/pkg/ovn/namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ var _ = Describe("OVN Namespace Operations", func() {
namespaceT.Name,
)

fakeOvn.start(ctx,
fakeOvn.start(ctx, nil,
&v1.NamespaceList{
Items: []v1.Namespace{
namespaceT,
Expand Down Expand Up @@ -104,7 +104,7 @@ var _ = Describe("OVN Namespace Operations", func() {
It("creates an empty address set for the namespace without pods", func() {
app.Action = func(ctx *cli.Context) error {
const namespaceName string = "namespace1"
fakeOvn.start(ctx, &v1.NamespaceList{
fakeOvn.start(ctx, nil, &v1.NamespaceList{
Items: []v1.Namespace{
*newNamespace("namespace1"),
},
Expand All @@ -128,7 +128,7 @@ var _ = Describe("OVN Namespace Operations", func() {
It("deletes an empty namespace's resources", func() {
app.Action = func(ctx *cli.Context) error {
const namespaceName string = "namespace1"
fakeOvn.start(ctx, &v1.NamespaceList{
fakeOvn.start(ctx, nil, &v1.NamespaceList{
Items: []v1.Namespace{
*newNamespace(namespaceName),
},
Expand Down
25 changes: 17 additions & 8 deletions go-controller/pkg/ovn/ovn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/urfave/cli/v2"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes/fake"

egressfirewallfake "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/crd/egressfirewall/v1/apis/clientset/versioned/fake"
)

const (
Expand All @@ -19,12 +21,13 @@ const (
)

type FakeOVN struct {
fakeClient *fake.Clientset
watcher *factory.WatchFactory
controller *Controller
stopChan chan struct{}
fakeExec *ovntest.FakeExec
asf *fakeAddressSetFactory
fakeClient *fake.Clientset
fakeEgressClient *egressfirewallfake.Clientset
watcher *factory.WatchFactory
controller *Controller
stopChan chan struct{}
fakeExec *ovntest.FakeExec
asf *fakeAddressSetFactory
}

func NewFakeOVN(fexec *ovntest.FakeExec) *FakeOVN {
Expand All @@ -37,10 +40,15 @@ func NewFakeOVN(fexec *ovntest.FakeExec) *FakeOVN {
}
}

func (o *FakeOVN) start(ctx *cli.Context, objects ...runtime.Object) {
func (o *FakeOVN) start(ctx *cli.Context, egressObjects runtime.Object, objects ...runtime.Object) {
_, err := config.InitConfig(ctx, o.fakeExec, nil)
Expect(err).NotTo(HaveOccurred())

if egressObjects == nil {
o.fakeEgressClient = egressfirewallfake.NewSimpleClientset()
} else {
o.fakeEgressClient = egressfirewallfake.NewSimpleClientset(egressObjects)
}
o.fakeClient = fake.NewSimpleClientset(objects...)
o.init()
}
Expand All @@ -59,7 +67,8 @@ func (o *FakeOVN) init() {
var err error

o.stopChan = make(chan struct{})
o.watcher, err = factory.NewWatchFactory(o.fakeClient)
//egressFirewallFakeClient := &egressfirewallfake.Clientset{}
o.watcher, err = factory.NewWatchFactory(o.fakeClient, o.fakeEgressClient)
Expect(err).NotTo(HaveOccurred())

o.controller = NewOvnController(o.fakeClient, o.watcher, o.stopChan, o.asf)
Expand Down
20 changes: 10 additions & 10 deletions go-controller/pkg/ovn/pods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ var _ = Describe("OVN Pod Operations", func() {
Output: "\n",
})

fakeOvn.start(ctx, &v1.PodList{
fakeOvn.start(ctx, nil, &v1.PodList{
Items: []v1.Pod{
*newPod(t.namespace, t.podName, t.nodeName, t.podIP),
},
Expand Down Expand Up @@ -260,7 +260,7 @@ var _ = Describe("OVN Pod Operations", func() {

t.baseCmds(fExec)

fakeOvn.start(ctx, &v1.PodList{
fakeOvn.start(ctx, nil, &v1.PodList{
Items: []v1.Pod{},
})
t.populateLogicalSwitchCache(fakeOvn)
Expand Down Expand Up @@ -311,7 +311,7 @@ var _ = Describe("OVN Pod Operations", func() {
})
t.addCmdsForNonExistingPod(fExec)

fakeOvn.start(ctx, &v1.PodList{
fakeOvn.start(ctx, nil, &v1.PodList{
Items: []v1.Pod{
*newPod(t.namespace, t.podName, t.nodeName, t.podIP),
},
Expand Down Expand Up @@ -367,7 +367,7 @@ var _ = Describe("OVN Pod Operations", func() {

t.addCmdsForNonExistingFailedPod(fExec)

fakeOvn.start(ctx, &v1.PodList{
fakeOvn.start(ctx, nil, &v1.PodList{
Items: []v1.Pod{
*newPod(t.namespace, t.podName, t.nodeName, t.podIP),
},
Expand Down Expand Up @@ -422,7 +422,7 @@ var _ = Describe("OVN Pod Operations", func() {
})
t.addCmdsForNonExistingPod(fExec)

fakeOvn.start(ctx, &v1.PodList{
fakeOvn.start(ctx, nil, &v1.PodList{
Items: []v1.Pod{
*newPod(t.namespace, t.podName, t.nodeName, t.podIP),
},
Expand Down Expand Up @@ -474,7 +474,7 @@ var _ = Describe("OVN Pod Operations", func() {
"ovn-nbctl --timeout=15 --if-exists lsp-del " + t.portName,
})

fakeOvn.start(ctx)
fakeOvn.start(ctx, nil)
fakeOvn.controller.WatchPods()
Expect(fExec.CalledMatchesExpected()).To(BeTrue(), fExec.ErrorDesc)
return nil
Expand Down Expand Up @@ -504,7 +504,7 @@ var _ = Describe("OVN Pod Operations", func() {
})
t.addCmdsForNonExistingPod(fExec)

fakeOvn.start(ctx, &v1.PodList{
fakeOvn.start(ctx, nil, &v1.PodList{
Items: []v1.Pod{
*newPod(t.namespace, t.podName, t.nodeName, t.podIP),
},
Expand Down Expand Up @@ -550,7 +550,7 @@ var _ = Describe("OVN Pod Operations", func() {
})
t.addCmdsForNonExistingPod(fExec)

fakeOvn.start(ctx, &v1.PodList{
fakeOvn.start(ctx, nil, &v1.PodList{
Items: []v1.Pod{
*newPod(t.namespace, t.podName, t.nodeName, t.podIP),
},
Expand Down Expand Up @@ -618,7 +618,7 @@ var _ = Describe("OVN Pod Operations", func() {
})
t.addCmdsForNonExistingPod(fExec)

fakeOvn.start(ctx, &v1.PodList{
fakeOvn.start(ctx, nil, &v1.PodList{
Items: []v1.Pod{
*newPod(t.namespace, t.podName, t.nodeName, t.podIP),
},
Expand Down Expand Up @@ -684,7 +684,7 @@ var _ = Describe("OVN Pod Operations", func() {
namespaceT.Name,
)

fakeOvn.start(ctx,
fakeOvn.start(ctx, nil,
&v1.NamespaceList{
Items: []v1.Namespace{
namespaceT,
Expand Down
Loading

0 comments on commit bdf5b2d

Please sign in to comment.