Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Release 1.20] Improve flannel logging #4618

Merged
merged 1 commit into from
Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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