ceph: chown ceph directories

At the beginning of every container startup we now change the ownership
of every known ceph directories to ceph:ceph.

This will allow daemons to start properly as well as allowing daemon to
writes their logs on files.

This is needed because ceph daemon now run as 'ceph' instead of 'root'

Signed-off-by: Sébastien Han <seb@redhat.com>
This commit is contained in:
Sébastien Han committed 2019-07-19 11:13:42 +02:00
1 parent 900abbc967
commit 9120791e24
9 files changed
+53 -1

No files matched your search

+1
View File
@@ -274,6 +274,7 @@ func (c *Cluster) makeMgrDaemonContainer(mgrConfig *mgrConfig) v1.Container {
},
InitialDelaySeconds: 60,
},
Lifecycle: opspec.PodLifeCycle(""),
}
return container
}
+1
View File
@@ -233,6 +233,7 @@ func (c *Cluster) makeMonDaemonContainer(monConfig *monConfig) v1.Container {
k8sutil.PodIPEnvVar(podIPEnvVar),
),
Resources: cephv1.GetMonResources(c.spec.Resources),
Lifecycle: opspec.PodLifeCycle(""),
}
// If host networking is enabled, we don't need a bind addr that is different from the public addr
+2
View File
@@ -265,6 +265,7 @@ func (c *Cluster) makeDeployment(nodeName string, selection rookalpha.Selection,
if c.HostNetwork {
DNSPolicy = v1.DNSClusterFirstWithHostNet
}
deployment := &apps.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf(osdAppNameFmt, osd.ID),
@@ -324,6 +325,7 @@ func (c *Cluster) makeDeployment(nodeName string, selection rookalpha.Selection,
Env: envVars,
Resources: resources,
SecurityContext: securityContext,
Lifecycle: opspec.PodLifeCycle(osd.DataPath),
},
},
Volumes: volumes,
+1
View File
@@ -83,6 +83,7 @@ func (m *Mirroring) makeMirroringDaemonContainer(daemonConfig *daemonConfig) v1.
VolumeMounts: opspec.DaemonVolumeMounts(daemonConfig.DataPathMap, daemonConfig.ResourceName),
Env: opspec.DaemonEnvVars(m.cephVersion.Image),
Resources: m.resources,
Lifecycle: opspec.PodLifeCycle(""),
}
return container
}
+13
View File
@@ -52,6 +52,12 @@ const (
// RbdMirrorType defines the rbd-mirror DaemonType
RbdMirrorType DaemonType = "rbd-mirror"
// CephUser is the Linux Ceph username
CephUser = "ceph"
// CephGroup is the Linux Ceph groupname
CephGroup = "ceph"
)
var (
@@ -66,6 +72,13 @@ var (
// VarLogCephDir defines Ceph logging directory. It is made overwriteable only for unit tests where it
// may be needed to send data intended for /var/log/ceph to a temporary test dir.
VarLogCephDir = "/var/log/ceph"
// chownUserGroup represents ceph:ceph
chownUserGroup = CephUser + ":" + CephGroup
// ContainerPostStartCmd is the command we run before starting any Ceph daemon
// It makes sure Ceph directories are owned by 'ceph'
ContainerPostStartCmd = []string{"chown", "--recursive", "--verbose", chownUserGroup, VarLogCephDir}
)
// Config is a Ceph config struct containing zero or more Ceph config sections.
+1
View File
@@ -117,6 +117,7 @@ func (c *Cluster) makeMdsDaemonContainer(mdsConfig *mdsConfig) v1.Container {
opspec.DaemonEnvVars(c.cephVersion.Image),
),
Resources: c.fs.Spec.MetadataServer.Resources,
Lifecycle: opspec.PodLifeCycle(""),
}
return container
+1 -1
View File
@@ -102,7 +102,6 @@ func (c *clusterConfig) makeRGWPodSpec(rgwConfig *rgwConfig) v1.PodTemplateSpec
}
func (c *clusterConfig) makeDaemonContainer(rgwConfig *rgwConfig) v1.Container {
// start the rgw daemon in the foreground
container := v1.Container{
Name: "rgw",
@@ -134,6 +133,7 @@ func (c *clusterConfig) makeDaemonContainer(rgwConfig *rgwConfig) v1.Container {
},
InitialDelaySeconds: 10,
},
Lifecycle: opspec.PodLifeCycle(""),
}
if c.store.Spec.Gateway.SSLCertificateRef != "" {
+23
View File
@@ -212,3 +212,26 @@ func StoredLogVolumeMount() v1.VolumeMount {
MountPath: config.VarLogCephDir,
}
}
func generateLifeCycleCmd(dataDirHostPath string) []string {
cmd := config.ContainerPostStartCmd
if dataDirHostPath != "" {
cmd = append(cmd, dataDirHostPath)
}
return cmd
}
// PodLifeCycle returns a pod lifecycle resource to execute actions before a pod starts
func PodLifeCycle(dataDirHostPath string) *v1.Lifecycle {
cmd := generateLifeCycleCmd(dataDirHostPath)
return &v1.Lifecycle{
PostStart: &v1.Handler{
Exec: &v1.ExecAction{
Command: cmd,
},
},
}
}
+10
View File
@@ -19,8 +19,10 @@ package spec
import (
"testing"
"github.com/rook/rook/pkg/operator/ceph/config"
"github.com/rook/rook/pkg/operator/k8sutil"
"github.com/rook/rook/pkg/operator/test"
"github.com/stretchr/testify/assert"
)
func TestPodVolumes(t *testing.T) {
@@ -42,3 +44,11 @@ func TestMountsMatchVolumes(t *testing.T) {
}
volsMountsTestDef.TestMountsMatchVolumes(t)
}
func TestGenerateLifeCycleCmd(t *testing.T) {
cmd := generateLifeCycleCmd("")
assert.Equal(t, config.ContainerPostStartCmd, cmd)
cmd = generateLifeCycleCmd("foo")
assert.Equal(t, append(config.ContainerPostStartCmd, "foo"), cmd)
}