-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add workaround for flannel issue 1044
- Loading branch information
1 parent
a1d5ffb
commit 09d74d8
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |