diff --git a/api/v1/seaweed_types.go b/api/v1/seaweed_types.go index 4581623..0e1780c 100644 --- a/api/v1/seaweed_types.go +++ b/api/v1/seaweed_types.go @@ -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 BasicSpec() method to respect the cluster-level properties diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index 0428b28..394b373 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -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. diff --git a/config/crd/bases/seaweed.seaweedfs.com_seaweeds.yaml b/config/crd/bases/seaweed.seaweedfs.com_seaweeds.yaml index e40ac82..7d96595 100644 --- a/config/crd/bases/seaweed.seaweedfs.com_seaweeds.yaml +++ b/config/crd/bases/seaweed.seaweedfs.com_seaweeds.yaml @@ -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 diff --git a/config/samples/seaweed_v1_seaweed.yaml b/config/samples/seaweed_v1_seaweed.yaml index 869db23..82d7882 100644 --- a/config/samples/seaweed_v1_seaweed.yaml +++ b/config/samples/seaweed_v1_seaweed.yaml @@ -7,6 +7,7 @@ spec: # Add fields here image: chrislusf/seaweedfs:2.09 volumeServerDiskCount: 1 + hostSuffix: seaweed.abcdefg.com master: replicas: 3 volumeSizeLimitMB: 1024 diff --git a/controllers/controller_filer_ingress.go b/controllers/controller_filer_ingress.go index 8fcc52b..f574334 100644 --- a/controllers/controller_filer_ingress.go +++ b/controllers/controller_filer_ingress.go @@ -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 diff --git a/controllers/controller_ingress.go b/controllers/controller_ingress.go index 33bc6ce..f36b6d8 100644 --- a/controllers/controller_ingress.go +++ b/controllers/controller_ingress.go @@ -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) } diff --git a/controllers/controller_volume_statefulset.go b/controllers/controller_volume_statefulset.go index 3da9b53..816d78d 100644 --- a/controllers/controller_volume_statefulset.go +++ b/controllers/controller_volume_statefulset.go @@ -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, ",")))