Skip to content

Commit

Permalink
Disable DHCP on cilium pod ENIs on Flatcar
Browse files Browse the repository at this point in the history
  • Loading branch information
rifelpet committed Sep 5, 2024
1 parent 801abbc commit d1e6e4e
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions nodeup/pkg/model/networking/cilium.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"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 +50,10 @@ func (b *CiliumBuilder) Build(c *fi.NodeupModelBuilderContext) error {
return nil
}

if b.Distribution == distributions.DistributionFlatcar && b.NodeupConfig.Networking.Cilium.IPAM == "eni" {
b.disableENIFlatcarDHCP(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 +197,29 @@ func (b *CiliumBuilder) buildCiliumEtcdSecrets(c *fi.NodeupModelBuilderContext)
return nil
}
}

// Flatcar is 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) disableENIFlatcarDHCP(c *fi.NodeupModelBuilderContext) {
contents := `
[Match]
Name=eth[1-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 d1e6e4e

Please sign in to comment.