add ingress for volume servers
fix https://github.com/seaweedfs/seaweedfs-operator/issues/16
This commit is contained in:
parent
e853e2870f
commit
2573216733
|
@ -98,6 +98,9 @@ type SeaweedSpec struct {
|
||||||
StatefulSetUpdateStrategy appsv1.StatefulSetUpdateStrategyType `json:"statefulSetUpdateStrategy,omitempty"`
|
StatefulSetUpdateStrategy appsv1.StatefulSetUpdateStrategyType `json:"statefulSetUpdateStrategy,omitempty"`
|
||||||
|
|
||||||
VolumeServerDiskCount int32 `json:"volumeServerDiskCount,omitempty"`
|
VolumeServerDiskCount int32 `json:"volumeServerDiskCount,omitempty"`
|
||||||
|
|
||||||
|
// Ingresses
|
||||||
|
HostSuffix *string `json:"hostSuffix,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// SeaweedStatus defines the observed state of Seaweed
|
// SeaweedStatus defines the observed state of Seaweed
|
||||||
|
@ -150,9 +153,6 @@ type VolumeSpec struct {
|
||||||
IdleTimeout *int32 `json:"idleTimeout,omitempty"`
|
IdleTimeout *int32 `json:"idleTimeout,omitempty"`
|
||||||
MaxVolumeCounts *int32 `json:"maxVolumeCounts,omitempty"`
|
MaxVolumeCounts *int32 `json:"maxVolumeCounts,omitempty"`
|
||||||
MinFreeSpacePercent *int32 `json:"minFreeSpacePercent,omitempty"`
|
MinFreeSpacePercent *int32 `json:"minFreeSpacePercent,omitempty"`
|
||||||
|
|
||||||
// Ingresses
|
|
||||||
HostSuffix *string `json:"hostSuffix,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FilerSpec is the spec for filers
|
// FilerSpec is the spec for filers
|
||||||
|
@ -171,9 +171,6 @@ type FilerSpec struct {
|
||||||
// Filer-specific settings
|
// Filer-specific settings
|
||||||
|
|
||||||
MaxMB *int32 `json:"maxMB,omitempty"`
|
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
|
// 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
|
||||||
|
|
|
@ -128,11 +128,6 @@ func (in *FilerSpec) DeepCopyInto(out *FilerSpec) {
|
||||||
*out = new(int32)
|
*out = new(int32)
|
||||||
**out = **in
|
**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.
|
// 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])
|
(*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.
|
// 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 = new(int32)
|
||||||
**out = **in
|
**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.
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new VolumeSpec.
|
||||||
|
|
|
@ -1343,9 +1343,6 @@ spec:
|
||||||
description: Whether Hostnetwork of the component is enabled. Override
|
description: Whether Hostnetwork of the component is enabled. Override
|
||||||
the cluster-level setting if present
|
the cluster-level setting if present
|
||||||
type: boolean
|
type: boolean
|
||||||
hostSuffix:
|
|
||||||
description: Ingresses
|
|
||||||
type: string
|
|
||||||
imagePullPolicy:
|
imagePullPolicy:
|
||||||
description: ImagePullPolicy of the component. Override the cluster-level
|
description: ImagePullPolicy of the component. Override the cluster-level
|
||||||
imagePullPolicy if present
|
imagePullPolicy if present
|
||||||
|
@ -1495,6 +1492,9 @@ spec:
|
||||||
hostNetwork:
|
hostNetwork:
|
||||||
description: Whether Hostnetwork is enabled for pods
|
description: Whether Hostnetwork is enabled for pods
|
||||||
type: boolean
|
type: boolean
|
||||||
|
hostSuffix:
|
||||||
|
description: Ingresses
|
||||||
|
type: string
|
||||||
image:
|
image:
|
||||||
description: Image
|
description: Image
|
||||||
type: string
|
type: string
|
||||||
|
@ -3191,9 +3191,6 @@ spec:
|
||||||
description: Whether Hostnetwork of the component is enabled. Override
|
description: Whether Hostnetwork of the component is enabled. Override
|
||||||
the cluster-level setting if present
|
the cluster-level setting if present
|
||||||
type: boolean
|
type: boolean
|
||||||
hostSuffix:
|
|
||||||
description: Ingresses
|
|
||||||
type: string
|
|
||||||
idleTimeout:
|
idleTimeout:
|
||||||
format: int32
|
format: int32
|
||||||
type: integer
|
type: integer
|
||||||
|
|
|
@ -7,6 +7,7 @@ spec:
|
||||||
# Add fields here
|
# Add fields here
|
||||||
image: chrislusf/seaweedfs:2.09
|
image: chrislusf/seaweedfs:2.09
|
||||||
volumeServerDiskCount: 1
|
volumeServerDiskCount: 1
|
||||||
|
hostSuffix: seaweed.abcdefg.com
|
||||||
master:
|
master:
|
||||||
replicas: 3
|
replicas: 3
|
||||||
volumeSizeLimitMB: 1024
|
volumeSizeLimitMB: 1024
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
|
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/util/intstr"
|
"k8s.io/apimachinery/pkg/util/intstr"
|
||||||
|
@ -9,7 +11,7 @@ import (
|
||||||
seaweedv1 "github.com/seaweedfs/seaweedfs-operator/api/v1"
|
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)
|
labels := labelsForIngress(m.Name)
|
||||||
|
|
||||||
dep := &extensionsv1beta1.Ingress{
|
dep := &extensionsv1beta1.Ingress{
|
||||||
|
@ -22,7 +24,7 @@ func (r *SeaweedReconciler) createFilerIngress(m *seaweedv1.Seaweed) *extensions
|
||||||
// TLS: ingressSpec.TLS,
|
// TLS: ingressSpec.TLS,
|
||||||
Rules: []extensionsv1beta1.IngressRule{
|
Rules: []extensionsv1beta1.IngressRule{
|
||||||
{
|
{
|
||||||
Host: "filer." + *m.Spec.Filer.HostSuffix,
|
Host: "filer." + *m.Spec.HostSuffix,
|
||||||
IngressRuleValue: extensionsv1beta1.IngressRuleValue{
|
IngressRuleValue: extensionsv1beta1.IngressRuleValue{
|
||||||
HTTP: &extensionsv1beta1.HTTPIngressRuleValue{
|
HTTP: &extensionsv1beta1.HTTPIngressRuleValue{
|
||||||
Paths: []extensionsv1beta1.HTTPIngressPath{
|
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{
|
IngressRuleValue: extensionsv1beta1.IngressRuleValue{
|
||||||
HTTP: &extensionsv1beta1.HTTPIngressRuleValue{
|
HTTP: &extensionsv1beta1.HTTPIngressRuleValue{
|
||||||
Paths: []extensionsv1beta1.HTTPIngressPath{
|
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
|
// Set master instance as the owner and controller
|
||||||
ctrl.SetControllerReference(m, dep, r.Scheme)
|
ctrl.SetControllerReference(m, dep, r.Scheme)
|
||||||
return dep
|
return dep
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
|
|
||||||
"github.com/seaweedfs/seaweedfs-operator/controllers/label"
|
"github.com/seaweedfs/seaweedfs-operator/controllers/label"
|
||||||
ctrl "sigs.k8s.io/controller-runtime"
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
|
"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) {
|
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 seaweedCR.Spec.HostSuffix != nil && len(*seaweedCR.Spec.HostSuffix) != 0 {
|
||||||
if done, result, err = r.ensureFilerIngress(seaweedCR); done {
|
if done, result, err = r.ensureAllIngress(seaweedCR); done {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,16 +19,16 @@ func (r *SeaweedReconciler) ensureSeaweedIngress(seaweedCR *seaweedv1.Seaweed) (
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *SeaweedReconciler) ensureFilerIngress(seaweedCR *seaweedv1.Seaweed) (bool, ctrl.Result, error) {
|
func (r *SeaweedReconciler) ensureAllIngress(seaweedCR *seaweedv1.Seaweed) (bool, ctrl.Result, error) {
|
||||||
log := r.Log.WithValues("sw-master-service", seaweedCR.Name)
|
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 {
|
if err := controllerutil.SetControllerReference(seaweedCR, ingressService, r.Scheme); err != nil {
|
||||||
return ReconcileResult(err)
|
return ReconcileResult(err)
|
||||||
}
|
}
|
||||||
_, err := r.CreateOrUpdateIngress(ingressService)
|
_, err := r.CreateOrUpdateIngress(ingressService)
|
||||||
|
|
||||||
log.Info("Get master service " + ingressService.Name)
|
log.Info("ensure ingress " + ingressService.Name)
|
||||||
return ReconcileResult(err)
|
return ReconcileResult(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,9 @@ func buildVolumeServerStartupScript(m *seaweedv1.Seaweed, dirs []string) string
|
||||||
commands = append(commands, fmt.Sprintf("-port=%d", seaweedv1.VolumeHTTPPort))
|
commands = append(commands, fmt.Sprintf("-port=%d", seaweedv1.VolumeHTTPPort))
|
||||||
commands = append(commands, "-max=0")
|
commands = append(commands, "-max=0")
|
||||||
commands = append(commands, fmt.Sprintf("-ip=$(POD_NAME).%s-volume-peer", m.Name))
|
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("-mserver=%s", getMasterPeersString(m)))
|
||||||
commands = append(commands, fmt.Sprintf("-dir=%s", strings.Join(dirs, ",")))
|
commands = append(commands, fmt.Sprintf("-dir=%s", strings.Join(dirs, ",")))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue