From 6b3384970c2ef0cde09da0bcd140cf020acb1399 Mon Sep 17 00:00:00 2001 From: Maxime Mouchet Date: Tue, 25 Jan 2022 15:37:36 +0100 Subject: [PATCH] node: fix SetKubeletNodeIP when kubeletEnvFile does not exists --- pkg/network/network.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/network/network.go b/pkg/network/network.go index 84b6753..9c8b795 100644 --- a/pkg/network/network.go +++ b/pkg/network/network.go @@ -17,12 +17,14 @@ limitations under the License. package network import ( + "errors" "fmt" "github.com/txn2/txeh" "github.com/vishvananda/netlink" "golang.org/x/sys/unix" "io/ioutil" "net" + "os" "os/exec" "strings" ) @@ -82,6 +84,9 @@ func SetHostname(hostname string) { // SetKubeletNodeIP sets the node IP in the kubelet configuration. func SetKubeletNodeIP(kubeletEnvFile string, ip net.IP) { + if _, err := os.Stat(kubeletEnvFile); errors.Is(err, os.ErrNotExist) { + return + } // TODO: Do not override existing content? s := fmt.Sprintf("KUBELET_EXTRA_ARGS=\"--node-ip=%s\"\n", ip.String()) check(ioutil.WriteFile(kubeletEnvFile, []byte(s), 0644))