add ingress for volume servers

fix https://github.com/seaweedfs/seaweedfs-operator/issues/16
This commit is contained in:
Chris Lu 2020-11-10 00:11:17 -08:00
parent e853e2870f
commit 2573216733
7 changed files with 46 additions and 35 deletions

View File

@ -98,6 +98,9 @@ type SeaweedSpec struct {
StatefulSetUpdateStrategy appsv1.StatefulSetUpdateStrategyType `json:"statefulSetUpdateStrategy,omitempty"`
VolumeServerDiskCount int32 `json:"volumeServerDiskCount,omitempty"`
// Ingresses
HostSuffix *string `json:"hostSuffix,omitempty"`
}
// SeaweedStatus defines the observed state of Seaweed
@ -150,9 +153,6 @@ type VolumeSpec struct {
IdleTimeout *int32 `json:"idleTimeout,omitempty"`
MaxVolumeCounts *int32 `json:"maxVolumeCounts,omitempty"`
MinFreeSpacePercent *int32 `json:"minFreeSpacePercent,omitempty"`
// Ingresses
HostSuffix *string `json:"hostSuffix,omitempty"`
}
// FilerSpec is the spec for filers
@ -171,9 +171,6 @@ type FilerSpec struct {
// Filer-specific settings
MaxMB *int32 `json:"maxMB,omitempty"`
// Ingresses
HostSuffix *string `json:"hostSuffix,omitempty"`
}
// ComponentSpec is the base spec of each component, the fields should always accessed by the Basic<Component>Spec() method to respect the cluster-level properties

View File

