-
Notifications
You must be signed in to change notification settings - Fork 109
/
virtualservice.go
87 lines (74 loc) · 2.16 KB
/
virtualservice.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
package manifest
import (
"fmt"
appmesh "github.com/aws/aws-app-mesh-controller-for-k8s/apis/appmesh/v1beta2"
"github.com/aws/aws-sdk-go/aws"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
type VSBuilder struct {
Namespace string
}
func (b *VSBuilder) BuildVirtualServiceWithRouterBackend(instanceName string, vrName string) *appmesh.VirtualService {
vsName := b.buildServiceName(instanceName)
vsDNS := fmt.Sprintf("%s.%s.svc.cluster.local", vsName, b.Namespace)
vs := &appmesh.VirtualService{
ObjectMeta: metav1.ObjectMeta{
Namespace: b.Namespace,
Name: vsName,
},
Spec: appmesh.VirtualServiceSpec{
AWSName: aws.String(vsDNS),
Provider: &appmesh.VirtualServiceProvider{
VirtualRouter: &appmesh.VirtualRouterServiceProvider{
VirtualRouterRef: &appmesh.VirtualRouterReference{
Namespace: aws.String(b.Namespace),
Name: vrName,
},
},
},
},
}
return vs
}
func (b *VSBuilder) BuildVirtualServiceWithNodeBackend(instanceName string, vnName string) *appmesh.VirtualService {
vsName := b.buildServiceName(instanceName)
vsDNS := fmt.Sprintf("%s.%s.svc.cluster.local", vsName, b.Namespace)
vs := &appmesh.VirtualService{
ObjectMeta: metav1.ObjectMeta{
Namespace: b.Namespace,
Name: vsName,
},
Spec: appmesh.VirtualServiceSpec{
AWSName: aws.String(vsDNS),
Provider: &appmesh.VirtualServiceProvider{
VirtualNode: &appmesh.VirtualNodeServiceProvider{
VirtualNodeRef: &appmesh.VirtualNodeReference{
Namespace: aws.String(b.Namespace),
Name: vnName,
},
},
},
},
}
return vs
}
func (b *VSBuilder) BuildVirtualServiceNoBackend(instanceName string) *appmesh.VirtualService {
vsName := b.buildServiceName(instanceName)
vsDNS := fmt.Sprintf("%s.%s.svc.cluster.local", vsName, b.Namespace)
vs := &appmesh.VirtualService{
ObjectMeta: metav1.ObjectMeta{
Namespace: b.Namespace,
Name: vsName,
},
Spec: appmesh.VirtualServiceSpec{
AWSName: aws.String(vsDNS),
},
}
return vs
}
func (b *VSBuilder) buildName(instanceName string) string {
return instanceName
}
func (b *VSBuilder) buildServiceName(instanceName string) string {
return instanceName
}