Skip to content

Commit

Permalink
Set BPFEnabled to true when installing in bpf mode. (#3721)
Browse files Browse the repository at this point in the history
* Set the bpfEnabled felix config if its a fresh install in ebpf mode.

* update CRDs

* Fix error handling

* Fix copyright

* Update error msg

* Add UT and address review comments

* Fix copyright

* update crds

* Update UT to use Reconcile
  • Loading branch information
sridhartigera authored Jan 28, 2025
1 parent 9558bda commit f031e8b
Show file tree
Hide file tree
Showing 3 changed files with 1,086 additions and 3 deletions.
12 changes: 10 additions & 2 deletions pkg/controller/installation/core_controller.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019-2024 Tigera, Inc. All rights reserved.
// Copyright (c) 2019-2025 Tigera, Inc. All rights reserved.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -1792,14 +1792,22 @@ func (r *ReconcileInstallation) setDefaultsOnFelixConfiguration(ctx context.Cont
// FelixConfiguration has the correct value set.

// If calico-node daemonset exists, we need to check the ENV VAR and set FelixConfiguration accordingly.
// Otherwise, just move on.
// Otherwise, this is a fresh install in eBPF mode, set the felix config.
ds := &appsv1.DaemonSet{}
err := r.client.Get(ctx, types.NamespacedName{Namespace: common.CalicoNamespace, Name: common.NodeDaemonSetName}, ds)
if err != nil {
if !apierrors.IsNotFound(err) {
reqLogger.Error(err, "An error occurred when getting the Daemonset resource")
return false, err
}
if install.Spec.BPFEnabled() {
err = setBPFEnabledOnFelixConfiguration(fc, true)
if err != nil {
reqLogger.Error(err, "Unable to enable eBPF data plane with a fresh install")
return false, err
}
updated = true
}
} else {
bpfEnabledOnDaemonsetWithEnvVar, err := bpfEnabledOnDaemonsetWithEnvVar(ds)
if err != nil {
Expand Down
20 changes: 19 additions & 1 deletion pkg/controller/installation/core_controller_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019-2024 Tigera, Inc. All rights reserved.
// Copyright (c) 2019-2025 Tigera, Inc. All rights reserved.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -1010,6 +1010,24 @@ var _ = Describe("Testing core-controller installation", func() {
Expect(*fc.Spec.BPFEnabled).To(BeTrue())
})

It("should set BPFEnabled to true on FelixConfiguration on a fresh install in BPF Mode", 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() {
createNodeDaemonSet()

Expand Down
Loading

0 comments on commit f031e8b

Please sign in to comment.