diff --git a/pkg/i2gw/providers/gce/gce_extensions.go b/pkg/i2gw/providers/gce/gce_extensions.go index d566d575..d2120254 100644 --- a/pkg/i2gw/providers/gce/gce_extensions.go +++ b/pkg/i2gw/providers/gce/gce_extensions.go @@ -167,21 +167,16 @@ func buildGceServiceExtensions(ir intermediate.IR, gatewayResources *i2gw.Gatewa } func addBackendPolicyIfConfigured(serviceNamespacedName types.NamespacedName, serviceIR intermediate.ProviderSpecificServiceIR) *gkegatewayv1.GCPBackendPolicy { - if serviceIR.Gce == nil || serviceIR.Gce.SessionAffinity == nil { + if serviceIR.Gce == nil { return nil } - affinityType := serviceIR.Gce.SessionAffinity.AffinityType backendPolicy := gkegatewayv1.GCPBackendPolicy{ ObjectMeta: metav1.ObjectMeta{ Namespace: serviceNamespacedName.Namespace, Name: serviceNamespacedName.Name, }, Spec: gkegatewayv1.GCPBackendPolicySpec{ - Default: &gkegatewayv1.GCPBackendPolicyConfig{ - SessionAffinity: &gkegatewayv1.SessionAffinityConfig{ - Type: &affinityType, - }, - }, + Default: &gkegatewayv1.GCPBackendPolicyConfig{}, TargetRef: gatewayv1alpha2.NamespacedPolicyTargetReference{ Group: "", Kind: "Service", @@ -189,10 +184,18 @@ func addBackendPolicyIfConfigured(serviceNamespacedName types.NamespacedName, se }, }, } - if affinityType == "GENERATED_COOKIE" { - backendPolicy.Spec.Default.SessionAffinity.CookieTTLSec = serviceIR.Gce.SessionAffinity.CookieTTLSec + backendPolicy.SetGroupVersionKind(GCPBackendPolicyGVK) + + if serviceIR.Gce.SessionAffinity != nil { + affinityType := serviceIR.Gce.SessionAffinity.AffinityType + saConfig := gkegatewayv1.SessionAffinityConfig{ + Type: &affinityType, + } + if affinityType == "GENERATED_COOKIE" { + saConfig.CookieTTLSec = serviceIR.Gce.SessionAffinity.CookieTTLSec + } + backendPolicy.Spec.Default.SessionAffinity = &saConfig } - backendPolicy.SetGroupVersionKind(GCPBackendPolicyGVK) return &backendPolicy }