/
service.go
46 lines (40 loc) · 956 Bytes
/
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
package tink
import (
"context"
corev1 "k8s.io/api/core/v1"
kerrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
ctrlruntimeclient "sigs.k8s.io/controller-runtime/pkg/client"
)
func CreateService(ctx context.Context, client ctrlruntimeclient.Client, ns string) error {
service := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: "tink-server",
Namespace: ns,
Labels: map[string]string{
"app": "tink-server",
},
},
Spec: corev1.ServiceSpec{
ClusterIP: "None",
Selector: map[string]string{
"app": "tink-server",
},
Ports: []corev1.ServicePort{
{
Port: 42113,
TargetPort: intstr.IntOrString{IntVal: 42113},
Protocol: corev1.ProtocolTCP,
},
},
},
}
if err := client.Create(ctx, service); err != nil {
if kerrors.IsAlreadyExists(err) {
return nil
}
return err
}
return nil
}