-
Notifications
You must be signed in to change notification settings - Fork 459
/
Copy pathservice.go
190 lines (171 loc) · 5.82 KB
/
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// Copyright (C) 2020, MinIO, Inc.
//
// This code is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License, version 3,
// as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License, version 3,
// along with this program. If not, see <http://www.gnu.org/licenses/>
package services
import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
miniov2 "github.com/minio/operator/pkg/apis/minio.min.io/v2"
)
// NewClusterIPForMinIO will return a new ClusterIP Kubernetes service for a Tenant
func NewClusterIPForMinIO(t *miniov2.Tenant) *corev1.Service {
var port int32 = miniov2.MinIOPortLoadBalancerSVC
name := miniov2.MinIOServiceHTTPPortName
if t.TLS() {
port = miniov2.MinIOTLSPortLoadBalancerSVC
name = miniov2.MinIOServiceHTTPSPortName
}
minioPort := corev1.ServicePort{
Port: port,
Name: name,
TargetPort: intstr.FromInt(miniov2.MinIOPort),
}
svc := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: t.MinIOCIServiceName(),
Namespace: t.Namespace,
OwnerReferences: t.OwnerRef(),
},
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{minioPort},
Selector: t.MinIOPodLabels(),
Type: corev1.ServiceTypeClusterIP,
PublishNotReadyAddresses: false,
},
}
if t.Spec.ServiceMetadata != nil {
svc.Labels = t.Spec.ServiceMetadata.MinIOServiceLabels
svc.Annotations = t.Spec.ServiceMetadata.MinIOServiceAnnotations
}
// check if the service is meant to be exposed
if t.Spec.ExposeServices != nil && t.Spec.ExposeServices.MinIO {
svc.Spec.Type = corev1.ServiceTypeLoadBalancer
}
return svc
}
// NewClusterIPForConsole will return a new cluster IP service for Console Deployment
func NewClusterIPForConsole(t *miniov2.Tenant) *corev1.Service {
consolePort := corev1.ServicePort{
Port: miniov2.ConsolePort,
TargetPort: intstr.FromInt(miniov2.ConsolePort),
Name: miniov2.ConsoleServicePortName,
}
if t.TLS() {
consolePort = corev1.ServicePort{
Port: miniov2.ConsoleTLSPort,
TargetPort: intstr.FromInt(miniov2.ConsoleTLSPort),
Name: miniov2.ConsoleServiceTLSPortName,
}
}
svc := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: t.ConsoleCIServiceName(),
Namespace: t.Namespace,
OwnerReferences: t.OwnerRef(),
},
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{
consolePort,
},
Selector: t.MinIOPodLabels(),
Type: corev1.ServiceTypeClusterIP,
},
}
if t.Spec.ServiceMetadata != nil {
svc.Labels = t.Spec.ServiceMetadata.ConsoleServiceLabels
svc.Annotations = t.Spec.ServiceMetadata.ConsoleServiceAnnotations
}
// check if the service is meant to be exposed
if t.Spec.ExposeServices != nil && t.Spec.ExposeServices.Console {
svc.Spec.Type = corev1.ServiceTypeLoadBalancer
}
return svc
}
// ServiceForBucket will return a external name based service
func ServiceForBucket(t *miniov2.Tenant, bucket string) *corev1.Service {
var port int32 = miniov2.MinIOPortLoadBalancerSVC
name := miniov2.MinIOServiceHTTPPortName
if t.TLS() {
port = miniov2.MinIOTLSPortLoadBalancerSVC
name = miniov2.MinIOServiceHTTPSPortName
}
minioPort := corev1.ServicePort{
Port: port,
Name: name,
TargetPort: intstr.FromInt(miniov2.MinIOPort),
}
svc := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: bucket,
Namespace: t.Namespace,
OwnerReferences: t.OwnerRef(),
},
Spec: corev1.ServiceSpec{
ExternalName: t.MinIOFQDNServiceName(),
Ports: []corev1.ServicePort{minioPort},
Type: corev1.ServiceTypeExternalName,
},
}
return svc
}
// NewHeadlessForMinIO will return a new headless Kubernetes service for a Tenant
func NewHeadlessForMinIO(t *miniov2.Tenant) *corev1.Service {
name := miniov2.MinIOServiceHTTPPortName
if t.TLS() {
name = miniov2.MinIOServiceHTTPSPortName
}
minioPort := corev1.ServicePort{Port: miniov2.MinIOPort, Name: name}
ports := []corev1.ServicePort{minioPort}
if t.Spec.Features != nil && t.Spec.Features.EnableSFTP != nil && *t.Spec.Features.EnableSFTP {
minioSFTPPort := corev1.ServicePort{Port: miniov2.MinIOSFTPPort, Name: miniov2.MinIOServiceSFTPPortName}
ports = append(ports, minioSFTPPort)
}
svc := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: t.MinIOHLServiceName(),
Namespace: t.Namespace,
OwnerReferences: t.OwnerRef(),
},
Spec: corev1.ServiceSpec{
Ports: ports,
Selector: t.MinIOPodLabels(),
Type: corev1.ServiceTypeClusterIP,
ClusterIP: corev1.ClusterIPNone,
PublishNotReadyAddresses: true,
},
}
return svc
}
// NewHeadlessForKES will return a new headless Kubernetes service for a KES StatefulSet
func NewHeadlessForKES(t *miniov2.Tenant) *corev1.Service {
kesPort := corev1.ServicePort{Port: miniov2.KESPort, Name: miniov2.KESServicePortName}
svc := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: t.KESHLServiceName(),
Namespace: t.Namespace,
OwnerReferences: t.OwnerRef(),
},
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{kesPort},
Selector: t.KESPodLabels(),
Type: corev1.ServiceTypeClusterIP,
ClusterIP: corev1.ClusterIPNone,
},
}
if t.Spec.ServiceMetadata != nil {
svc.Labels = t.Spec.ServiceMetadata.KESServiceLabels
svc.Annotations = t.Spec.ServiceMetadata.KESServiceAnnotations
}
return svc
}