Skip to content

Commit

Permalink
More UT
Browse files Browse the repository at this point in the history
  • Loading branch information
song-jiang committed Feb 19, 2024
1 parent 4ec393e commit 41003a0
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions pkg/controller/installation/core_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,62 @@ var _ = Describe("Testing core-controller installation", func() {
Expect(*fc.Spec.BPFEnabled).To(BeFalse())
})

It("should set BPFEnabled to ture on FelixConfiguration if BPF is enabled on installation", func() {
network := operator.LinuxDataplaneBPF
cr.Spec.CalicoNetwork = &operator.CalicoNetworkSpec{LinuxDataplane: &network}
Expect(c.Create(ctx, cr)).NotTo(HaveOccurred())
_, err := r.Reconcile(ctx, reconcile.Request{})
Expect(err).ShouldNot(HaveOccurred())

fc := &crdv1.FelixConfiguration{}
err = c.Get(ctx, types.NamespacedName{Name: "default"}, fc)
Expect(err).ShouldNot(HaveOccurred())

// Should set correct annoation and BPFEnabled field.
Expect(fc.Annotations).NotTo(BeNil())
Expect(fc.Annotations[render.BPFOperatorAnnotation]).To(Equal("true"))
Expect(fc.Spec.BPFEnabled).NotTo(BeNil())
Expect(*fc.Spec.BPFEnabled).To(BeTrue())
})

It("should set BPFEnabled to false on FelixConfiguration if BPF is disabled on installation", func() {
// Enabled BPF first.
network := operator.LinuxDataplaneBPF
cr.Spec.CalicoNetwork = &operator.CalicoNetworkSpec{LinuxDataplane: &network}
Expect(c.Create(ctx, cr)).NotTo(HaveOccurred())
_, err := r.Reconcile(ctx, reconcile.Request{})
Expect(err).ShouldNot(HaveOccurred())

fc := &crdv1.FelixConfiguration{}
err = c.Get(ctx, types.NamespacedName{Name: "default"}, fc)
Expect(err).ShouldNot(HaveOccurred())

// Should set correct annoation and BPFEnabled field.
Expect(fc.Annotations).NotTo(BeNil())
Expect(fc.Annotations[render.BPFOperatorAnnotation]).To(Equal("true"))
Expect(fc.Spec.BPFEnabled).NotTo(BeNil())
Expect(*fc.Spec.BPFEnabled).To(BeTrue())

// Set dataplane to IPTables.
err = c.Get(ctx, types.NamespacedName{Name: "default"}, cr)
Expect(err).ShouldNot(HaveOccurred())
network = operator.LinuxDataplaneIptables
cr.Spec.CalicoNetwork = &operator.CalicoNetworkSpec{LinuxDataplane: &network}
Expect(c.Update(ctx, cr)).NotTo(HaveOccurred())
_, err = r.Reconcile(ctx, reconcile.Request{})
Expect(err).ShouldNot(HaveOccurred())

fc = &crdv1.FelixConfiguration{}
err = c.Get(ctx, types.NamespacedName{Name: "default"}, fc)
Expect(err).ShouldNot(HaveOccurred())

// Should set correct annoation and BPFEnabled field.
Expect(fc.Annotations).NotTo(BeNil())
Expect(fc.Annotations[render.BPFOperatorAnnotation]).To(Equal("false"))
Expect(fc.Spec.BPFEnabled).NotTo(BeNil())
Expect(*fc.Spec.BPFEnabled).To(BeFalse())
})

It("should set BPFEnabled on FelixConfiguration if FELIX_BPFENABLED Env var is set by old version of operator", func() {
ds := &appsv1.DaemonSet{}
err := c.Get(ctx,
Expand Down

0 comments on commit 41003a0

Please sign in to comment.