Skip to content

Commit

Permalink
fix(nodeup): set MACAddressPolicy to none when using AWS CNI and …
Browse files Browse the repository at this point in the history
…Ubuntu 22.04
  • Loading branch information
moshevayner committed Feb 2, 2024
1 parent 6a1783b commit 1eeabc4
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions nodeup/pkg/model/sysctls.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ package model
import (
"fmt"
"net"
"os"
"strings"

"k8s.io/klog/v2"
"k8s.io/kops/pkg/apis/kops"
"k8s.io/kops/upup/pkg/fi"
"k8s.io/kops/upup/pkg/fi/nodeup/nodetasks"
Expand Down Expand Up @@ -195,5 +197,38 @@ func (b *SysctlBuilder) Build(c *fi.NodeupModelBuilderContext) error {
OnChangeExecute: [][]string{{"sysctl", "--system"}},
})

// Running AWS VPC CNI on Ubuntu 22.04 Requires Setting MACAddressPolicy to `none` (ref: https://github.com/aws/amazon-vpc-cni-k8s/issues/2103 & https://github.com/kubernetes/kops/issues/16255)
klog.V(2).Infof("Checking if we need to disable MACAddressPolicy on Ubuntu 22.04")
if b.NodeupConfig.Networking.AmazonVPC != nil && b.Distribution == distributions.DistributionUbuntu2204 {
klog.V(2).Infof("Detected OS %v; disabling MACAddressPolicy", b.Distribution)
// Read the contents of the file /usr/lib/systemd/network/99-default.link into a string
origFileName := "/usr/lib/systemd/network/99-default.link"
outputFileName := "/etc/systemd/network/99-default.link"
input, err := os.ReadFile("/usr/lib/systemd/network/99-default.link")
if err != nil {
klog.Errorf("Failed to read file %s: %v", origFileName, err)
return err
}

// Copy all the relevant entries and replace the one that contains MACAddressPolicy= with MACAddressPolicy=none
lines := strings.Split(string(input), "\n")
finalOutput := make([]string, 0, len(lines))
for i, line := range lines {
// We don't want to copy comments or empty lines
if strings.HasPrefix(line, "#") || len(line) == 0 {
continue
} else if strings.Contains(line, "MACAddressPolicy=") {
lines[i] = "MACAddressPolicy=none"
}
finalOutput = append(finalOutput, lines[i])
}
klog.V(2).Infof("Adding Task to write file %s", outputFileName)
c.AddTask(&nodetasks.File{
Path: outputFileName,
Contents: fi.NewStringResource(strings.Join(finalOutput, "\n")),
Type: nodetasks.FileType_File,
OnChangeExecute: [][]string{{"systemctl", "restart", "systemd-networkd"}},
})
}
return nil
}

0 comments on commit 1eeabc4

Please sign in to comment.