Files
my-rook-config/pkg/operator/ceph/cluster/rbd/spec.go
T
Blaine Gardner db7a6da09e ceph: do ceph:ceph chown in init containers
Following the Ceph OSD rework, my test environment regularly failed to
start OSDs, as they would start before the postStart lifecyle hook which
was chown'ing the log and data directories could finish. Pods failed to
start for an arbitrarily long time before starting successfully. This
was a manifestation of a race condition identified in Ceph monitors in
https://github.com/rook/rook/pull/3594#discussion_r312279176

Create a Ceph operator-level method to create an init container that
will chown the necessary directories for all Ceph daemons (any daemon
which runs as the ceph:ceph user-and-group). Also add this container to
expectations for Ceph pod templates in unit tests.

Signed-off-by: Blaine Gardner <blaine.gardner@suse.com>
2019-10-15 12:12:46 -06:00

103 lines
3.2 KiB
Go

/*
Copyright 2016 The Rook Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package rbd
import (
"github.com/rook/rook/pkg/operator/ceph/cluster/mon"
"github.com/rook/rook/pkg/operator/ceph/config"
opspec "github.com/rook/rook/pkg/operator/ceph/spec"
"github.com/rook/rook/pkg/operator/k8sutil"
apps "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func (m *Mirroring) makeDeployment(daemonConfig *daemonConfig) *apps.Deployment {
podSpec := v1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Name: daemonConfig.ResourceName,
Labels: opspec.PodLabels(appName, m.Namespace, string(config.RbdMirrorType), daemonConfig.DaemonID),
},
Spec: v1.PodSpec{
InitContainers: []v1.Container{
m.makeChownInitContainer(daemonConfig),
},
Containers: []v1.Container{
m.makeMirroringDaemonContainer(daemonConfig),
},
RestartPolicy: v1.RestartPolicyAlways,
Volumes: opspec.DaemonVolumes(daemonConfig.DataPathMap, daemonConfig.ResourceName),
HostNetwork: m.Network.IsHost(),
},
}
if m.Network.IsHost() {
podSpec.Spec.DNSPolicy = v1.DNSClusterFirstWithHostNet
}
m.placement.ApplyToPodSpec(&podSpec.Spec)
replicas := int32(1)
d := &apps.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: daemonConfig.ResourceName,
Namespace: m.Namespace,
Annotations: m.annotations,
Labels: opspec.PodLabels(appName, m.Namespace, string(config.RbdMirrorType), daemonConfig.DaemonID),
},
Spec: apps.DeploymentSpec{
Selector: &metav1.LabelSelector{
MatchLabels: podSpec.Labels,
},
Template: podSpec,
Replicas: &replicas,
},
}
k8sutil.AddRookVersionLabelToDeployment(d)
opspec.AddCephVersionLabelToDeployment(m.ClusterInfo.CephVersion, d)
k8sutil.SetOwnerRef(&d.ObjectMeta, &m.ownerRef)
return d
}
func (m *Mirroring) makeChownInitContainer(daemonConfig *daemonConfig) v1.Container {
return opspec.ChownCephDataDirsInitContainer(
*daemonConfig.DataPathMap,
m.cephVersion.Image,
opspec.DaemonVolumeMounts(daemonConfig.DataPathMap, daemonConfig.ResourceName),
m.resources,
mon.PodSecurityContext(),
)
}
func (m *Mirroring) makeMirroringDaemonContainer(daemonConfig *daemonConfig) v1.Container {
container := v1.Container{
Name: "rbd-mirror",
Command: []string{
"rbd-mirror",
},
Args: append(
opspec.DaemonFlags(m.ClusterInfo, daemonConfig.DaemonID),
"--foreground",
"--name="+fullDaemonName(daemonConfig.DaemonID),
),
Image: m.cephVersion.Image,
VolumeMounts: opspec.DaemonVolumeMounts(daemonConfig.DataPathMap, daemonConfig.ResourceName),
Env: opspec.DaemonEnvVars(m.cephVersion.Image),
Resources: m.resources,
SecurityContext: mon.PodSecurityContext(),
}
return container
}