From bd25630d917c0f68d2f275c99bd3a34870b10419 Mon Sep 17 00:00:00 2001 From: travisn Date: Tue, 22 Jan 2019 22:57:25 -0700 Subject: [PATCH] allow disabling of fsGroup in the flex driver Signed-off-by: travisn --- PendingReleaseNotes.md | 3 +- .../examples/kubernetes/ceph/operator.yaml | 4 ++ cmd/rookflex/cmd/init.go | 43 ++++++++++++++++++- pkg/operator/ceph/agent/agent.go | 9 ++++ pkg/operator/ceph/agent/agent_test.go | 2 +- 5 files changed, 57 insertions(+), 4 deletions(-) diff --git a/PendingReleaseNotes.md b/PendingReleaseNotes.md index f8dfa4d76..a2eaf51c9 100644 --- a/PendingReleaseNotes.md +++ b/PendingReleaseNotes.md @@ -13,7 +13,8 @@ ### Ceph - A `CephNFS` CRD will start NFS daemon(s) for exporting CephFS volumes or RGW buckets. See the [NFS documentation](Documentation/ceph-nfs-crd.md). -- Selinux labeling for mounts can now be toggled with the ROOK_ENABLE_SELINUX_RELABELING environment variable. This addresses https://github.com/rook/rook/issues/2417 +- Selinux labeling for mounts can now be toggled with the [ROOK_ENABLE_SELINUX_RELABELING](https://github.com/rook/rook/issues/2417) environment variable. +- Recursive chown for mounts can now be toggled with the [ROOK_ENABLE_FSGROUP](https://github.com/rook/rook/issues/2254) environment variable. - Added the dashboard `port` configuration setting. - Added the dashboard `ssl` configuration setting. diff --git a/cluster/examples/kubernetes/ceph/operator.yaml b/cluster/examples/kubernetes/ceph/operator.yaml index f886d8bd1..73cde2e5e 100755 --- a/cluster/examples/kubernetes/ceph/operator.yaml +++ b/cluster/examples/kubernetes/ceph/operator.yaml @@ -475,6 +475,10 @@ spec: # For more details see https://github.com/rook/rook/issues/2417 - name: ROOK_ENABLE_SELINUX_RELABELING value: "true" + # In large volumes it will take some time to chown all the files. Disable it here if you have performance issues. + # For more details see https://github.com/rook/rook/issues/2254 + - name: ROOK_ENABLE_FSGROUP + value: "true" # The name of the node to pass with the downward API - name: NODE_NAME valueFrom: diff --git a/cmd/rookflex/cmd/init.go b/cmd/rookflex/cmd/init.go index 982eb1569..b7a8477a9 100644 --- a/cmd/rookflex/cmd/init.go +++ b/cmd/rookflex/cmd/init.go @@ -45,12 +45,19 @@ func initPlugin(cmd *cobra.Command, args []string) error { rookEnableSelinuxRelabeling = true } - status := flexvolume.DriverStatus{ + rookEnableFSGroup, err := strconv.ParseBool(os.Getenv(agent.RookEnableFSGroupEnv)) + if err != nil { + // Don't log any errors to stdout as this will break the init. Just default the value to true. + rookEnableFSGroup = true + } + + status := DriverStatus{ Status: flexvolume.StatusSuccess, - Capabilities: &flexvolume.DriverCapabilities{ + Capabilities: &DriverCapabilities{ Attach: false, // Required for any mount performed on a host running selinux SELinuxRelabel: rookEnableSelinuxRelabeling, + FSGroup: rookEnableFSGroup, }, } if err := json.NewEncoder(os.Stdout).Encode(&status); err != nil { @@ -59,3 +66,35 @@ func initPlugin(cmd *cobra.Command, args []string) error { os.Exit(0) return nil } + +// FIX: After we move to the k8s 1.13 dependencies, we can remove this type +// and reference the type in k8s.io/kubernetes/pkg/volume/flexvolume/driver-call.go +type DriverStatus struct { + // Status of the callout. One of "Success", "Failure" or "Not supported". + Status string `json:"status"` + // Reason for success/failure. + Message string `json:"message,omitempty"` + // Path to the device attached. This field is valid only for attach calls. + // ie: /dev/sdx + DevicePath string `json:"device,omitempty"` + // Cluster wide unique name of the volume. + VolumeName string `json:"volumeName,omitempty"` + // Represents volume is attached on the node + Attached bool `json:"attached,omitempty"` + // Returns capabilities of the driver. + // By default we assume all the capabilities are supported. + // If the plugin does not support a capability, it can return false for that capability. + Capabilities *DriverCapabilities `json:",omitempty"` + // Returns the actual size of the volume after resizing is done, the size is in bytes. + ActualVolumeSize int64 `json:"volumeNewSize,omitempty"` +} + +// FIX: After we move to the k8s 1.13 dependencies, we can remove this type +// and reference the type in k8s.io/kubernetes/pkg/volume/flexvolume/driver-call.go +type DriverCapabilities struct { + Attach bool `json:"attach"` + SELinuxRelabel bool `json:"selinuxRelabel"` + SupportsMetrics bool `json:"supportsMetrics"` + FSGroup bool `json:"fsGroup"` + RequiresFSResize bool `json:"requiresFSResize"` +} diff --git a/pkg/operator/ceph/agent/agent.go b/pkg/operator/ceph/agent/agent.go index 01ce9c2ea..5aae8b309 100644 --- a/pkg/operator/ceph/agent/agent.go +++ b/pkg/operator/ceph/agent/agent.go @@ -43,6 +43,7 @@ const ( agentDaemonsetTolerationKeyEnv = "AGENT_TOLERATION_KEY" AgentMountSecurityModeEnv = "AGENT_MOUNT_SECURITY_MODE" RookEnableSelinuxRelabelingEnv = "ROOK_ENABLE_SELINUX_RELABELING" + RookEnableFSGroupEnv = "ROOK_ENABLE_FSGROUP" // MountSecurityModeAny "any" security mode for the agent for mount action MountSecurityModeAny = "Any" @@ -94,6 +95,13 @@ func (a *Agent) createAgentDaemonSet(namespace, agentImage, serviceAccount strin rookEnableSelinuxRelabeling = "true" } + rookEnableFSGroup := os.Getenv(RookEnableFSGroupEnv) + _, err = strconv.ParseBool(rookEnableFSGroup) + if err != nil { + logger.Warningf("Invalid %s value \"%s\". Defaulting to \"true\".", RookEnableFSGroupEnv, rookEnableFSGroup) + rookEnableFSGroup = "true" + } + privileged := true ds := &extensions.DaemonSet{ ObjectMeta: metav1.ObjectMeta{ @@ -142,6 +150,7 @@ func (a *Agent) createAgentDaemonSet(namespace, agentImage, serviceAccount strin k8sutil.NodeEnvVar(), {Name: AgentMountSecurityModeEnv, Value: agentMountSecurityMode}, {Name: RookEnableSelinuxRelabelingEnv, Value: rookEnableSelinuxRelabeling}, + {Name: RookEnableFSGroupEnv, Value: rookEnableFSGroup}, }, }, }, diff --git a/pkg/operator/ceph/agent/agent_test.go b/pkg/operator/ceph/agent/agent_test.go index 9d0c568a3..4ba0e658e 100644 --- a/pkg/operator/ceph/agent/agent_test.go +++ b/pkg/operator/ceph/agent/agent_test.go @@ -73,7 +73,7 @@ func TestStartAgentDaemonset(t *testing.T) { volumeMounts := agentDS.Spec.Template.Spec.Containers[0].VolumeMounts assert.Equal(t, 4, len(volumeMounts)) envs := agentDS.Spec.Template.Spec.Containers[0].Env - assert.Equal(t, 4, len(envs)) + assert.Equal(t, 5, len(envs)) image := agentDS.Spec.Template.Spec.Containers[0].Image assert.Equal(t, "rook/rook:myversion", image) assert.Nil(t, agentDS.Spec.Template.Spec.Tolerations)