@ -128,11 +128,6 @@ func (in *FilerSpec) DeepCopyInto(out *FilerSpec) {
*out = new(int32)
**out = **in
}
if in.HostSuffix != nil {
in, out := &in.HostSuffix, &out.HostSuffix
*out = new(string)
**out = **in
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FilerSpec.
@ -325,6 +320,11 @@ func (in *SeaweedSpec) DeepCopyInto(out *SeaweedSpec) {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
if in.HostSuffix != nil {
in, out := &in.HostSuffix, &out.HostSuffix
*out = new(string)
**out = **in
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SeaweedSpec.
@ -429,11 +429,6 @@ func (in *VolumeSpec) DeepCopyInto(out *VolumeSpec) {
*out = new(int32)
**out = **in
}
if in.HostSuffix != nil {
in, out := &in.HostSuffix, &out.HostSuffix
*out = new(string)
**out = **in
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new VolumeSpec.

View File

@ -1343,9 +1343,6 @@ spec:
description: Whether Hostnetwork of the component is enabled. Override
the cluster-level setting if present
type: boolean
hostSuffix:
description: Ingresses
type: string
imagePullPolicy:
description: ImagePullPolicy of the component. Override the cluster-level
imagePullPolicy if present
@ -1495,6 +1492,9 @@ spec:
hostNetwork:
description: Whether Hostnetwork is enabled for pods
type: boolean
hostSuffix:
description: Ingresses
type: string
image:
description: Image
type: string
@ -3191,9 +3191,6 @@ spec:
description: Whether Hostnetwork of the component is enabled. Override
the cluster-level setting if present
type: boolean
hostSuffix:
description: Ingresses
type: string
idleTimeout:
format: int32
type: integer

View File

@ -7,6 +7,7 @@ spec:
# Add fields here
image: chrislusf/seaweedfs:2.09
volumeServerDiskCount: 1
hostSuffix: seaweed.abcdefg.com
master:
replicas: 3
volumeSizeLimitMB: 1024

View File

@ -1,6 +1,8 @@
package controllers
import (
"fmt"
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
@ -9,7 +11,7 @@ import (
seaweedv1 "github.com/seaweedfs/seaweedfs-operator/api/v1"
)
func (r *SeaweedReconciler) createFilerIngress(m *seaweedv1.Seaweed) *extensionsv1beta1.Ingress {
func (r *SeaweedReconciler) createAllIngress(m *seaweedv1.Seaweed) *extensionsv1beta1.Ingress {
labels := labelsForIngress(m.Name)
dep := &extensionsv1beta1.Ingress{
@ -22,7 +24,7 @@ func (r *SeaweedReconciler) createFilerIngress(m *seaweedv1.Seaweed) *extensions
// TLS: ingressSpec.TLS,
Rules: []extensionsv1beta1.IngressRule{
{
Host: "filer." + *m.Spec.Filer.HostSuffix,
Host: "filer." + *m.Spec.HostSuffix,
IngressRuleValue: extensionsv1beta1.IngressRuleValue{
HTTP: &extensionsv1beta1.HTTPIngressRuleValue{
Paths: []extensionsv1beta1.HTTPIngressPath{
@ -38,7 +40,7 @@ func (r *SeaweedReconciler) createFilerIngress(m *seaweedv1.Seaweed) *extensions
},
},
{
Host: "s3." + *m.Spec.Filer.HostSuffix,
Host: "s3." + *m.Spec.HostSuffix,
IngressRuleValue: extensionsv1beta1.IngressRuleValue{
HTTP: &extensionsv1beta1.HTTPIngressRuleValue{
Paths: []extensionsv1beta1.HTTPIngressPath{
@ -57,6 +59,26 @@ func (r *SeaweedReconciler) createFilerIngress(m *seaweedv1.Seaweed) *extensions
},
}
// add ingress for volume servers
for i := 0; i < int(m.Spec.Volume.Replicas); i++ {
dep.Spec.Rules = append(dep.Spec.Rules, extensionsv1beta1.IngressRule{
Host: fmt.Sprintf("%s-volume-%d.%s", m.Name, i, *m.Spec.HostSuffix),
IngressRuleValue: extensionsv1beta1.IngressRuleValue{
HTTP: &extensionsv1beta1.HTTPIngressRuleValue{
Paths: []extensionsv1beta1.HTTPIngressPath{
{
Path: "/",
Backend: extensionsv1beta1.IngressBackend{
ServiceName: fmt.Sprintf("%s-volume-%d", m.Name, i),
ServicePort: intstr.FromInt(seaweedv1.VolumeHTTPPort),
},
},
},
},
},
})
}
// Set master instance as the owner and controller
ctrl.SetControllerReference(m, dep, r.Scheme)
return dep

View File

@ -1,8 +1,6 @@
package controllers
import (
"context"
"github.com/seaweedfs/seaweedfs-operator/controllers/label"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
@ -11,11 +9,9 @@ import (
)
func (r *SeaweedReconciler) ensureSeaweedIngress(seaweedCR *seaweedv1.Seaweed) (done bool, result ctrl.Result, err error) {
_ = context.Background()
_ = r.Log.WithValues("seaweed", seaweedCR.Name)
if seaweedCR.Spec.Filer.HostSuffix != nil && len(*seaweedCR.Spec.Filer.HostSuffix) != 0 {
if done, result, err = r.ensureFilerIngress(seaweedCR); done {
if seaweedCR.Spec.HostSuffix != nil && len(*seaweedCR.Spec.HostSuffix) != 0 {
if done, result, err = r.ensureAllIngress(seaweedCR); done {
return
}
}
@ -23,16 +19,16 @@ func (r *SeaweedReconciler) ensureSeaweedIngress(seaweedCR *seaweedv1.Seaweed) (
return
}
func (r *SeaweedReconciler) ensureFilerIngress(seaweedCR *seaweedv1.Seaweed) (bool, ctrl.Result, error) {
log := r.Log.WithValues("sw-master-service", seaweedCR.Name)
func (r *SeaweedReconciler) ensureAllIngress(seaweedCR *seaweedv1.Seaweed) (bool, ctrl.Result, error) {
log := r.Log.WithValues("sw-ingress", seaweedCR.Name)
ingressService := r.createFilerIngress(seaweedCR)
ingressService := r.createAllIngress(seaweedCR)
if err := controllerutil.SetControllerReference(seaweedCR, ingressService, r.Scheme); err != nil {
return ReconcileResult(err)
}
_, err := r.CreateOrUpdateIngress(ingressService)
log.Info("Get master service " + ingressService.Name)
log.Info("ensure ingress " + ingressService.Name)
return ReconcileResult(err)
}

View File

@ -17,6 +17,9 @@ func buildVolumeServerStartupScript(m *seaweedv1.Seaweed, dirs []string) string
commands = append(commands, fmt.Sprintf("-port=%d", seaweedv1.VolumeHTTPPort))
commands = append(commands, "-max=0")
commands = append(commands, fmt.Sprintf("-ip=$(POD_NAME).%s-volume-peer", m.Name))
if m.Spec.HostSuffix != nil && *m.Spec.HostSuffix != "" {
commands = append(commands, fmt.Sprintf("-publicUrl=$(POD_NAME).%s", *m.Spec.HostSuffix))
}
commands = append(commands, fmt.Sprintf("-mserver=%s", getMasterPeersString(m)))
commands = append(commands, fmt.Sprintf("-dir=%s", strings.Join(dirs, ",")))