Add toleration for agent daemonset

Fixes https://github.com/rook/rook/issues/1295
This commit is contained in:
Steve Leon committed 2017-12-12 18:33:44 -08:00
1 parent 42f9e27f1d
commit b73d5ddeb5
5 files changed
+73 -3

No files matched your search

@@ -26,6 +26,12 @@ spec:
{{- if not .Values.rbacEnable }}
- name: RBAC_ENABLED
value: "false"
{{- end }}
{{- if .Values.agent }}
{{- if .Values.agent.toleration }}
- name: AGENT_TOLERATION
value: {{ .Values.agent.toleration }}
{{- end }}
{{- end }}
- name: ROOK_LOG_LEVEL
value: {{ .Values.logLevel }}
+5
View File
@@ -26,3 +26,8 @@ logLevel: INFO
## If true, create & use RBAC resources
##
rbacEnable: true
## Rook Agent configuration
## toleration. Choose between NoSchedule, PreferNoSchedule and NoExecute:
# agent:
# toleration: NoSchedule
@@ -126,6 +126,9 @@ spec:
# To disable RBAC, uncomment the following:
# - name: RBAC_ENABLED
# value: "false"
# Rook Agent toleration. Choose between NoSchedule, PreferNoSchedule and NoExecute:
# - name: AGENT_TOLERATION
# value: "NoSchedule"
# The interval to check if every mon is in the quorum.
- name: ROOK_MON_HEALTHCHECK_INTERVAL
value: "45s"
+15 -3
View File
@@ -38,9 +38,10 @@ import (
)
const (
agentDaemonsetName = "rook-agent"
flexvolumePathDirEnv = "FLEXVOLUME_DIR_PATH"
flexvolumeDefaultDirPath = "/usr/libexec/kubernetes/kubelet-plugins/volume/exec/"
agentDaemonsetName = "rook-agent"
flexvolumePathDirEnv = "FLEXVOLUME_DIR_PATH"
flexvolumeDefaultDirPath = "/usr/libexec/kubernetes/kubelet-plugins/volume/exec/"
agentDaemonsetTolerationEnv = "AGENT_TOLERATION"
)
var logger = capnslog.NewPackageLogger("github.com/rook/rook", "op-agent")
@@ -187,6 +188,17 @@ func (a *Agent) createAgentDaemonSet(namespace string) error {
},
}
// Add toleration if any
tolerationValue := os.Getenv(agentDaemonsetTolerationEnv)
if tolerationValue != "" {
ds.Spec.Template.Spec.Tolerations = []v1.Toleration{
{
Effect: v1.TaintEffect(tolerationValue),
Operator: v1.TolerationOpExists,
},
}
}
_, err = a.clientset.Extensions().DaemonSets(namespace).Create(ds)
if err != nil {
if !kserrors.IsAlreadyExists(err) {
+44
View File
@@ -91,6 +91,7 @@ func TestStartAgentDaemonset(t *testing.T) {
assert.Equal(t, 2, len(envs))
image := agentDS.Spec.Template.Spec.Containers[0].Image
assert.Equal(t, "rook/test", image)
assert.Nil(t, agentDS.Spec.Template.Spec.Tolerations)
}
func TestGetContainerImage(t *testing.T) {
@@ -158,3 +159,46 @@ func TestGetContainerImageMultipleContainers(t *testing.T) {
assert.NotNil(t, err)
assert.Equal(t, "failed to get container image. There should only be exactly one container in this pod", err.Error())
}
func TestStartAgentDaemonsetWithToleration(t *testing.T) {
clientset := test.New(3)
os.Setenv(k8sutil.PodNamespaceEnvVar, "rook-system")
defer os.Unsetenv(k8sutil.PodNamespaceEnvVar)
os.Setenv(k8sutil.PodNameEnvVar, "rook-operator")
defer os.Unsetenv(k8sutil.PodNameEnvVar)
os.Setenv(agentDaemonsetTolerationEnv, "NoSchedule")
defer os.Unsetenv(agentDaemonsetTolerationEnv)
pod := v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "rook-operator",
Namespace: "rook-system",
},
Spec: v1.PodSpec{
Containers: []v1.Container{
{
Name: "mypodContainer",
Image: "rook/test",
},
},
},
}
clientset.CoreV1().Pods("rook-system").Create(&pod)
namespace := "ns"
a := New(clientset)
// start a basic cluster
err := a.Start(namespace)
assert.Nil(t, err)
// check daemonset toleration
agentDS, err := clientset.Extensions().DaemonSets(namespace).Get("rook-agent", metav1.GetOptions{})
assert.Nil(t, err)
assert.Equal(t, 1, len(agentDS.Spec.Template.Spec.Tolerations))
assert.Equal(t, "NoSchedule", string(agentDS.Spec.Template.Spec.Tolerations[0].Effect))
assert.Equal(t, "Exists", string(agentDS.Spec.Template.Spec.Tolerations[0].Operator))
}