Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set HTTP listeners for AppMesh virtual routers #272

Merged
merged 3 commits into from
Aug 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions pkg/apis/appmesh/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,18 @@ type VirtualServiceSpec struct {
Routes []Route `json:"routes,omitempty"`
}

// VirtualRouter is the spec for a VirtualRouter resource
type VirtualRouter struct {
Name string `json:"name"`
Name string `json:"name"`
Listeners []Listener `json:"listeners,omitempty"`
}

type Route struct {
Name string `json:"name"`
Http HttpRoute `json:"http"`
Name string `json:"name"`
// +optional
Http *HttpRoute `json:"http,omitempty"`
// +optional
Tcp *TcpRoute `json:"tcp,omitempty"`
}

type HttpRoute struct {
Expand All @@ -124,6 +129,14 @@ type HttpRouteAction struct {
WeightedTargets []WeightedTarget `json:"weightedTargets"`
}

type TcpRoute struct {
Action TcpRouteAction `json:"action"`
}

type TcpRouteAction struct {
WeightedTargets []WeightedTarget `json:"weightedTargets"`
}

type WeightedTarget struct {
VirtualNodeName string `json:"virtualNodeName"`
Weight int64 `json:"weight"`
Expand Down Expand Up @@ -203,6 +216,8 @@ type VirtualNodeSpec struct {
ServiceDiscovery *ServiceDiscovery `json:"serviceDiscovery,omitempty"`
// +optional
Backends []Backend `json:"backends,omitempty"`
// +optional
Logging *Logging `json:"logging,omitempty"`
}

type Listener struct {
Expand Down Expand Up @@ -237,6 +252,21 @@ type VirtualServiceBackend struct {
VirtualServiceName string `json:"virtualServiceName"`
}

// Logging refers to https://docs.aws.amazon.com/app-mesh/latest/APIReference/API_Logging.html
type Logging struct {
AccessLog *AccessLog `json:"accessLog"`
}

// AccessLog refers to https://docs.aws.amazon.com/app-mesh/latest/APIReference/API_AccessLog.html
type AccessLog struct {
File *FileAccessLog `json:"file"`
}

// FileAccessLog refers to https://docs.aws.amazon.com/app-mesh/latest/APIReference/API_FileAccessLog.html
type FileAccessLog struct {
Path string `json:"path"`
}

// VirtualNodeStatus is the status for a VirtualNode resource
type VirtualNodeStatus struct {
MeshArn *string `json:"meshArn,omitempty"`
Expand Down
119 changes: 117 additions & 2 deletions pkg/apis/appmesh/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions pkg/notifier/client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package notifier

import (
"encoding/json"
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
)

func Test_postMessage(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
b, err := ioutil.ReadAll(r.Body)
if err != nil {
t.Fatal(err)
}
var payload = make(map[string]string)
err = json.Unmarshal(b, &payload)

if payload["status"] != "success" {
t.Fatal("wrong payload")
}
}))
defer ts.Close()

err := postMessage(ts.URL, map[string]string{"status": "success"})
if err != nil {
t.Fatal(err)
}
}
35 changes: 35 additions & 0 deletions pkg/notifier/slack_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package notifier

import (
"encoding/json"
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
)

func TestSlack_Post(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
b, err := ioutil.ReadAll(r.Body)
if err != nil {
t.Fatal(err)
}
var payload = SlackPayload{}
err = json.Unmarshal(b, &payload)

if payload.Attachments[0].AuthorName != "podinfo.test" {
t.Fatal("wrong author name")
}
}))
defer ts.Close()

slack, err := NewSlack(ts.URL, "test", "test")
if err != nil {
t.Fatal(err)
}

err = slack.Post("podinfo", "test", "test", nil, true)
if err != nil {
t.Fatal(err)
}
}
35 changes: 35 additions & 0 deletions pkg/notifier/teams_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package notifier

import (
"encoding/json"
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
)

func TestTeams_Post(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
b, err := ioutil.ReadAll(r.Body)
if err != nil {
t.Fatal(err)
}
var payload = MSTeamsPayload{}
err = json.Unmarshal(b, &payload)

if payload.Sections[0].ActivitySubtitle != "podinfo.test" {
t.Fatal("wrong activity subtitle")
}
}))
defer ts.Close()

teams, err := NewMSTeams(ts.URL)
if err != nil {
t.Fatal(err)
}

err = teams.Post("podinfo", "test", "test", nil, true)
if err != nil {
t.Fatal(err)
}
}
10 changes: 9 additions & 1 deletion pkg/router/appmesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,19 @@ func (ar *AppMeshRouter) reconcileVirtualService(canary *flaggerv1.Canary, name
MeshName: canary.Spec.Service.MeshName,
VirtualRouter: &AppmeshV1beta1.VirtualRouter{
Name: fmt.Sprintf("%s-router", targetName),
Listeners: []AppmeshV1beta1.Listener{
{
PortMapping: AppmeshV1beta1.PortMapping{
Port: int64(canary.Spec.Service.Port),
Protocol: "http",
},
},
},
},
Routes: []AppmeshV1beta1.Route{
{
Name: fmt.Sprintf("%s-route", targetName),
Http: AppmeshV1beta1.HttpRoute{
Http: &AppmeshV1beta1.HttpRoute{
Match: AppmeshV1beta1.HttpRouteMatch{
Prefix: routePrefix,
},
Expand Down