Skip to content

Commit

Permalink
add annotation to enable appmesh logs
Browse files Browse the repository at this point in the history
Signed-off-by: Sanskar Jaiswal <[email protected]>
Co-authored-by: wucg <[email protected]>
  • Loading branch information
Sanskar Jaiswal and wucg committed Mar 22, 2022
1 parent cc7b35b commit a22638f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 0 deletions.
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

0 comments on commit a22638f

Please sign in to comment.