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

AppMesh: Add annotation to enable Envoy access logs #1156

Merged
merged 1 commit into from
Mar 22, 2022
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
3 changes: 3 additions & 0 deletions docs/gitbook/tutorials/appmesh-progressive-delivery.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ Create a canary definition:
apiVersion: flagger.app/v1beta1
kind: Canary
metadata:
annotations:
# Enable Envoy access logging to stdout.
appmesh.flagger.app/accesslog: enabled
name: podinfo
namespace: test
spec:
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/appmesh/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ package appmesh
const (
GroupName = "appmesh.k8s.aws"
)

const AccessLogAnnotation = "appmesh.flagger.app/accesslog"

const EnabledValue = "enabled"
13 changes: 13 additions & 0 deletions pkg/router/appmesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/kubernetes"

appmesh "github.com/fluxcd/flagger/pkg/apis/appmesh"
appmeshv1 "github.com/fluxcd/flagger/pkg/apis/appmesh/v1beta1"
flaggerv1 "github.com/fluxcd/flagger/pkg/apis/flagger/v1beta1"
clientset "github.com/fluxcd/flagger/pkg/client/clientset/versioned"
Expand Down Expand Up @@ -114,6 +115,18 @@ func (ar *AppMeshRouter) reconcileVirtualNode(canary *flaggerv1.Canary, name str
},
}

//get annotation to enable the access log
val, _ := canary.ObjectMeta.GetAnnotations()[appmesh.AccessLogAnnotation]
if val == appmesh.EnabledValue {
vnSpec.Logging = &appmeshv1.Logging{
AccessLog: &appmeshv1.AccessLog{
File: &appmeshv1.FileAccessLog{
Path: "/dev/stdout",
},
},
}
}

backends := make([]appmeshv1.Backend, len(canary.Spec.Service.Backends))
for i, b := range canary.Spec.Service.Backends {
backends[i] = appmeshv1.Backend{
Expand Down
1 change: 1 addition & 0 deletions pkg/router/appmesh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func TestAppmeshRouter_Reconcile(t *testing.T) {
vnName := mocks.appmeshCanary.Spec.TargetRef.Name
vn, err := router.appmeshClient.AppmeshV1beta1().VirtualNodes("default").Get(context.TODO(), vnName, metav1.GetOptions{})
require.NoError(t, err)
require.NotNil(t, vn.Spec.Logging)

primaryDNS := fmt.Sprintf("%s-primary.%s", mocks.appmeshCanary.Spec.TargetRef.Name, mocks.appmeshCanary.Namespace)
assert.Equal(t, primaryDNS, vn.Spec.ServiceDiscovery.Dns.HostName)
Expand Down
13 changes: 13 additions & 0 deletions pkg/router/appmesh_v1beta2.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/kubernetes"

appmesh "github.com/fluxcd/flagger/pkg/apis/appmesh"
appmeshv1 "github.com/fluxcd/flagger/pkg/apis/appmesh/v1beta2"
flaggerv1 "github.com/fluxcd/flagger/pkg/apis/flagger/v1beta1"
clientset "github.com/fluxcd/flagger/pkg/client/clientset/versioned"
Expand Down Expand Up @@ -118,6 +119,18 @@ func (ar *AppMeshv1beta2Router) reconcileVirtualNode(canary *flaggerv1.Canary, n
},
}

//get annotation to enable the access log
val, _ := canary.ObjectMeta.GetAnnotations()[appmesh.AccessLogAnnotation]
if val == appmesh.EnabledValue {
vnSpec.Logging = &appmeshv1.Logging{
AccessLog: &appmeshv1.AccessLog{
File: &appmeshv1.FileAccessLog{
Path: "/dev/stdout",
},
},
}
}

backends := make([]appmeshv1.Backend, 0)
for i := range canary.Spec.Service.Backends {
if strings.HasPrefix(canary.Spec.Service.Backends[i], "arn:aws") {
Expand Down
1 change: 1 addition & 0 deletions pkg/router/appmesh_v1beta2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func TestAppmeshv1beta2Router_Reconcile(t *testing.T) {
// check primary virtual node
vnPrimary, err := router.appmeshClient.AppmeshV1beta2().VirtualNodes("default").Get(context.TODO(), primaryName, metav1.GetOptions{})
require.NoError(t, err)
require.NotNil(t, vnPrimary.Spec.Logging)

// check FQDN
primaryDNS := fmt.Sprintf("%s.%s.svc.cluster.local.", primaryName, mocks.appmeshCanary.Namespace)
Expand Down
4 changes: 4 additions & 0 deletions pkg/router/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/fake"

appmesh "github.com/fluxcd/flagger/pkg/apis/appmesh"
flaggerv1 "github.com/fluxcd/flagger/pkg/apis/flagger/v1beta1"
"github.com/fluxcd/flagger/pkg/apis/gatewayapi/v1alpha2"
istiov1alpha1 "github.com/fluxcd/flagger/pkg/apis/istio/common/v1alpha1"
Expand Down Expand Up @@ -164,6 +165,9 @@ func newTestCanaryAppMesh() *flaggerv1.Canary {
ObjectMeta: metav1.ObjectMeta{
Namespace: "default",
Name: "appmesh",
Annotations: map[string]string{
appmesh.AccessLogAnnotation: appmesh.EnabledValue,
},
},
Spec: flaggerv1.CanarySpec{
TargetRef: flaggerv1.CrossNamespaceObjectReference{
Expand Down