-
Notifications
You must be signed in to change notification settings - Fork 22
/
desired.go
52 lines (45 loc) · 1.28 KB
/
desired.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
package service
import (
"context"
"github.com/giantswarm/microerror"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"github.com/giantswarm/aws-operator/v14/pkg/label"
"github.com/giantswarm/aws-operator/v14/service/controller/key"
)
const (
AnnotationEtcdDomain = "giantswarm.io/etcd-domain"
AnnotationPrometheusCluster = "giantswarm.io/prometheus-cluster"
)
func (r *Resource) GetDesiredState(ctx context.Context, obj interface{}) (interface{}, error) {
cr, err := key.ToCluster(ctx, obj)
if err != nil {
return nil, microerror.Mask(err)
}
service := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: "master",
Namespace: key.ClusterID(&cr),
Labels: map[string]string{
label.App: "master",
label.Cluster: key.ClusterID(&cr),
label.Organization: key.OrganizationID(&cr),
},
Annotations: map[string]string{
AnnotationEtcdDomain: key.ClusterEtcdEndpointWithPort(cr),
AnnotationPrometheusCluster: key.ClusterID(&cr),
},
},
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{
{
Protocol: corev1.ProtocolTCP,
Port: httpsPort,
TargetPort: intstr.FromInt(httpsPort),
},
},
},
}
return service, nil
}