Skip to content

Commit c0b60b1

Browse files
authored
Merge pull request #272 from weaveworks/appmesh
Set HTTP listeners for AppMesh virtual routers
2 parents 0463c19 + 0a418eb commit c0b60b1

File tree

6 files changed

+259
-6
lines changed

6 files changed

+259
-6
lines changed

pkg/apis/appmesh/v1beta1/types.go

+33-3
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,18 @@ type VirtualServiceSpec struct {
102102
Routes []Route `json:"routes,omitempty"`
103103
}
104104

105+
// VirtualRouter is the spec for a VirtualRouter resource
105106
type VirtualRouter struct {
106-
Name string `json:"name"`
107+
Name string `json:"name"`
108+
Listeners []Listener `json:"listeners,omitempty"`
107109
}
108110

109111
type Route struct {
110-
Name string `json:"name"`
111-
Http HttpRoute `json:"http"`
112+
Name string `json:"name"`
113+
// +optional
114+
Http *HttpRoute `json:"http,omitempty"`
115+
// +optional
116+
Tcp *TcpRoute `json:"tcp,omitempty"`
112117
}
113118

114119
type HttpRoute struct {
@@ -124,6 +129,14 @@ type HttpRouteAction struct {
124129
WeightedTargets []WeightedTarget `json:"weightedTargets"`
125130
}
126131

132+
type TcpRoute struct {
133+
Action TcpRouteAction `json:"action"`
134+
}
135+
136+
type TcpRouteAction struct {
137+
WeightedTargets []WeightedTarget `json:"weightedTargets"`
138+
}
139+
127140
type WeightedTarget struct {
128141
VirtualNodeName string `json:"virtualNodeName"`
129142
Weight int64 `json:"weight"`
@@ -203,6 +216,8 @@ type VirtualNodeSpec struct {
203216
ServiceDiscovery *ServiceDiscovery `json:"serviceDiscovery,omitempty"`
204217
// +optional
205218
Backends []Backend `json:"backends,omitempty"`
219+
// +optional
220+
Logging *Logging `json:"logging,omitempty"`
206221
}
207222

208223
type Listener struct {
@@ -237,6 +252,21 @@ type VirtualServiceBackend struct {
237252
VirtualServiceName string `json:"virtualServiceName"`
238253
}
239254

255+
// Logging refers to https://docs.aws.amazon.com/app-mesh/latest/APIReference/API_Logging.html
256+
type Logging struct {
257+
AccessLog *AccessLog `json:"accessLog"`
258+
}
259+
260+
// AccessLog refers to https://docs.aws.amazon.com/app-mesh/latest/APIReference/API_AccessLog.html
261+
type AccessLog struct {
262+
File *FileAccessLog `json:"file"`
263+
}
264+
265+
// FileAccessLog refers to https://docs.aws.amazon.com/app-mesh/latest/APIReference/API_FileAccessLog.html
266+
type FileAccessLog struct {
267+
Path string `json:"path"`
268+
}
269+
240270
// VirtualNodeStatus is the status for a VirtualNode resource
241271
type VirtualNodeStatus struct {
242272
MeshArn *string `json:"meshArn,omitempty"`

pkg/apis/appmesh/v1beta1/zz_generated.deepcopy.go

+117-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/notifier/client_test.go

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package notifier
2+
3+
import (
4+
"encoding/json"
5+
"io/ioutil"
6+
"net/http"
7+
"net/http/httptest"
8+
"testing"
9+
)
10+
11+
func Test_postMessage(t *testing.T) {
12+
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
13+
b, err := ioutil.ReadAll(r.Body)
14+
if err != nil {
15+
t.Fatal(err)
16+
}
17+
var payload = make(map[string]string)
18+
err = json.Unmarshal(b, &payload)
19+
20+
if payload["status"] != "success" {
21+
t.Fatal("wrong payload")
22+
}
23+
}))
24+
defer ts.Close()
25+
26+
err := postMessage(ts.URL, map[string]string{"status": "success"})
27+
if err != nil {
28+
t.Fatal(err)
29+
}
30+
}

pkg/notifier/slack_test.go

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package notifier
2+
3+
import (
4+
"encoding/json"
5+
"io/ioutil"
6+
"net/http"
7+
"net/http/httptest"
8+
"testing"
9+
)
10+
11+
func TestSlack_Post(t *testing.T) {
12+
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
13+
b, err := ioutil.ReadAll(r.Body)
14+
if err != nil {
15+
t.Fatal(err)
16+
}
17+
var payload = SlackPayload{}
18+
err = json.Unmarshal(b, &payload)
19+
20+
if payload.Attachments[0].AuthorName != "podinfo.test" {
21+
t.Fatal("wrong author name")
22+
}
23+
}))
24+
defer ts.Close()
25+
26+
slack, err := NewSlack(ts.URL, "test", "test")
27+
if err != nil {
28+
t.Fatal(err)
29+
}
30+
31+
err = slack.Post("podinfo", "test", "test", nil, true)
32+
if err != nil {
33+
t.Fatal(err)
34+
}
35+
}

pkg/notifier/teams_test.go

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package notifier
2+
3+
import (
4+
"encoding/json"
5+
"io/ioutil"
6+
"net/http"
7+
"net/http/httptest"
8+
"testing"
9+
)
10+
11+
func TestTeams_Post(t *testing.T) {
12+
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
13+
b, err := ioutil.ReadAll(r.Body)
14+
if err != nil {
15+
t.Fatal(err)
16+
}
17+
var payload = MSTeamsPayload{}
18+
err = json.Unmarshal(b, &payload)
19+
20+
if payload.Sections[0].ActivitySubtitle != "podinfo.test" {
21+
t.Fatal("wrong activity subtitle")
22+
}
23+
}))
24+
defer ts.Close()
25+
26+
teams, err := NewMSTeams(ts.URL)
27+
if err != nil {
28+
t.Fatal(err)
29+
}
30+
31+
err = teams.Post("podinfo", "test", "test", nil, true)
32+
if err != nil {
33+
t.Fatal(err)
34+
}
35+
}

pkg/router/appmesh.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,19 @@ func (ar *AppMeshRouter) reconcileVirtualService(canary *flaggerv1.Canary, name
165165
MeshName: canary.Spec.Service.MeshName,
166166
VirtualRouter: &AppmeshV1beta1.VirtualRouter{
167167
Name: fmt.Sprintf("%s-router", targetName),
168+
Listeners: []AppmeshV1beta1.Listener{
169+
{
170+
PortMapping: AppmeshV1beta1.PortMapping{
171+
Port: int64(canary.Spec.Service.Port),
172+
Protocol: "http",
173+
},
174+
},
175+
},
168176
},
169177
Routes: []AppmeshV1beta1.Route{
170178
{
171179
Name: fmt.Sprintf("%s-route", targetName),
172-
Http: AppmeshV1beta1.HttpRoute{
180+
Http: &AppmeshV1beta1.HttpRoute{
173181
Match: AppmeshV1beta1.HttpRouteMatch{
174182
Prefix: routePrefix,
175183
},

0 commit comments

Comments
 (0)