-
Notifications
You must be signed in to change notification settings - Fork 46
/
service.go
75 lines (62 loc) · 1.9 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
package lattice
import (
"github.com/aws/aws-application-networking-k8s/pkg/aws/services"
"github.com/aws/aws-application-networking-k8s/pkg/model/core"
"github.com/aws/aws-application-networking-k8s/pkg/utils"
)
type Service struct {
core.ResourceMeta `json:"-"`
Spec ServiceSpec `json:"spec"`
Status *ServiceStatus `json:"status,omitempty"`
IsDeleted bool `json:"isdeleted"`
}
type ServiceSpec struct {
ServiceTagFields
ServiceNetworkNames []string `json:"servicenetworkhnames"`
CustomerDomainName string `json:"customerdomainname"`
CustomerCertARN string `json:"customercertarn"`
}
type ServiceStatus struct {
Arn string `json:"arn"`
Id string `json:"id"`
Dns string `json:"dns"`
}
type ServiceTagFields struct {
RouteName string
RouteNamespace string
RouteType core.RouteType
}
func ServiceTagFieldsFromTags(tags map[string]*string) ServiceTagFields {
return ServiceTagFields{
RouteName: getMapValue(tags, K8SRouteNameKey),
RouteNamespace: getMapValue(tags, K8SRouteNamespaceKey),
RouteType: core.RouteType(getMapValue(tags, K8SRouteTypeKey)),
}
}
func (t *ServiceTagFields) ToTags() services.Tags {
rt := string(t.RouteType)
return services.Tags{
K8SRouteNameKey: &t.RouteName,
K8SRouteNamespaceKey: &t.RouteNamespace,
K8SRouteTypeKey: &rt,
}
}
func NewLatticeService(stack core.Stack, spec ServiceSpec) (*Service, error) {
id := spec.LatticeServiceName()
service := &Service{
ResourceMeta: core.NewResourceMeta(stack, "AWS::VPCServiceNetwork::Service", id),
Spec: spec,
Status: nil,
}
err := stack.AddResource(service)
if err != nil {
return nil, err
}
return service, nil
}
func (s *Service) LatticeServiceName() string {
return s.Spec.LatticeServiceName()
}
func (s *ServiceSpec) LatticeServiceName() string {
return utils.LatticeServiceName(s.RouteName, s.RouteNamespace)
}