Skip to content

Commit b982623

Browse files
committed
Enable cilium lb by default
1 parent 7a0a040 commit b982623

File tree

6 files changed

+69
-33
lines changed

6 files changed

+69
-33
lines changed

pkg/config/setup/system_probe.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func InitSystemProbeConfig(cfg pkgconfigmodel.Config) {
219219
cfg.BindEnvAndSetDefault(join(netNS, "conntrack_init_timeout"), 10*time.Second)
220220
cfg.BindEnvAndSetDefault(join(netNS, "allow_netlink_conntracker_fallback"), true)
221221
cfg.BindEnvAndSetDefault(join(netNS, "enable_ebpf_conntracker"), true)
222-
cfg.BindEnvAndSetDefault(join(netNS, "enable_cilium_lb_conntracker"), false)
222+
cfg.BindEnvAndSetDefault(join(netNS, "enable_cilium_lb_conntracker"), true)
223223

224224
cfg.BindEnvAndSetDefault(join(spNS, "source_excludes"), map[string][]string{})
225225
cfg.BindEnvAndSetDefault(join(spNS, "dest_excludes"), map[string][]string{})

pkg/network/tracer/cilium_lb.go

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"errors"
1414
"fmt"
1515
"net"
16+
"os"
1617
"sync"
1718
"time"
1819
"unsafe"
@@ -27,6 +28,7 @@ import (
2728
"github.com/DataDog/datadog-agent/pkg/network/netlink"
2829
"github.com/DataDog/datadog-agent/pkg/process/util"
2930
"github.com/DataDog/datadog-agent/pkg/telemetry"
31+
"github.com/DataDog/datadog-agent/pkg/util/kernel"
3032
"github.com/DataDog/datadog-agent/pkg/util/log"
3133
)
3234

@@ -106,28 +108,18 @@ type ciliumLoadBalancerConntracker struct {
106108

107109
func newCiliumLoadBalancerConntracker(cfg *config.Config) (netlink.Conntracker, error) {
108110
if !cfg.EnableCiliumLBConntracker {
109-
return netlink.NewNoOpConntracker(), nil
111+
return nil, nil
110112
}
111113

112-
ctTCP, err := ebpf.LoadPinnedMap("/sys/fs/bpf/tc/globals/cilium_ct4_global", &ebpf.LoadPinOptions{
113-
ReadOnly: true,
114-
})
114+
ctTCP, ctUDP, backends, err := loadMaps()
115115
if err != nil {
116-
return nil, fmt.Errorf("error loading pinned ct TCP map: %w", err)
117-
}
116+
// special case where we couldn't find at least one map
117+
if os.IsNotExist(err) {
118+
log.Info("not loading cilium conntracker since cilium maps are not present")
119+
return nil, nil
120+
}
118121

119-
ctUDP, err := ebpf.LoadPinnedMap("/sys/fs/bpf/tc/globals/cilium_ct_any4_global", &ebpf.LoadPinOptions{
120-
ReadOnly: true,
121-
})
122-
if err != nil {
123-
return nil, fmt.Errorf("error loading pinned ct UDP map: %w", err)
124-
}
125-
126-
backends, err := ebpf.LoadPinnedMap("/sys/fs/bpf/tc/globals/cilium_lb4_backends_v3", &ebpf.LoadPinOptions{
127-
ReadOnly: true,
128-
})
129-
if err != nil {
130-
return nil, fmt.Errorf("error loading pinned backends map: %w", err)
122+
return nil, err
131123
}
132124

133125
clb := &ciliumLoadBalancerConntracker{
@@ -161,6 +153,50 @@ func newCiliumLoadBalancerConntracker(cfg *config.Config) (netlink.Conntracker,
161153
return clb, nil
162154
}
163155

156+
func loadMaps() (ctTCP, ctUDP, backends *ebpf.Map, err error) {
157+
defer func() {
158+
if err != nil {
159+
ctTCP.Close()
160+
ctUDP.Close()
161+
backends.Close()
162+
}
163+
}()
164+
165+
ctTCP, err = loadMap(kernel.HostSys("/fs/bpf/tc/globals/cilium_ct4_global"))
166+
if ctTCP == nil {
167+
return nil, nil, nil, err
168+
}
169+
170+
ctUDP, err = loadMap(kernel.HostSys("/fs/bpf/tc/globals/cilium_ct_any4_global"))
171+
if ctUDP == nil {
172+
return nil, nil, nil, err
173+
}
174+
175+
backends, err = loadMap(kernel.HostSys("/fs/bpf/tc/globals/cilium_lb4_backends_v3"))
176+
if backends == nil {
177+
return nil, nil, nil, err
178+
}
179+
180+
return ctTCP, ctUDP, backends, nil
181+
}
182+
183+
func loadMap(path string) (m *ebpf.Map, err error) {
184+
// check if the path exists first, since the errors returned
185+
// from LoadPinnedMap are not consistent if it doesn't
186+
if _, err = os.Stat(path); err != nil {
187+
return nil, err
188+
}
189+
190+
m, err = ebpf.LoadPinnedMap(path, &ebpf.LoadPinOptions{
191+
ReadOnly: true,
192+
})
193+
if err != nil {
194+
return nil, fmt.Errorf("error loading pinned cilium map at %s: %w", path, err)
195+
}
196+
197+
return m, nil
198+
}
199+
164200
func ntohs(n uint16) uint16 {
165201
return binary.BigEndian.Uint16([]byte{byte(n), byte(n >> 8)})
166202
}
@@ -290,6 +326,7 @@ func (clb *ciliumLoadBalancerConntracker) Close() {
290326
clb.stop <- struct{}{}
291327
<-clb.stop
292328
clb.ctTCP.Map().Close()
329+
clb.ctUDP.Map().Close()
293330
clb.backends.Map().Close()
294331
})
295332
}

pkg/network/tracer/conntracker_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,3 +294,15 @@ func testConntrackerCrossNamespaceNATonRoot(t *testing.T, ct netlink.Conntracker
294294

295295
assert.Equal(t, util.AddressFromString("1.1.1.1"), trans.ReplSrcIP)
296296
}
297+
298+
func TestCiliumConntrackerEnabledByDefault(t *testing.T) {
299+
cfg := config.New()
300+
assert.True(t, cfg.EnableCiliumLBConntracker)
301+
302+
// most unit tests environments don't have cilium enabled (including CI)
303+
// so this should not load the cilium conntracker even if it enabled, without
304+
// any error
305+
clb, err := newCiliumLoadBalancerConntracker(cfg)
306+
assert.NoError(t, err)
307+
assert.Nil(t, clb)
308+
}

test/new-e2e/tests/npm/cilium_lb_conntracker_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func testCiliumLBConntracker(t *testing.T, ciliumVersion string) {
8686
awskubernetes.KindProvisioner(
8787
awskubernetes.WithName(name),
8888
awskubernetes.WithCiliumOptions(cilium.WithHelmValues(ciliumHelmValues), cilium.WithVersion(ciliumVersion)),
89-
awskubernetes.WithAgentOptions(kubernetesagentparams.WithHelmValues(systemProbeConfigWithCiliumLB)),
89+
awskubernetes.WithAgentOptions(kubernetesagentparams.WithHelmValues(systemProbeConfigNPMHelmValues)),
9090
awskubernetes.WithWorkloadApp(httpBinServiceInstall),
9191
awskubernetes.WithWorkloadApp(npmToolsWorkload),
9292
),

test/new-e2e/tests/npm/config.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,3 @@ func systemProbeConfigNPMEnv() []dockeragentparams.Option {
3030
dockeragentparams.WithAgentServiceEnvVariable("DD_SYSTEM_PROBE_NETWORK_ENABLED", pulumi.StringPtr("true")),
3131
}
3232
}
33-
34-
//go:embed config/npm-helm-cilium-lb-values.yaml
35-
var systemProbeConfigWithCiliumLB string

test/new-e2e/tests/npm/config/npm-helm-cilium-lb-values.yaml

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)