2018-11-28 08:29:37 -07:00
|
|
|
/*
|
|
|
|
|
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 (
|
2020-03-24 18:44:43 +01:00
|
|
|
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
|
2019-03-08 13:15:43 -07:00
|
|
|
"github.com/rook/rook/pkg/operator/ceph/config"
|
2020-02-25 18:07:01 +01:00
|
|
|
"github.com/rook/rook/pkg/operator/ceph/controller"
|
2018-11-28 08:29:37 -07:00
|
|
|
"github.com/rook/rook/pkg/operator/k8sutil"
|
2019-02-04 19:35:45 +00:00
|
|
|
apps "k8s.io/api/apps/v1"
|
2019-01-24 14:58:46 +01:00
|
|
|
v1 "k8s.io/api/core/v1"
|
2018-11-28 08:29:37 -07:00
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
|
)
|
|
|
|
|
|
2020-07-24 00:26:37 +05:30
|
|
|
func (r *ReconcileCephRBDMirror) makeDeployment(daemonConfig *daemonConfig, rbdMirror *cephv1.CephRBDMirror) (*apps.Deployment, error) {
|
2018-11-28 08:29:37 -07:00
|
|
|
podSpec := v1.PodTemplateSpec{
|
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2019-03-08 13:15:43 -07:00
|
|
|
Name: daemonConfig.ResourceName,
|
2021-12-06 12:52:11 +05:30
|
|
|
Labels: controller.CephDaemonAppLabels(AppName, rbdMirror.Namespace, config.RbdMirrorType, daemonConfig.DaemonID, rbdMirror.Name, "cephrbdmirrors.ceph.rook.io", true),
|
2018-11-28 08:29:37 -07:00
|
|
|
},
|
|
|
|
|
Spec: v1.PodSpec{
|
2019-10-10 14:55:43 -06:00
|
|
|
InitContainers: []v1.Container{
|
2020-03-24 18:44:43 +01:00
|
|
|
r.makeChownInitContainer(daemonConfig, rbdMirror),
|
2019-10-10 14:55:43 -06:00
|
|
|
},
|
2018-11-28 08:29:37 -07:00
|
|
|
Containers: []v1.Container{
|
2020-03-24 18:44:43 +01:00
|
|
|
r.makeMirroringDaemonContainer(daemonConfig, rbdMirror),
|
2018-11-28 08:29:37 -07:00
|
|
|
},
|
2023-12-14 18:30:11 +05:30
|
|
|
RestartPolicy: v1.RestartPolicyAlways,
|
|
|
|
|
Volumes: controller.DaemonVolumes(daemonConfig.DataPathMap, daemonConfig.ResourceName, r.cephClusterSpec.DataDirHostPath),
|
|
|
|
|
HostNetwork: r.cephClusterSpec.Network.IsHost(),
|
|
|
|
|
PriorityClassName: rbdMirror.Spec.PriorityClassName,
|
|
|
|
|
ServiceAccountName: k8sutil.DefaultServiceAccount,
|
2018-11-28 08:29:37 -07:00
|
|
|
},
|
|
|
|
|
}
|
2020-11-19 17:58:18 +01:00
|
|
|
|
|
|
|
|
// If the log collector is enabled we add the side-car container
|
|
|
|
|
if r.cephClusterSpec.LogCollector.Enabled {
|
|
|
|
|
shareProcessNamespace := true
|
|
|
|
|
podSpec.Spec.ShareProcessNamespace = &shareProcessNamespace
|
2022-08-29 11:26:05 -06:00
|
|
|
|
|
|
|
|
// The rbd mirror daemon logs to multiple logs, so we need a more generous log rotation filter for files:
|
|
|
|
|
// ceph-client.rbd-mirror.a.log
|
|
|
|
|
// <CLUSTER_FSID>-client.rbd-mirror-peer.log
|
|
|
|
|
logRotationFilter := "*-client.rbd-mirror*"
|
|
|
|
|
podSpec.Spec.Containers = append(podSpec.Spec.Containers, *controller.LogCollectorContainer(logRotationFilter, r.clusterInfo.Namespace, *r.cephClusterSpec))
|
2020-11-19 17:58:18 +01:00
|
|
|
}
|
|
|
|
|
|
2019-11-19 12:10:24 +01:00
|
|
|
// Replace default unreachable node toleration
|
|
|
|
|
k8sutil.AddUnreachableNodeToleration(&podSpec.Spec)
|
2020-08-14 14:29:02 +02:00
|
|
|
rbdMirror.Spec.Annotations.ApplyToObjectMeta(&podSpec.ObjectMeta)
|
|
|
|
|
rbdMirror.Spec.Labels.ApplyToObjectMeta(&podSpec.ObjectMeta)
|
2019-11-19 12:10:24 +01:00
|
|
|
|
2020-03-24 18:44:43 +01:00
|
|
|
if r.cephClusterSpec.Network.IsHost() {
|
2018-11-28 08:29:37 -07:00
|
|
|
podSpec.Spec.DNSPolicy = v1.DNSClusterFirstWithHostNet
|
2020-03-24 18:44:43 +01:00
|
|
|
} else if r.cephClusterSpec.Network.IsMultus() {
|
2023-08-22 13:15:08 -06:00
|
|
|
if err := k8sutil.ApplyMultus(r.clusterInfo.Namespace, &r.cephClusterSpec.Network, &podSpec.ObjectMeta); err != nil {
|
2020-07-24 00:26:37 +05:30
|
|
|
return nil, err
|
|
|
|
|
}
|
2018-11-28 08:29:37 -07:00
|
|
|
}
|
2021-03-16 12:05:08 +05:30
|
|
|
rbdMirror.Spec.Placement.ApplyToPodSpec(&podSpec.Spec)
|
2018-11-28 08:29:37 -07:00
|
|
|
|
2021-02-08 18:33:32 +01:00
|
|
|
replicas := int32(rbdMirror.Spec.Count)
|
2019-02-04 19:35:45 +00:00
|
|
|
d := &apps.Deployment{
|
2018-11-28 08:29:37 -07:00
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2019-03-05 11:21:57 +01:00
|
|
|
Name: daemonConfig.ResourceName,
|
2020-03-24 18:44:43 +01:00
|
|
|
Namespace: rbdMirror.Namespace,
|
|
|
|
|
Annotations: rbdMirror.Spec.Annotations,
|
2021-12-06 12:52:11 +05:30
|
|
|
Labels: controller.CephDaemonAppLabels(AppName, rbdMirror.Namespace, config.RbdMirrorType, daemonConfig.DaemonID, rbdMirror.Name, "cephrbdmirrors.ceph.rook.io", true),
|
2018-11-28 08:29:37 -07:00
|
|
|
},
|
2019-02-04 19:35:45 +00:00
|
|
|
Spec: apps.DeploymentSpec{
|
|
|
|
|
Selector: &metav1.LabelSelector{
|
|
|
|
|
MatchLabels: podSpec.Labels,
|
|
|
|
|
},
|
|
|
|
|
Template: podSpec,
|
|
|
|
|
Replicas: &replicas,
|
|
|
|
|
},
|
2018-11-28 08:29:37 -07:00
|
|
|
}
|
2019-04-11 17:21:16 -06:00
|
|
|
k8sutil.AddRookVersionLabelToDeployment(d)
|
2020-03-24 18:44:43 +01:00
|
|
|
controller.AddCephVersionLabelToDeployment(r.clusterInfo.CephVersion, d)
|
2020-08-14 14:29:02 +02:00
|
|
|
rbdMirror.Spec.Annotations.ApplyToObjectMeta(&d.ObjectMeta)
|
|
|
|
|
rbdMirror.Spec.Labels.ApplyToObjectMeta(&d.ObjectMeta)
|
2020-03-24 18:44:43 +01:00
|
|
|
|
2020-07-24 00:26:37 +05:30
|
|
|
return d, nil
|
2018-11-28 08:29:37 -07:00
|
|
|
}
|
|
|
|
|
|
2020-03-24 18:44:43 +01:00
|
|
|
func (r *ReconcileCephRBDMirror) makeChownInitContainer(daemonConfig *daemonConfig, rbdMirror *cephv1.CephRBDMirror) v1.Container {
|
2020-02-25 18:07:01 +01:00
|
|
|
return controller.ChownCephDataDirsInitContainer(
|
2019-10-10 14:55:43 -06:00
|
|
|
*daemonConfig.DataPathMap,
|
2020-03-24 18:44:43 +01:00
|
|
|
r.cephClusterSpec.CephVersion.Image,
|
2022-09-13 16:02:03 +05:30
|
|
|
controller.GetContainerImagePullPolicy(r.cephClusterSpec.CephVersion.ImagePullPolicy),
|
2023-01-09 15:47:51 +05:30
|
|
|
controller.DaemonVolumeMounts(daemonConfig.DataPathMap, daemonConfig.ResourceName, r.cephClusterSpec.DataDirHostPath),
|
2020-03-24 18:44:43 +01:00
|
|
|
rbdMirror.Spec.Resources,
|
2020-11-19 17:58:18 +01:00
|
|
|
controller.PodSecurityContext(),
|
2023-01-09 15:47:51 +05:30
|
|
|
"",
|
2019-10-10 14:55:43 -06:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-24 18:44:43 +01:00
|
|
|
func (r *ReconcileCephRBDMirror) makeMirroringDaemonContainer(daemonConfig *daemonConfig, rbdMirror *cephv1.CephRBDMirror) v1.Container {
|
2018-11-28 08:29:37 -07:00
|
|
|
container := v1.Container{
|
2019-03-08 13:15:43 -07:00
|
|
|
Name: "rbd-mirror",
|
2018-11-28 08:29:37 -07:00
|
|
|
Command: []string{
|
|
|
|
|
"rbd-mirror",
|
|
|
|
|
},
|
2019-03-08 13:15:43 -07:00
|
|
|
Args: append(
|
2020-09-18 10:17:23 +05:30
|
|
|
controller.DaemonFlags(r.clusterInfo, r.cephClusterSpec, daemonConfig.DaemonID),
|
2018-11-28 08:29:37 -07:00
|
|
|
"--foreground",
|
2019-03-08 13:15:43 -07:00
|
|
|
"--name="+fullDaemonName(daemonConfig.DaemonID),
|
|
|
|
|
),
|
2020-03-24 18:44:43 +01:00
|
|
|
Image: r.cephClusterSpec.CephVersion.Image,
|
2022-09-13 16:02:03 +05:30
|
|
|
ImagePullPolicy: controller.GetContainerImagePullPolicy(r.cephClusterSpec.CephVersion.ImagePullPolicy),
|
2023-01-09 15:47:51 +05:30
|
|
|
VolumeMounts: controller.DaemonVolumeMounts(daemonConfig.DataPathMap, daemonConfig.ResourceName, r.cephClusterSpec.DataDirHostPath),
|
2023-08-25 19:58:46 +05:30
|
|
|
Env: controller.DaemonEnvVars(r.cephClusterSpec),
|
2020-03-24 18:44:43 +01:00
|
|
|
Resources: rbdMirror.Spec.Resources,
|
2020-11-19 17:58:18 +01:00
|
|
|
SecurityContext: controller.PodSecurityContext(),
|
2021-01-13 17:25:25 +01:00
|
|
|
WorkingDir: config.VarLogCephDir,
|
2020-03-31 15:15:44 +02:00
|
|
|
// TODO:
|
|
|
|
|
// Not implemented at this point since the socket name is '/run/ceph/ceph-client.rbd-mirror.a.1.94362516231272.asok'
|
|
|
|
|
// Also the command to run will be:
|
|
|
|
|
// ceph --admin-daemon /run/ceph/ceph-client.rbd-mirror.a.1.94362516231272.asok rbd mirror status
|
2020-03-31 19:09:39 +02:00
|
|
|
// LivenessProbe: controller.GenerateLivenessProbeExecDaemon(config.RbdMirrorType, daemonConfig.DaemonID),
|
2018-11-28 08:29:37 -07:00
|
|
|
}
|
2020-08-25 09:46:18 +02:00
|
|
|
|
2018-11-28 08:29:37 -07:00
|
|
|
return container
|
|
|
|
|
}
|