mirror of
https://github.com/fluxcd/flagger.git
synced 2026-04-15 06:57:34 +00:00
Merge pull request #1156 from aryan9600/appmesh-log
AppMesh: Add annotation to enable Envoy access logs
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -3,3 +3,7 @@ package appmesh
|
||||
const (
|
||||
GroupName = "appmesh.k8s.aws"
|
||||
)
|
||||
|
||||
const AccessLogAnnotation = "appmesh.flagger.app/accesslog"
|
||||
|
||||
const EnabledValue = "enabled"
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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") {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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{
|
||||
|
||||
Reference in New Issue
Block a user