forked from goharbor/harbor-operator
/
services.go
36 lines (32 loc) · 1.07 KB
/
services.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
package exporter
import (
"context"
goharborv1 "github.com/plotly/harbor-operator/apis/goharbor.io/v1beta1"
harbormetav1 "github.com/plotly/harbor-operator/apis/meta/v1alpha1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)
func (r *Reconciler) GetService(ctx context.Context, exporter *goharborv1.Exporter) (*corev1.Service, error) {
name := r.NormalizeName(ctx, exporter.GetName())
namespace := exporter.GetNamespace()
return &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
Annotations: harbormetav1.AddPrometheusAnnotations(nil, exporter.Spec.Port, exporter.Spec.Path),
},
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{{
Name: harbormetav1.ExporterMetricsPortName,
Port: exporter.Spec.Port,
TargetPort: intstr.FromString(harbormetav1.ExporterMetricsPortName),
Protocol: corev1.ProtocolTCP,
}},
Selector: map[string]string{
r.Label("name"): name,
r.Label("namespace"): namespace,
},
},
}, nil
}