diff --git a/docs/gitbook/tutorials/appmesh-progressive-delivery.md b/docs/gitbook/tutorials/appmesh-progressive-delivery.md index 9a7206f3d..d8b6170ce 100644 --- a/docs/gitbook/tutorials/appmesh-progressive-delivery.md +++ b/docs/gitbook/tutorials/appmesh-progressive-delivery.md @@ -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: diff --git a/pkg/apis/appmesh/register.go b/pkg/apis/appmesh/register.go index 2e54ff10f..ffcf13884 100644 --- a/pkg/apis/appmesh/register.go +++ b/pkg/apis/appmesh/register.go @@ -3,3 +3,7 @@ package appmesh const ( GroupName = "appmesh.k8s.aws" ) + +const AccessLogAnnotation = "appmesh.flagger.app/accesslog" + +const EnabledValue = "enabled" diff --git a/pkg/router/appmesh.go b/pkg/router/appmesh.go index 296aaf843..78f986d3d 100644 --- a/pkg/router/appmesh.go +++ b/pkg/router/appmesh.go @@ -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" @@ -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{ diff --git a/pkg/router/appmesh_test.go b/pkg/router/appmesh_test.go index b983935ff..ec12df861 100644 --- a/pkg/router/appmesh_test.go +++ b/pkg/router/appmesh_test.go @@ -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) diff --git a/pkg/router/appmesh_v1beta2.go b/pkg/router/appmesh_v1beta2.go index 61e4fb971..73346c733 100644 --- a/pkg/router/appmesh_v1beta2.go +++ b/pkg/router/appmesh_v1beta2.go @@ -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" @@ -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") { diff --git a/pkg/router/appmesh_v1beta2_test.go b/pkg/router/appmesh_v1beta2_test.go index b41162aeb..6815b0229 100644 --- a/pkg/router/appmesh_v1beta2_test.go +++ b/pkg/router/appmesh_v1beta2_test.go @@ -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) diff --git a/pkg/router/router_test.go b/pkg/router/router_test.go index 0561b40b2..917282bfd 100644 --- a/pkg/router/router_test.go +++ b/pkg/router/router_test.go @@ -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" @@ -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{