Skip to content

Commit

Permalink
Disable DHCP on cilium pod ENIs for various distros
Browse files Browse the repository at this point in the history
  • Loading branch information
rifelpet committed Sep 13, 2024
1 parent 91e2a7f commit 9fc828c
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions nodeup/pkg/model/networking/cilium.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ import (
"fmt"
"os"
"path/filepath"
"slices"

"golang.org/x/sys/unix"

"k8s.io/kops/nodeup/pkg/model"
"k8s.io/kops/upup/pkg/fi"
"k8s.io/kops/upup/pkg/fi/nodeup/nodetasks"
"k8s.io/kops/util/pkg/distributions"
)

// CiliumBuilder writes Cilium's assets
Expand All @@ -49,6 +51,13 @@ func (b *CiliumBuilder) Build(c *fi.NodeupModelBuilderContext) error {
return nil
}

if b.NodeupConfig.Networking.Cilium.IPAM == "eni" && slices.Contains([]distributions.Distribution{
distributions.DistributionFlatcar,
distributions.DistributionAmazonLinux2023,
}, b.Distribution) {
b.eniDisableDHCP(c)
}

if err := b.buildBPFMount(c); err != nil {
return fmt.Errorf("failed to create bpf mount unit: %w", err)
}
Expand Down Expand Up @@ -192,3 +201,29 @@ func (b *CiliumBuilder) buildCiliumEtcdSecrets(c *fi.NodeupModelBuilderContext)
return nil
}
}

// Certain distros are known to manipulate network interfaces created and managed by Cilium
// To avoid this, disable DHCP on the ENI interfaces and mark them as unmanaged
// https://github.com/cilium/cilium/blob/04f033e39c15fcfdae664caef3b0cbc17f2cec0b/Documentation/operations/system_requirements.rst#flatcar-on-aws-eks-in-eni-mode
func (b *CiliumBuilder) eniDisableDHCP(c *fi.NodeupModelBuilderContext) {
contents := `
[Match]
Name=eth[1-9]* ens[6-9]*
[Network]
DHCP=no
[Link]
Unmanaged=yes
`

c.AddTask(&nodetasks.File{
Path: "/etc/systemd/network/01-no-dhcp.network",
Contents: fi.NewStringResource(contents),
Type: nodetasks.FileType_File,
OnChangeExecute: [][]string{
{"systemctl", "daemon-reload"},
{"systemctl", "restart", "systemd-networkd"},
},
})
}

0 comments on commit 9fc828c

Please sign in to comment.