Skip to content

Commit

Permalink
Refactor addBackendPolicyIfConfigured to allow future features
Browse files Browse the repository at this point in the history
  • Loading branch information
sawsa307 committed Sep 12, 2024
1 parent a7628a8 commit f7219b3
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions pkg/i2gw/providers/gce/gce_extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,32 +167,35 @@ 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",
Name: gatewayv1.ObjectName(serviceNamespacedName.Name),
},
},
}
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
}

0 comments on commit f7219b3

Please sign in to comment.