Skip to content

Commit

Permalink
Merge pull request #5682 from manuelbuil/flannelcniconf123
Browse files Browse the repository at this point in the history
[Release 1.23] Add FlannelConfCNI flag
  • Loading branch information
manuelbuil committed Jun 15, 2022
2 parents 8bbc089 + 3e74702 commit 2507fd8
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions pkg/agent/config/config.go
Expand Up @@ -530,6 +530,7 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N
}
nodeConfig.AgentConfig.CNIBinDir = filepath.Dir(hostLocal)
nodeConfig.AgentConfig.CNIConfDir = filepath.Join(envInfo.DataDir, "agent", "etc", "cni", "net.d")
nodeConfig.AgentConfig.FlannelCniConfFile = envInfo.FlannelCniConfFile
}

if !nodeConfig.Docker && nodeConfig.ContainerRuntimeEndpoint == "" {
Expand Down
9 changes: 7 additions & 2 deletions pkg/agent/flannel/setup.go
Expand Up @@ -91,7 +91,7 @@ const (
)

func Prepare(ctx context.Context, nodeConfig *config.Node) error {
if err := createCNIConf(nodeConfig.AgentConfig.CNIConfDir); err != nil {
if err := createCNIConf(nodeConfig.AgentConfig.CNIConfDir, nodeConfig); err != nil {
return err
}

Expand Down Expand Up @@ -146,12 +146,17 @@ func waitForPodCIDR(ctx context.Context, nodeName string, nodes typedcorev1.Node
return nil
}

func createCNIConf(dir string) error {
func createCNIConf(dir string, nodeConfig *config.Node) error {
logrus.Debugf("Creating the CNI conf in directory %s", dir)
if dir == "" {
return nil
}
p := filepath.Join(dir, "10-flannel.conflist")

if nodeConfig.AgentConfig.FlannelCniConfFile != "" {
logrus.Debugf("Using %s as the flannel CNI conf", nodeConfig.AgentConfig.FlannelCniConfFile)
return util.CopyFile(nodeConfig.AgentConfig.FlannelCniConfFile, p)
}
return util.WriteFile(p, cniConf)
}

Expand Down
13 changes: 13 additions & 0 deletions pkg/agent/util/file.go
Expand Up @@ -16,3 +16,16 @@ func WriteFile(name string, content string) error {
}
return nil
}

func CopyFile(sourceFile string, destinationFile string) error {
os.MkdirAll(filepath.Dir(destinationFile), 0755)
input, err := ioutil.ReadFile(sourceFile)
if err != nil {
return errors.Wrapf(err, "copying %s to %s", sourceFile, destinationFile)
}
err = ioutil.WriteFile(destinationFile, input, 0644)
if err != nil {
return errors.Wrapf(err, "copying %s to %s", sourceFile, destinationFile)
}
return nil
}
7 changes: 7 additions & 0 deletions pkg/cli/cmds/agent.go
Expand Up @@ -31,6 +31,7 @@ type Agent struct {
NoFlannel bool
FlannelIface string
FlannelConf string
FlannelCniConfFile string
Debug bool
Rootless bool
RootlessAlreadyUnshared bool
Expand Down Expand Up @@ -134,6 +135,11 @@ var (
Usage: "(agent/networking) Override default flannel config file",
Destination: &AgentConfig.FlannelConf,
}
FlannelCniConfFileFlag = cli.StringFlag{
Name: "flannel-cni-conf",
Usage: "(agent/networking) Override default flannel cni config file",
Destination: &AgentConfig.FlannelCniConfFile,
}
ResolvConfFlag = cli.StringFlag{
Name: "resolv-conf",
Usage: "(agent/networking) Kubelet resolv.conf file",
Expand Down Expand Up @@ -259,6 +265,7 @@ func NewAgentCommand(action func(ctx *cli.Context) error) cli.Command {
ResolvConfFlag,
FlannelIfaceFlag,
FlannelConfFlag,
FlannelCniConfFileFlag,
ExtraKubeletArgs,
ExtraKubeProxyArgs,
ProtectKernelDefaultsFlag,
Expand Down
1 change: 1 addition & 0 deletions pkg/cli/cmds/server.go
Expand Up @@ -445,6 +445,7 @@ var ServerFlags = []cli.Flag{
ResolvConfFlag,
FlannelIfaceFlag,
FlannelConfFlag,
FlannelCniConfFileFlag,
ExtraKubeletArgs,
ExtraKubeProxyArgs,
ProtectKernelDefaultsFlag,
Expand Down
1 change: 1 addition & 0 deletions pkg/daemons/config/types.go
Expand Up @@ -111,6 +111,7 @@ type Agent struct {
ImageCredProvBinDir string
ImageCredProvConfig string
IPSECPSK string
FlannelCniConfFile string
StrongSwanDir string
PrivateRegistry string
SystemDefaultRegistry string
Expand Down

0 comments on commit 2507fd8

Please sign in to comment.