@@ -23,6 +23,7 @@ import (
2323 envoyapi "github.com/envoyproxy/gateway/api/v1alpha1"
2424 operatorv1 "github.com/tigera/operator/api/v1"
2525 "github.com/tigera/operator/pkg/components"
26+ "github.com/tigera/operator/pkg/ptr"
2627 rtest "github.com/tigera/operator/pkg/render/common/test"
2728 appsv1 "k8s.io/api/apps/v1"
2829 batchv1 "k8s.io/api/batch/v1"
@@ -719,4 +720,203 @@ var _ = Describe("Gateway API rendering tests", func() {
719720 Expect (ep4 .Spec .Provider .Kubernetes .EnvoyService .LoadBalancerSourceRanges ).To (ConsistOf ("182.98.44.55/24" ))
720721 Expect (* ep4 .Spec .Provider .Kubernetes .EnvoyService .LoadBalancerIP ).To (Equal (lbIP ))
721722 })
723+
724+ It ("should not deploy waf-http-filter for open-source" , func () {
725+ installation := & operatorv1.InstallationSpec {
726+ Variant : operatorv1 .Calico ,
727+ }
728+ gatewayAPI := & operatorv1.GatewayAPI {
729+ Spec : operatorv1.GatewayAPISpec {
730+ GatewayClasses : []operatorv1.GatewayClassSpec {{Name : "tigera-gateway-class" }},
731+ },
732+ }
733+ gatewayComp := GatewayAPIImplementationComponent (& GatewayAPIImplementationConfig {
734+ Installation : installation ,
735+ GatewayAPI : gatewayAPI ,
736+ })
737+
738+ objsToCreate , _ := gatewayComp .Objects ()
739+ proxy , err := rtest .GetResourceOfType [* envoyapi.EnvoyProxy ](objsToCreate , "tigera-gateway-class" , "tigera-gateway" )
740+ Expect (err ).NotTo (HaveOccurred ())
741+ envoyDeployment := proxy .Spec .Provider .Kubernetes .EnvoyDeployment
742+ Expect (envoyDeployment ).ToNot (BeNil ())
743+ Expect (envoyDeployment .InitContainers ).To (BeNil ())
744+ Expect (envoyDeployment .Container ).ToNot (BeNil ())
745+ Expect (envoyDeployment .Container .VolumeMounts ).To (BeNil ())
746+ })
747+
748+ It ("should deploy waf-http-filter for Enterprise" , func () {
749+ installation := & operatorv1.InstallationSpec {
750+ Variant : operatorv1 .TigeraSecureEnterprise ,
751+ }
752+ gatewayAPI := & operatorv1.GatewayAPI {
753+ Spec : operatorv1.GatewayAPISpec {
754+ GatewayClasses : []operatorv1.GatewayClassSpec {{Name : "tigera-gateway-class" }},
755+ },
756+ }
757+ gatewayComp := GatewayAPIImplementationComponent (& GatewayAPIImplementationConfig {
758+ Installation : installation ,
759+ GatewayAPI : gatewayAPI ,
760+ })
761+
762+ objsToCreate , _ := gatewayComp .Objects ()
763+ proxy , err := rtest .GetResourceOfType [* envoyapi.EnvoyProxy ](objsToCreate , "tigera-gateway-class" , "tigera-gateway" )
764+ Expect (err ).NotTo (HaveOccurred ())
765+
766+ envoyDeployment := proxy .Spec .Provider .Kubernetes .EnvoyDeployment
767+ Expect (envoyDeployment ).ToNot (BeNil ())
768+
769+ Expect (envoyDeployment .Pod ).ToNot (BeNil ())
770+ Expect (envoyDeployment .Pod .Volumes ).To (HaveLen (2 ))
771+ Expect (envoyDeployment .Pod .Volumes [0 ].Name ).To (Equal ("var-log-calico" ))
772+ Expect (envoyDeployment .Pod .Volumes [0 ].HostPath .Path ).To (Equal ("/var/log/calico" ))
773+ Expect (envoyDeployment .Pod .Volumes [1 ].Name ).To (Equal ("waf-http-filter" ))
774+ Expect (envoyDeployment .Pod .Volumes [1 ].EmptyDir ).ToNot (BeNil ())
775+
776+ Expect (envoyDeployment .InitContainers [0 ].Name ).To (Equal ("waf-http-filter" ))
777+ Expect (* envoyDeployment .InitContainers [0 ].RestartPolicy ).To (Equal (corev1 .ContainerRestartPolicyAlways ))
778+ Expect (envoyDeployment .InitContainers [0 ].VolumeMounts ).To (HaveLen (2 ))
779+ Expect (envoyDeployment .InitContainers [0 ].VolumeMounts ).To (ContainElements ([]corev1.VolumeMount {
780+ {
781+ Name : "waf-http-filter" ,
782+ MountPath : "/var/run/waf-http-filter" ,
783+ },
784+ {
785+ Name : "var-log-calico" ,
786+ MountPath : "/var/log/calico" ,
787+ },
788+ }))
789+
790+ Expect (envoyDeployment .Container ).ToNot (BeNil ())
791+ Expect (envoyDeployment .Container .VolumeMounts ).To (HaveLen (1 ))
792+ Expect (envoyDeployment .Container .VolumeMounts ).To (ContainElement (corev1.VolumeMount {
793+ Name : "waf-http-filter" ,
794+ MountPath : "/var/run/waf-http-filter" ,
795+ }))
796+ })
797+
798+ It ("should deploy waf-http-filter for Enterprise when using a custom proxy" , func () {
799+ installation := & operatorv1.InstallationSpec {
800+ Variant : operatorv1 .TigeraSecureEnterprise ,
801+ }
802+ gatewayAPI := & operatorv1.GatewayAPI {
803+ Spec : operatorv1.GatewayAPISpec {
804+ GatewayClasses : []operatorv1.GatewayClassSpec {{
805+ Name : "custom-class" ,
806+ EnvoyProxyRef : & operatorv1.NamespacedName {
807+ Namespace : "default" ,
808+ Name : "my-proxy" ,
809+ },
810+ }},
811+ },
812+ }
813+ envoyProxy := & envoyapi.EnvoyProxy {
814+ TypeMeta : metav1.TypeMeta {
815+ Kind : "EnvoyProxy" ,
816+ APIVersion : "gateway.envoyproxy.io/v1alpha1" ,
817+ },
818+ ObjectMeta : metav1.ObjectMeta {
819+ Name : "my-proxy" ,
820+ Namespace : "default" ,
821+ },
822+ Spec : envoyapi.EnvoyProxySpec {
823+ Provider : & envoyapi.EnvoyProxyProvider {
824+ Type : envoyapi .ProviderTypeKubernetes ,
825+ Kubernetes : & envoyapi.EnvoyProxyKubernetesProvider {
826+ EnvoyDeployment : & envoyapi.KubernetesDeploymentSpec {
827+ InitContainers : []corev1.Container {
828+ {
829+ Name : "some-other-sidecar" ,
830+ RestartPolicy : ptr.ToPtr [corev1.ContainerRestartPolicy ](corev1 .ContainerRestartPolicyAlways ),
831+ VolumeMounts : []corev1.VolumeMount {
832+ {
833+ Name : "some-other-volume" ,
834+ MountPath : "/test" ,
835+ },
836+ },
837+ },
838+ },
839+ Container : & envoyapi.KubernetesContainerSpec {
840+ VolumeMounts : []corev1.VolumeMount {
841+ {
842+ Name : "some-other-volume" ,
843+ MountPath : "/test" ,
844+ },
845+ },
846+ },
847+ Pod : & envoyapi.KubernetesPodSpec {
848+ Volumes : []corev1.Volume {
849+ {
850+ Name : "some-other-volume" ,
851+ VolumeSource : corev1.VolumeSource {
852+ EmptyDir : & corev1.EmptyDirVolumeSource {},
853+ },
854+ },
855+ },
856+ },
857+ },
858+ },
859+ },
860+ },
861+ }
862+ gatewayComp := GatewayAPIImplementationComponent (& GatewayAPIImplementationConfig {
863+ Installation : installation ,
864+ GatewayAPI : gatewayAPI ,
865+ CustomEnvoyProxies : map [string ]* envoyapi.EnvoyProxy {
866+ "custom-class" : envoyProxy ,
867+ },
868+ })
869+
870+ objsToCreate , _ := gatewayComp .Objects ()
871+
872+ // Get the four expected GatewayClasses.
873+ gc , err := rtest .GetResourceOfType [* gapi.GatewayClass ](objsToCreate , "custom-class" , "tigera-gateway" )
874+ Expect (err ).NotTo (HaveOccurred ())
875+
876+ // Get their four EnvoyProxies.
877+ Expect (gc .Spec .ParametersRef ).NotTo (BeNil ())
878+ proxy , err := rtest .GetResourceOfType [* envoyapi.EnvoyProxy ](objsToCreate , gc .Spec .ParametersRef .Name , string (* gc .Spec .ParametersRef .Namespace ))
879+ Expect (err ).NotTo (HaveOccurred ())
880+
881+ envoyDeployment := proxy .Spec .Provider .Kubernetes .EnvoyDeployment
882+ Expect (envoyDeployment ).ToNot (BeNil ())
883+
884+ Expect (envoyDeployment .InitContainers ).To (HaveLen (2 ))
885+ Expect (envoyDeployment .InitContainers [0 ].Name ).To (Equal ("some-other-sidecar" ))
886+ Expect (envoyDeployment .InitContainers [1 ].Name ).To (Equal ("waf-http-filter" ))
887+ Expect (* envoyDeployment .InitContainers [1 ].RestartPolicy ).To (Equal (corev1 .ContainerRestartPolicyAlways ))
888+ Expect (envoyDeployment .InitContainers [1 ].VolumeMounts ).To (HaveLen (2 ))
889+ Expect (envoyDeployment .InitContainers [1 ].VolumeMounts ).To (ContainElements ([]corev1.VolumeMount {
890+ {
891+ Name : "waf-http-filter" ,
892+ MountPath : "/var/run/waf-http-filter" ,
893+ },
894+ {
895+ Name : "var-log-calico" ,
896+ MountPath : "/var/log/calico" ,
897+ },
898+ }))
899+
900+ Expect (envoyDeployment .Container ).ToNot (BeNil ())
901+ Expect (envoyDeployment .Container .VolumeMounts ).To (ContainElements (
902+ corev1.VolumeMount {
903+ Name : "some-other-volume" ,
904+ MountPath : "/test" ,
905+ }, corev1.VolumeMount {
906+ Name : "waf-http-filter" ,
907+ MountPath : "/var/run/waf-http-filter" ,
908+ },
909+ ))
910+
911+ Expect (envoyDeployment .Pod ).ToNot (BeNil ())
912+ Expect (envoyDeployment .Pod .Volumes ).To (HaveLen (3 ))
913+ Expect (envoyDeployment .Pod .Volumes [0 ].Name ).To (Equal ("some-other-volume" ))
914+ Expect (envoyDeployment .Pod .Volumes [0 ].EmptyDir ).ToNot (BeNil ())
915+ Expect (envoyDeployment .Pod .Volumes [1 ].Name ).To (Equal ("var-log-calico" ))
916+ Expect (envoyDeployment .Pod .Volumes [1 ].HostPath .Path ).To (Equal ("/var/log/calico" ))
917+ Expect (envoyDeployment .Pod .Volumes [2 ].Name ).To (Equal ("waf-http-filter" ))
918+ Expect (envoyDeployment .Pod .Volumes [2 ].EmptyDir ).ToNot (BeNil ())
919+
920+ })
921+
722922})
0 commit comments