Skip to content

Commit

Permalink
Add workaround for flannel issue 1044
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Lipovetsky authored and dlipovetsky committed May 7, 2019
1 parent a1d5ffb commit 09d74d8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/nodeinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ func networkInit(config *apis.InitConfiguration) error {
log.Fatalf("failed to run %q: %s", strings.Join(cmd.Args, " "), err)
}

log.Infoln("Applying workaround for https://github.com/coreos/flannel/issues/1044")
if err := ensureFlannelDaemonSetToleratesAllNoScheduleTaints(); err != nil {
log.Fatalf("Failed to apply workaround: %v", err)
}

return nil
}

Expand Down
38 changes: 38 additions & 0 deletions cmd/workaround_flannel_issue_1044.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package cmd

import (
"bytes"
"context"
"fmt"
"os/exec"
"path/filepath"
"strings"
"time"

"github.com/platform9/nodeadm/constants"
)

// ensureFlannelDaemonSetTolerations patches the flannel daemonset so that it
// tolerates all NoSchedule taints. See https://github.com/coreos/flannel/issues/1044
func ensureFlannelDaemonSetToleratesAllNoScheduleTaints() error {
return patchFlannelDaemonSet()
}

// patchFlannelDaemonSet is idempotent; kubectl patch has a zero exit code if
// the patch has already been applied.
func patchFlannelDaemonSet() error {
name := "/bin/sh"
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)

ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
var stdout, stderr bytes.Buffer
cmd := exec.CommandContext(ctx, name, "-c", arg)
cmd.Stdout = &stdout
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("error running %q: %v (stdout: %s) (stderr: %s)", strings.Join(cmd.Args, " "), err, string(stdout.Bytes()), string(stderr.Bytes()))
}

return nil
}

0 comments on commit 09d74d8

Please sign in to comment.