2020-08-06 04:11:40 +00:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-10-29 08:57:16 +00:00
|
|
|
"strings"
|
2020-08-06 04:11:40 +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-06 04:11:40 +00:00
|
|
|
|
|
|
|
seaweedv1 "github.com/seaweedfs/seaweedfs-operator/api/v1"
|
|
|
|
)
|
|
|
|
|
2020-10-29 08:57:16 +00:00
|
|
|
func buildFilerStartupScript(m *seaweedv1.Seaweed) string {
|
|
|
|
commands := []string{"weed", "filer"}
|
|
|
|
commands = append(commands, fmt.Sprintf("-port=%d", seaweedv1.FilerHTTPPort))
|
|
|
|
commands = append(commands, fmt.Sprintf("-ip=$(POD_NAME).%s-filer-peer", m.Name))
|
2020-10-30 09:15:16 +00:00
|
|
|
commands = append(commands, fmt.Sprintf("-peers=%s", getFilerPeersString(m.Name, m.Spec.Volume.Replicas)))
|
2020-10-29 08:57:16 +00:00
|
|
|
commands = append(commands, fmt.Sprintf("-master=%s", getMasterPeersString(m.Name, m.Spec.Master.Replicas)))
|
|
|
|
commands = append(commands, "-s3")
|
|
|
|
|
|
|
|
return strings.Join(commands, " ")
|
|
|
|
}
|
|
|
|
|
2020-08-06 04:11:40 +00:00
|
|
|
func (r *SeaweedReconciler) createFilerStatefulSet(m *seaweedv1.Seaweed) *appsv1.StatefulSet {
|
|
|
|
labels := labelsForFiler(m.Name)
|
2020-10-28 05:06:25 +00:00
|
|
|
replicas := int32(m.Spec.Filer.Replicas)
|
2020-08-06 04:11:40 +00:00
|
|
|
rollingUpdatePartition := int32(0)
|
|
|
|
enableServiceLinks := false
|
|
|
|
|
2020-10-28 06:57:38 +00:00
|
|
|
filerPodSpec := m.BaseFilerSpec().BuildPodSpec()
|
2020-10-28 11:19:17 +00:00
|
|
|
filerPodSpec.Volumes = []corev1.Volume{
|
|
|
|
{
|
|
|
|
Name: "filer-config",
|
|
|
|
VolumeSource: corev1.VolumeSource{
|
|
|
|
ConfigMap: &corev1.ConfigMapVolumeSource{
|
|
|
|
LocalObjectReference: corev1.LocalObjectReference{
|
|
|
|
Name: m.Name + "-filer",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2020-10-28 06:57:38 +00:00
|
|
|
filerPodSpec.EnableServiceLinks = &enableServiceLinks
|
|
|
|
filerPodSpec.Containers = []corev1.Container{{
|
2020-10-30 06:57:02 +00:00
|
|
|
Name: "filer",
|
2020-10-28 06:57:38 +00:00
|
|
|
Image: m.Spec.Image,
|
2020-10-29 09:03:30 +00:00
|
|
|
ImagePullPolicy: m.BaseFilerSpec().ImagePullPolicy(),
|
|
|
|
Env: append(m.BaseFilerSpec().Env(), kubernetesEnvVars...),
|
2020-10-28 06:57:38 +00:00
|
|
|
Command: []string{
|
|
|
|
"/bin/sh",
|
|
|
|
"-ec",
|
2020-10-29 08:57:16 +00:00
|
|
|
buildFilerStartupScript(m),
|
2020-10-28 06:57:38 +00:00
|
|
|
},
|
|
|
|
Ports: []corev1.ContainerPort{
|
|
|
|
{
|
|
|
|
ContainerPort: seaweedv1.FilerHTTPPort,
|
2020-10-30 06:57:02 +00:00
|
|
|
Name: "filer-http",
|
2020-10-28 06:57:38 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ContainerPort: seaweedv1.FilerGRPCPort,
|
2020-10-30 06:57:02 +00:00
|
|
|
Name: "filer-grpc",
|
2020-10-28 06:57:38 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ContainerPort: seaweedv1.FilerS3Port,
|
2020-10-30 06:57:02 +00:00
|
|
|
Name: "filer-s3",
|
2020-10-28 06:57:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
ReadinessProbe: &corev1.Probe{
|
|
|
|
Handler: corev1.Handler{
|
|
|
|
HTTPGet: &corev1.HTTPGetAction{
|
|
|
|
Path: "/",
|
|
|
|
Port: intstr.FromInt(seaweedv1.FilerHTTPPort),
|
|
|
|
Scheme: corev1.URISchemeHTTP,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
InitialDelaySeconds: 10,
|
|
|
|
TimeoutSeconds: 3,
|
|
|
|
PeriodSeconds: 15,
|
|
|
|
SuccessThreshold: 1,
|
|
|
|
FailureThreshold: 100,
|
|
|
|
},
|
|
|
|
LivenessProbe: &corev1.Probe{
|
|
|
|
Handler: corev1.Handler{
|
|
|
|
HTTPGet: &corev1.HTTPGetAction{
|
|
|
|
Path: "/",
|
|
|
|
Port: intstr.FromInt(seaweedv1.FilerHTTPPort),
|
|
|
|
Scheme: corev1.URISchemeHTTP,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
InitialDelaySeconds: 20,
|
|
|
|
TimeoutSeconds: 3,
|
|
|
|
PeriodSeconds: 30,
|
|
|
|
SuccessThreshold: 1,
|
|
|
|
FailureThreshold: 6,
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
|
2020-08-06 04:11:40 +00:00
|
|
|
dep := &appsv1.StatefulSet{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: m.Name + "-filer",
|
|
|
|
Namespace: m.Namespace,
|
|
|
|
},
|
|
|
|
Spec: appsv1.StatefulSetSpec{
|
2020-10-29 08:57:16 +00:00
|
|
|
ServiceName: m.Name + "-filer-peer",
|
2020-08-06 04:11:40 +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: filerPodSpec,
|
2020-08-06 04:11:40 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return dep
|
|
|
|
}
|