2020-08-05 05:13:36 +00:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-10-20 07:17:14 +00:00
|
|
|
"strings"
|
2020-08-05 05:13:36 +00:00
|
|
|
|
|
|
|
appsv1 "k8s.io/api/apps/v1"
|
|
|
|
corev1 "k8s.io/api/core/v1"
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
2020-10-19 05:56:12 +00:00
|
|
|
"k8s.io/apimachinery/pkg/util/intstr"
|
2020-08-05 05:13:36 +00:00
|
|
|
|
|
|
|
seaweedv1 "github.com/seaweedfs/seaweedfs-operator/api/v1"
|
|
|
|
)
|
|
|
|
|
2020-10-29 08:57:16 +00:00
|
|
|
func buildVolumeServerStartupScript(m *seaweedv1.Seaweed, dirs []string) string {
|
2022-02-27 10:43:43 +00:00
|
|
|
commands := []string{"weed", "-logtostderr=true", "volume"}
|
2020-10-29 08:57:16 +00:00
|
|
|
commands = append(commands, fmt.Sprintf("-port=%d", seaweedv1.VolumeHTTPPort))
|
|
|
|
commands = append(commands, "-max=0")
|
2021-04-26 04:54:38 +00:00
|
|
|
commands = append(commands, fmt.Sprintf("-ip=$(POD_NAME).%s-volume-peer.%s", m.Name, m.Namespace))
|
2020-11-10 08:11:17 +00:00
|
|
|
if m.Spec.HostSuffix != nil && *m.Spec.HostSuffix != "" {
|
|
|
|
commands = append(commands, fmt.Sprintf("-publicUrl=$(POD_NAME).%s", *m.Spec.HostSuffix))
|
|
|
|
}
|
2020-11-09 00:12:31 +00:00
|
|
|
commands = append(commands, fmt.Sprintf("-mserver=%s", getMasterPeersString(m)))
|
2020-10-29 08:57:16 +00:00
|
|
|
commands = append(commands, fmt.Sprintf("-dir=%s", strings.Join(dirs, ",")))
|
|
|
|
|
|
|
|
return strings.Join(commands, " ")
|
|
|
|
}
|
|
|
|
|
2020-08-05 05:13:36 +00:00
|
|
|
func (r *SeaweedReconciler) createVolumeServerStatefulSet(m *seaweedv1.Seaweed) *appsv1.StatefulSet {
|
|
|
|
labels := labelsForVolumeServer(m.Name)
|
2020-10-28 05:06:25 +00:00
|
|
|
replicas := int32(m.Spec.Volume.Replicas)
|
2020-08-05 05:13:36 +00:00
|
|
|
rollingUpdatePartition := int32(0)
|
|
|
|
enableServiceLinks := false
|
|
|
|
|
2020-10-20 07:17:14 +00:00
|
|
|
volumeCount := int(m.Spec.VolumeServerDiskCount)
|
2020-10-28 05:06:25 +00:00
|
|
|
volumeRequests := corev1.ResourceList{
|
|
|
|
corev1.ResourceStorage: m.Spec.Volume.Requests[corev1.ResourceStorage],
|
2020-10-20 07:17:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// connect all the disks
|
|
|
|
var volumeMounts []corev1.VolumeMount
|
|
|
|
var volumes []corev1.Volume
|
|
|
|
var persistentVolumeClaims []corev1.PersistentVolumeClaim
|
|
|
|
var dirs []string
|
|
|
|
for i := 0; i < volumeCount; i++ {
|
|
|
|
volumeMounts = append(volumeMounts, corev1.VolumeMount{
|
|
|
|
Name: fmt.Sprintf("mount%d", i),
|
|
|
|
ReadOnly: false,
|
|
|
|
MountPath: fmt.Sprintf("/data%d/", i),
|
|
|
|
})
|
|
|
|
volumes = append(volumes, corev1.Volume{
|
|
|
|
Name: fmt.Sprintf("mount%d", i),
|
|
|
|
VolumeSource: corev1.VolumeSource{
|
|
|
|
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
|
|
|
|
ClaimName: fmt.Sprintf("mount%d", i),
|
|
|
|
ReadOnly: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
persistentVolumeClaims = append(persistentVolumeClaims, corev1.PersistentVolumeClaim{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: fmt.Sprintf("mount%d", i),
|
|
|
|
},
|
|
|
|
Spec: corev1.PersistentVolumeClaimSpec{
|
2020-10-30 06:42:00 +00:00
|
|
|
StorageClassName: m.Spec.Volume.StorageClassName,
|
2020-10-20 07:17:14 +00:00
|
|
|
AccessModes: []corev1.PersistentVolumeAccessMode{
|
|
|
|
corev1.ReadWriteOnce,
|
|
|
|
},
|
|
|
|
Resources: corev1.ResourceRequirements{
|
|
|
|
Requests: volumeRequests,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
dirs = append(dirs, fmt.Sprintf("/data%d", i))
|
|
|
|
}
|
|
|
|
|
2020-10-28 06:57:38 +00:00
|
|
|
volumePodSpec := m.BaseVolumeSpec().BuildPodSpec()
|
|
|
|
volumePodSpec.EnableServiceLinks = &enableServiceLinks
|
|
|
|
volumePodSpec.Containers = []corev1.Container{{
|
2020-10-30 06:57:02 +00:00
|
|
|
Name: "volume",
|
2020-10-28 06:57:38 +00:00
|
|
|
Image: m.Spec.Image,
|
|
|
|
ImagePullPolicy: m.BaseVolumeSpec().ImagePullPolicy(),
|
|
|
|
Env: append(m.BaseVolumeSpec().Env(), kubernetesEnvVars...),
|
|
|
|
Command: []string{
|
|
|
|
"/bin/sh",
|
|
|
|
"-ec",
|
2020-10-29 08:57:16 +00:00
|
|
|
buildVolumeServerStartupScript(m, dirs),
|
2020-10-28 06:57:38 +00:00
|
|
|
},
|
|
|
|
Ports: []corev1.ContainerPort{
|
|
|
|
{
|
2020-10-29 08:57:16 +00:00
|
|
|
ContainerPort: seaweedv1.VolumeHTTPPort,
|
2020-10-30 06:57:02 +00:00
|
|
|
Name: "volume-http",
|
2020-10-28 06:57:38 +00:00
|
|
|
},
|
|
|
|
{
|
2020-10-29 08:57:16 +00:00
|
|
|
ContainerPort: seaweedv1.VolumeGRPCPort,
|
2020-10-30 06:57:02 +00:00
|
|
|
Name: "volume-grpc",
|
2020-10-28 06:57:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
ReadinessProbe: &corev1.Probe{
|
|
|
|
Handler: corev1.Handler{
|
|
|
|
HTTPGet: &corev1.HTTPGetAction{
|
|
|
|
Path: "/status",
|
2020-10-29 08:57:16 +00:00
|
|
|
Port: intstr.FromInt(seaweedv1.VolumeHTTPPort),
|
2020-10-28 06:57:38 +00:00
|
|
|
Scheme: corev1.URISchemeHTTP,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
InitialDelaySeconds: 15,
|
|
|
|
TimeoutSeconds: 5,
|
|
|
|
PeriodSeconds: 90,
|
|
|
|
SuccessThreshold: 1,
|
|
|
|
FailureThreshold: 100,
|
|
|
|
},
|
|
|
|
LivenessProbe: &corev1.Probe{
|
|
|
|
Handler: corev1.Handler{
|
|
|
|
HTTPGet: &corev1.HTTPGetAction{
|
|
|
|
Path: "/status",
|
2020-10-29 08:57:16 +00:00
|
|
|
Port: intstr.FromInt(seaweedv1.VolumeHTTPPort),
|
2020-10-28 06:57:38 +00:00
|
|
|
Scheme: corev1.URISchemeHTTP,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
InitialDelaySeconds: 20,
|
|
|
|
TimeoutSeconds: 5,
|
|
|
|
PeriodSeconds: 90,
|
|
|
|
SuccessThreshold: 1,
|
|
|
|
FailureThreshold: 6,
|
|
|
|
},
|
|
|
|
VolumeMounts: volumeMounts,
|
|
|
|
}}
|
|
|
|
volumePodSpec.Volumes = volumes
|
|
|
|
|
2020-08-05 05:13:36 +00:00
|
|
|
dep := &appsv1.StatefulSet{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: m.Name + "-volume",
|
|
|
|
Namespace: m.Namespace,
|
|
|
|
},
|
|
|
|
Spec: appsv1.StatefulSetSpec{
|
2020-10-29 08:57:16 +00:00
|
|
|
ServiceName: m.Name + "-volume-peer",
|
2020-08-05 05:13:36 +00:00
|
|
|
PodManagementPolicy: appsv1.ParallelPodManagement,
|
|
|
|
Replicas: &replicas,
|
|
|
|
UpdateStrategy: appsv1.StatefulSetUpdateStrategy{
|
|
|
|
Type: appsv1.RollingUpdateStatefulSetStrategyType,
|
|
|
|
RollingUpdate: &appsv1.RollingUpdateStatefulSetStrategy{
|
|
|
|
Partition: &rollingUpdatePartition,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Selector: &metav1.LabelSelector{
|
|
|
|
MatchLabels: labels,
|
|
|
|
},
|
|
|
|
Template: corev1.PodTemplateSpec{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Labels: labels,
|
|
|
|
},
|
2020-10-28 06:57:38 +00:00
|
|
|
Spec: volumePodSpec,
|
2020-08-05 05:13:36 +00:00
|
|
|
},
|
2020-10-20 07:17:14 +00:00
|
|
|
VolumeClaimTemplates: persistentVolumeClaims,
|
2020-08-05 05:13:36 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
return dep
|
|
|
|
}
|