Skip to content

Commit

Permalink
Improve flannel logging
Browse files Browse the repository at this point in the history
Signed-off-by: Manuel Buil <[email protected]>
  • Loading branch information
manuelbuil committed Dec 2, 2021
1 parent b8a1f45 commit e34e7cc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions pkg/agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,9 @@ func get(envInfo *cmds.Agent, proxy proxy.Proxy) (*config.Node, error) {
}

if envInfo.FlannelConf == "" {
nodeConfig.FlannelConf = filepath.Join(envInfo.DataDir, "agent", "etc", "flannel", "net-conf.json")
nodeConfig.FlannelConfFile = filepath.Join(envInfo.DataDir, "agent", "etc", "flannel", "net-conf.json")
} else {
nodeConfig.FlannelConf = envInfo.FlannelConf
nodeConfig.FlannelConfFile = envInfo.FlannelConf
nodeConfig.FlannelConfOverride = true
}
nodeConfig.AgentConfig.CNIBinDir = filepath.Dir(hostLocal)
Expand Down
16 changes: 10 additions & 6 deletions pkg/agent/flannel/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func Prepare(ctx context.Context, nodeConfig *config.Node) error {
}

func Run(ctx context.Context, nodeConfig *config.Node, nodes v1.NodeInterface) error {
logrus.Infof("Starting flannel with backend %s", nodeConfig.FlannelBackend)
nodeName := nodeConfig.AgentConfig.NodeName

for {
Expand All @@ -92,17 +93,18 @@ func Run(ctx context.Context, nodeConfig *config.Node, nodes v1.NodeInterface) e
}
time.Sleep(2 * time.Second)
}
logrus.Info("Node CIDR assigned for: " + nodeName)
logrus.Info("Flannel found PodCIDR assigned for: " + nodeName)

go func() {
err := flannel(ctx, nodeConfig.FlannelIface, nodeConfig.FlannelConf, nodeConfig.AgentConfig.KubeConfigKubelet)
err := flannel(ctx, nodeConfig.FlannelIface, nodeConfig.FlannelConfFile, nodeConfig.AgentConfig.KubeConfigKubelet)
logrus.Fatalf("flannel exited: %v", err)
}()

return nil
}

func createCNIConf(dir string) error {
logrus.Debugf("Creating the CNI conf in directory %s", dir)
if dir == "" {
return nil
}
Expand All @@ -111,11 +113,12 @@ func createCNIConf(dir string) error {
}

func createFlannelConf(nodeConfig *config.Node) error {
if nodeConfig.FlannelConf == "" {
return nil
logrus.Debugf("Creating the flannel configuration for backend %s in file %s", nodeConfig.FlannelBackend, nodeConfig.FlannelConfFile)
if nodeConfig.FlannelConfFile == "" {
return fmt.Errorf("Flannel configuration not defined")
}
if nodeConfig.FlannelConfOverride {
logrus.Infof("Using custom flannel conf defined at %s", nodeConfig.FlannelConf)
logrus.Infof("Using custom flannel conf defined at %s", nodeConfig.FlannelConfFile)
return nil
}
confJSON := strings.Replace(flannelConf, "%CIDR%", nodeConfig.AgentConfig.ClusterCIDR.String(), -1)
Expand All @@ -139,7 +142,8 @@ func createFlannelConf(nodeConfig *config.Node) error {
}
confJSON = strings.Replace(confJSON, "%backend%", backendConf, -1)

return util.WriteFile(nodeConfig.FlannelConf, confJSON)
logrus.Debugf("The flannel configuration is %s", confJSON)
return util.WriteFile(nodeConfig.FlannelConfFile, confJSON)
}

func setupStrongSwan(nodeConfig *config.Node) error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/daemons/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type Node struct {
NoFlannel bool
SELinux bool
FlannelBackend string
FlannelConf string
FlannelConfFile string
FlannelConfOverride bool
FlannelIface *net.Interface
Containerd Containerd
Expand Down

0 comments on commit e34e7cc

Please sign in to comment.