@@ -3,6 +3,7 @@ package envoy
33import (
44 "errors"
55 "log"
6+ "path/filepath"
67 "strings"
78 "sync"
89 "time"
@@ -58,6 +59,7 @@ type KubernetesConfigurator struct {
5859 ingressClasses []string
5960 nodeID string
6061 syncSecrets bool
62+ accessLog string
6163 certificates []Certificate
6264 trustCA string
6365 upstreamPort uint32
@@ -80,21 +82,40 @@ type KubernetesConfigurator struct {
8082}
8183
8284// NewKubernetesConfigurator returns a Kubernetes configurator given a lister and ingress class
83- func NewKubernetesConfigurator (nodeID string , certificates []Certificate , ca string , ingressClasses []string , options ... option ) * KubernetesConfigurator {
84- c := & KubernetesConfigurator {ingressClasses : ingressClasses , nodeID : nodeID , certificates : certificates , trustCA : ca }
85+ func NewKubernetesConfigurator (nodeID string , certificates []Certificate , ca string , ingressClasses []string , accessLog string , options ... option ) * KubernetesConfigurator {
86+ c := & KubernetesConfigurator {ingressClasses : ingressClasses , nodeID : nodeID , certificates : certificates , trustCA : ca , accessLog : accessLog }
8587 for _ , opt := range options {
8688 opt (c )
8789 }
8890 return c
8991}
9092
93+ func (c * KubernetesConfigurator ) ValidateAndFormatPath () {
94+ if c .accessLog == "" {
95+ logrus .Fatal ("accessLog path cannot be empty" )
96+ }
97+
98+ // Clean the path and make it absolute
99+ c .accessLog = filepath .Clean (c .accessLog )
100+ absolutePath , err := filepath .Abs (c .accessLog )
101+ if err != nil {
102+ logrus .Fatalf ("invalid path: %v" , err )
103+ }
104+ c .accessLog = absolutePath
105+
106+ // Ensure the path ends with a directory separator if it's a directory
107+ if strings .HasSuffix (c .accessLog , string (filepath .Separator )) {
108+ c .accessLog = string (filepath .Separator )
109+ }
110+ }
111+
91112// Generate creates a new snapshot
92113func (c * KubernetesConfigurator ) Generate (ingresses []* k8s.Ingress , secrets []* v1.Secret ) cache.Snapshot {
93114 c .Lock ()
94115 defer c .Unlock ()
95116
96117 validIngresses := validIngressFilter (classFilter (ingresses , c .ingressClasses ))
97- config := translateIngresses (validIngresses , c .syncSecrets , secrets , c .defaultTimeouts )
118+ config := translateIngresses (validIngresses , c .syncSecrets , secrets , c .defaultTimeouts , c . accessLog )
98119
99120 vmatch , cmatch := config .equals (c .previousConfig )
100121
@@ -195,7 +216,7 @@ func (c *KubernetesConfigurator) generateDynamicTLSFilterChains(config *envoyCon
195216 Cert : virtualHost .TlsCert ,
196217 Key : virtualHost .TlsKey ,
197218 }
198- filterChain , err := c .makeFilterChain (certificate , []* route.VirtualHost {envoyVhost })
219+ filterChain , err := c .makeFilterChain (certificate , []* route.VirtualHost {envoyVhost }, config . AccessLog )
199220 if err != nil {
200221 logrus .Warnf ("error making filter chain: %v" , err )
201222 }
@@ -208,7 +229,7 @@ func (c *KubernetesConfigurator) generateDynamicTLSFilterChains(config *envoyCon
208229 Cert : c .certificates [0 ].Cert ,
209230 Key : c .certificates [0 ].Key ,
210231 }
211- if defaultFC , err := c .makeFilterChain (defaultCert , allVhosts ); err != nil {
232+ if defaultFC , err := c .makeFilterChain (defaultCert , allVhosts , config . AccessLog ); err != nil {
212233 logrus .Warnf ("error making default filter chain: %v" , err )
213234 } else {
214235 filterChains = append (filterChains , & defaultFC )
@@ -224,7 +245,7 @@ func (c *KubernetesConfigurator) generateHTTPFilterChain(config *envoyConfigurat
224245 virtualHosts = append (virtualHosts , makeVirtualHost (virtualHost , c .hostSelectionRetryAttempts , c .defaultRetryOn ))
225246 }
226247
227- httpConnectionManager := c .makeConnectionManager (virtualHosts )
248+ httpConnectionManager := c .makeConnectionManager (virtualHosts , config . AccessLog )
228249 httpConfig , err := util .MessageToStruct (httpConnectionManager )
229250 if err != nil {
230251 log .Fatalf ("failed to convert virtualHost to envoy control plane struct: %s" , err )
@@ -267,7 +288,7 @@ func (c *KubernetesConfigurator) generateTLSFilterChains(config *envoyConfigurat
267288 continue
268289 }
269290
270- filterChain , err := c .makeFilterChain (certificate , virtualHosts )
291+ filterChain , err := c .makeFilterChain (certificate , virtualHosts , config . AccessLog )
271292 if err != nil {
272293 log .Printf ("error making filter chain: %v" , err )
273294 }
0 commit comments