-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
spec.go
162 lines (142 loc) · 5.55 KB
/
spec.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
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 mds
import (
"fmt"
"github.com/pkg/errors"
"github.com/rook/rook/pkg/clusterd"
"github.com/rook/rook/pkg/operator/ceph/cluster/mon"
"github.com/rook/rook/pkg/operator/ceph/config"
"github.com/rook/rook/pkg/operator/ceph/controller"
"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"
)
const (
mdsDaemonCommand = "ceph-mds"
// MDS cache memory limit should be set to 50-60% of RAM reserved for the MDS container
// MDS uses approximately 125% of the value of mds_cache_memory_limit in RAM.
// Eventually we will tune this automatically: http://tracker.ceph.com/issues/36663
mdsCacheMemoryLimitFactor = 0.5
)
func (c *Cluster) makeDeployment(mdsConfig *mdsConfig) (*apps.Deployment, error) {
podSpec := v1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Name: mdsConfig.ResourceName,
Labels: c.podLabels(mdsConfig, true),
},
Spec: v1.PodSpec{
InitContainers: []v1.Container{
c.makeChownInitContainer(mdsConfig),
},
Containers: []v1.Container{
c.makeMdsDaemonContainer(mdsConfig),
},
RestartPolicy: v1.RestartPolicyAlways,
Volumes: controller.DaemonVolumes(mdsConfig.DataPathMap, mdsConfig.ResourceName),
HostNetwork: c.clusterSpec.Network.IsHost(),
PriorityClassName: c.fs.Spec.MetadataServer.PriorityClassName,
},
}
// Replace default unreachable node toleration
k8sutil.AddUnreachableNodeToleration(&podSpec.Spec)
c.fs.Spec.MetadataServer.Annotations.ApplyToObjectMeta(&podSpec.ObjectMeta)
c.fs.Spec.MetadataServer.Labels.ApplyToObjectMeta(&podSpec.ObjectMeta)
c.fs.Spec.MetadataServer.Placement.ApplyToPodSpec(&podSpec.Spec)
replicas := int32(1)
d := &apps.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: mdsConfig.ResourceName,
Namespace: c.fs.Namespace,
Labels: c.podLabels(mdsConfig, true),
},
Spec: apps.DeploymentSpec{
Selector: &metav1.LabelSelector{
MatchLabels: c.podLabels(mdsConfig, false),
},
Template: podSpec,
Replicas: &replicas,
Strategy: apps.DeploymentStrategy{
Type: apps.RecreateDeploymentStrategyType,
},
},
}
if c.clusterSpec.Network.IsHost() {
d.Spec.Template.Spec.DNSPolicy = v1.DNSClusterFirstWithHostNet
} else if c.clusterSpec.Network.NetworkSpec.IsMultus() {
if err := k8sutil.ApplyMultus(c.clusterSpec.Network.NetworkSpec, &podSpec.ObjectMeta); err != nil {
return nil, err
}
}
k8sutil.AddRookVersionLabelToDeployment(d)
c.fs.Spec.MetadataServer.Annotations.ApplyToObjectMeta(&d.ObjectMeta)
c.fs.Spec.MetadataServer.Labels.ApplyToObjectMeta(&d.ObjectMeta)
controller.AddCephVersionLabelToDeployment(c.clusterInfo.CephVersion, d)
return d, nil
}
func (c *Cluster) makeChownInitContainer(mdsConfig *mdsConfig) v1.Container {
return controller.ChownCephDataDirsInitContainer(
*mdsConfig.DataPathMap,
c.clusterSpec.CephVersion.Image,
controller.DaemonVolumeMounts(mdsConfig.DataPathMap, mdsConfig.ResourceName),
c.fs.Spec.MetadataServer.Resources,
mon.PodSecurityContext(),
)
}
func (c *Cluster) makeMdsDaemonContainer(mdsConfig *mdsConfig) v1.Container {
args := append(
controller.DaemonFlags(c.clusterInfo, mdsConfig.DaemonID),
"--foreground",
)
container := v1.Container{
Name: "mds",
Command: []string{
"ceph-mds",
},
Args: args,
Image: c.clusterSpec.CephVersion.Image,
VolumeMounts: controller.DaemonVolumeMounts(mdsConfig.DataPathMap, mdsConfig.ResourceName),
Env: append(
controller.DaemonEnvVars(c.clusterSpec.CephVersion.Image),
),
Resources: c.fs.Spec.MetadataServer.Resources,
SecurityContext: mon.PodSecurityContext(),
LivenessProbe: controller.GenerateLivenessProbeExecDaemon(config.MdsType, mdsConfig.DaemonID),
}
return container
}
func (c *Cluster) podLabels(mdsConfig *mdsConfig, includeNewLabels bool) map[string]string {
labels := controller.CephDaemonAppLabels(AppName, c.fs.Namespace, "mds", mdsConfig.DaemonID, includeNewLabels)
labels["rook_file_system"] = c.fs.Name
return labels
}
func getMdsDeployments(context *clusterd.Context, namespace, fsName string) (*apps.DeploymentList, error) {
fsLabelSelector := fmt.Sprintf("rook_file_system=%s", fsName)
deps, err := k8sutil.GetDeployments(context.Clientset, namespace, fsLabelSelector)
if err != nil {
return nil, errors.Wrapf(err, "could not get deployments for filesystem %s (matching label selector %q)", fsName, fsLabelSelector)
}
return deps, nil
}
func deleteMdsDeployment(context *clusterd.Context, namespace string, deployment *apps.Deployment) error {
// Delete the mds deployment
logger.Infof("deleting mds deployment %s", deployment.Name)
var gracePeriod int64
propagation := metav1.DeletePropagationForeground
options := &metav1.DeleteOptions{GracePeriodSeconds: &gracePeriod, PropagationPolicy: &propagation}
if err := context.Clientset.AppsV1().Deployments(namespace).Delete(deployment.GetName(), options); err != nil {
return errors.Wrapf(err, "failed to delete mds deployment %s", deployment.GetName())
}
return nil
}