2020-11-04 22:30:15 +00:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
import (
|
2020-11-10 08:11:17 +00:00
|
|
|
"fmt"
|
|
|
|
|
2020-11-04 22:30:15 +00:00
|
|
|
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
"k8s.io/apimachinery/pkg/util/intstr"
|
|
|
|
ctrl "sigs.k8s.io/controller-runtime"
|
|
|
|
|
|
|
|
seaweedv1 "github.com/seaweedfs/seaweedfs-operator/api/v1"
|
|
|
|
)
|
|
|
|
|
2020-11-10 08:11:17 +00:00
|
|
|
func (r *SeaweedReconciler) createAllIngress(m *seaweedv1.Seaweed) *extensionsv1beta1.Ingress {
|
2020-11-04 22:30:15 +00:00
|
|
|
labels := labelsForIngress(m.Name)
|
|
|
|
|
|
|
|
dep := &extensionsv1beta1.Ingress{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: m.Name + "-ingress",
|
|
|
|
Namespace: m.Namespace,
|
|
|
|
Labels: labels,
|
|
|
|
},
|
|
|
|
Spec: extensionsv1beta1.IngressSpec{
|
|
|
|
// TLS: ingressSpec.TLS,
|
|
|
|
Rules: []extensionsv1beta1.IngressRule{
|
|
|
|
{
|
2020-11-10 08:11:17 +00:00
|
|
|
Host: "filer." + *m.Spec.HostSuffix,
|
2020-11-04 22:30:15 +00:00
|
|
|
IngressRuleValue: extensionsv1beta1.IngressRuleValue{
|
|
|
|
HTTP: &extensionsv1beta1.HTTPIngressRuleValue{
|
|
|
|
Paths: []extensionsv1beta1.HTTPIngressPath{
|
|
|
|
{
|
|
|
|
Path: "/",
|
|
|
|
Backend: extensionsv1beta1.IngressBackend{
|
|
|
|
ServiceName: m.Name + "-filer",
|
|
|
|
ServicePort: intstr.FromInt(seaweedv1.FilerHTTPPort),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-11-10 08:11:17 +00:00
|
|
|
Host: "s3." + *m.Spec.HostSuffix,
|
2020-11-04 22:30:15 +00:00
|
|
|
IngressRuleValue: extensionsv1beta1.IngressRuleValue{
|
|
|
|
HTTP: &extensionsv1beta1.HTTPIngressRuleValue{
|
|
|
|
Paths: []extensionsv1beta1.HTTPIngressPath{
|
|
|
|
{
|
|
|
|
Path: "/",
|
|
|
|
Backend: extensionsv1beta1.IngressBackend{
|
|
|
|
ServiceName: m.Name + "-s3",
|
|
|
|
ServicePort: intstr.FromInt(seaweedv1.FilerS3Port),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-11-10 08:11:17 +00:00
|
|
|
// 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),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-11-04 22:30:15 +00:00
|
|
|
// Set master instance as the owner and controller
|
|
|
|
ctrl.SetControllerReference(m, dep, r.Scheme)
|
|
|
|
return dep
|
|
|
|
}
|