Skip to content
This repository was archived by the owner on Dec 31, 2025. It is now read-only.

Commit 09d74d8

Browse files
Daniel Lipovetskydlipovetsky
authored andcommitted
Add workaround for flannel issue 1044
1 parent a1d5ffb commit 09d74d8

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

cmd/nodeinit.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ func networkInit(config *apis.InitConfiguration) error {
102102
log.Fatalf("failed to run %q: %s", strings.Join(cmd.Args, " "), err)
103103
}
104104

105+
log.Infoln("Applying workaround for https://github.com/coreos/flannel/issues/1044")
106+
if err := ensureFlannelDaemonSetToleratesAllNoScheduleTaints(); err != nil {
107+
log.Fatalf("Failed to apply workaround: %v", err)
108+
}
109+
105110
return nil
106111
}
107112

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package cmd
2+
3+
import (
4+
"bytes"
5+
"context"
6+
"fmt"
7+
"os/exec"
8+
"path/filepath"
9+
"strings"
10+
"time"
11+
12+
"github.com/platform9/nodeadm/constants"
13+
)
14+
15+
// ensureFlannelDaemonSetTolerations patches the flannel daemonset so that it
16+
// tolerates all NoSchedule taints. See https://github.com/coreos/flannel/issues/1044
17+
func ensureFlannelDaemonSetToleratesAllNoScheduleTaints() error {
18+
return patchFlannelDaemonSet()
19+
}
20+
21+
// patchFlannelDaemonSet is idempotent; kubectl patch has a zero exit code if
22+
// the patch has already been applied.
23+
func patchFlannelDaemonSet() error {
24+
name := "/bin/sh"
25+
arg := fmt.Sprintf(`%s --kubeconfig=%s --namespace=kube-system patch daemonset kube-flannel-ds --patch='{"spec":{"template":{"spec":{"tolerations":[{"effect":"NoSchedule","operator":"Exists"}]}}}}'`, filepath.Join(constants.BaseInstallDir, constants.KubectlFilename), constants.AdminKubeconfigFile)
26+
27+
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
28+
defer cancel()
29+
var stdout, stderr bytes.Buffer
30+
cmd := exec.CommandContext(ctx, name, "-c", arg)
31+
cmd.Stdout = &stdout
32+
cmd.Stderr = &stderr
33+
if err := cmd.Run(); err != nil {
34+
return fmt.Errorf("error running %q: %v (stdout: %s) (stderr: %s)", strings.Join(cmd.Args, " "), err, string(stdout.Bytes()), string(stderr.Bytes()))
35+
}
36+
37+
return nil
38+
}

0 commit comments

Comments
 (0)