/
controller_filer_service.go
130 lines (120 loc) · 3.43 KB
/
controller_filer_service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package controllers
import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
seaweedv1 "github.com/seaweedfs/seaweedfs-operator/api/v1"
)
func (r *SeaweedReconciler) createFilerPeerService(m *seaweedv1.Seaweed) *corev1.Service {
labels := labelsForFiler(m.Name)
ports := []corev1.ServicePort{
{
Name: "filer-http",
Protocol: corev1.Protocol("TCP"),
Port: seaweedv1.FilerHTTPPort,
TargetPort: intstr.FromInt(seaweedv1.FilerHTTPPort),
},
{
Name: "filer-grpc",
Protocol: corev1.Protocol("TCP"),
Port: seaweedv1.FilerGRPCPort,
TargetPort: intstr.FromInt(seaweedv1.FilerGRPCPort),
},
}
if m.Spec.Filer.S3 {
ports = append(ports, corev1.ServicePort{
Name: "filer-s3",
Protocol: corev1.Protocol("TCP"),
Port: seaweedv1.FilerS3Port,
TargetPort: intstr.FromInt(seaweedv1.FilerS3Port),
})
}
if m.Spec.Filer.MetricsPort != nil {
ports = append(ports, corev1.ServicePort{
Name: "filer-metrics",
Protocol: corev1.Protocol("TCP"),
Port: *m.Spec.Filer.MetricsPort,
TargetPort: intstr.FromInt(int(*m.Spec.Filer.MetricsPort)),
})
}
dep := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: m.Name + "-filer-peer",
Namespace: m.Namespace,
Labels: labels,
Annotations: map[string]string{
"service.alpha.kubernetes.io/tolerate-unready-endpoints": "true",
},
},
Spec: corev1.ServiceSpec{
ClusterIP: "None",
PublishNotReadyAddresses: true,
Ports: ports,
Selector: labels,
},
}
return dep
}
func (r *SeaweedReconciler) createFilerService(m *seaweedv1.Seaweed) *corev1.Service {
labels := labelsForFiler(m.Name)
ports := []corev1.ServicePort{
{
Name: "filer-http",
Protocol: corev1.Protocol("TCP"),
Port: seaweedv1.FilerHTTPPort,
TargetPort: intstr.FromInt(seaweedv1.FilerHTTPPort),
},
{
Name: "filer-grpc",
Protocol: corev1.Protocol("TCP"),
Port: seaweedv1.FilerGRPCPort,
TargetPort: intstr.FromInt(seaweedv1.FilerGRPCPort),
},
}
if m.Spec.Filer.S3 {
ports = append(ports, corev1.ServicePort{
Name: "filer-s3",
Protocol: corev1.Protocol("TCP"),
Port: seaweedv1.FilerS3Port,
TargetPort: intstr.FromInt(seaweedv1.FilerS3Port),
})
}
if m.Spec.Filer.MetricsPort != nil {
ports = append(ports, corev1.ServicePort{
Name: "filer-metrics",
Protocol: corev1.Protocol("TCP"),
Port: *m.Spec.Filer.MetricsPort,
TargetPort: intstr.FromInt(int(*m.Spec.Filer.MetricsPort)),
})
}
dep := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: m.Name + "-filer",
Namespace: m.Namespace,
Labels: labels,
Annotations: map[string]string{
"service.alpha.kubernetes.io/tolerate-unready-endpoints": "true",
},
},
Spec: corev1.ServiceSpec{
Type: corev1.ServiceTypeClusterIP,
PublishNotReadyAddresses: true,
Ports: ports,
Selector: labels,
},
}
if m.Spec.Filer.Service != nil {
svcSpec := m.Spec.Filer.Service
dep.Annotations = copyAnnotations(svcSpec.Annotations)
if svcSpec.Type != "" {
dep.Spec.Type = svcSpec.Type
}
if svcSpec.ClusterIP != nil {
dep.Spec.ClusterIP = *svcSpec.ClusterIP
}
if svcSpec.LoadBalancerIP != nil {
dep.Spec.LoadBalancerIP = *svcSpec.LoadBalancerIP
}
}
return dep
}