Add FlannelConfCNI flag

Signed-off-by: Manuel Buil <mbuil@suse.com>
pull/5656/head
Manuel Buil 2022-06-08 10:38:07 +02:00
parent c00f953ef9
commit c705d34804
6 changed files with 30 additions and 2 deletions

View File

@ -533,6 +533,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.ContainerRuntimeEndpoint == "" {

View File

@ -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
}
@ -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)
}

View File

@ -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
}

View File

@ -31,6 +31,7 @@ type Agent struct {
NoFlannel bool
FlannelIface string
FlannelConf string
FlannelCniConfFile string
Debug bool
Rootless bool
RootlessAlreadyUnshared bool
@ -135,6 +136,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",
@ -258,6 +264,7 @@ func NewAgentCommand(action func(ctx *cli.Context) error) cli.Command {
ResolvConfFlag,
FlannelIfaceFlag,
FlannelConfFlag,
FlannelCniConfFileFlag,
ExtraKubeletArgs,
ExtraKubeProxyArgs,
ProtectKernelDefaultsFlag,

View File

@ -439,6 +439,7 @@ var ServerFlags = []cli.Flag{
ResolvConfFlag,
FlannelIfaceFlag,
FlannelConfFlag,
FlannelCniConfFileFlag,
ExtraKubeletArgs,
ExtraKubeProxyArgs,
ProtectKernelDefaultsFlag,

View File

@ -101,6 +101,7 @@ type Agent struct {
ImageCredProvBinDir string
ImageCredProvConfig string
IPSECPSK string
FlannelCniConfFile string
StrongSwanDir string
PrivateRegistry string
SystemDefaultRegistry string