Skip to content

Commit

Permalink
adding session affinity for eks
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Singer authored and jhsinger-klotho committed Jan 16, 2023
1 parent e7b0095 commit 3dab0c1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pkg/infra/pulumi_aws/iac/eks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface EksExecUnitArgs {
memoryUtilization?: number // Differs from ephemeral-storage resource request (stable in k8s 1.25)
maxReplicas?: number
}
stickinessTimeout?: number
}

export interface HelmOptions {
Expand Down Expand Up @@ -546,7 +547,7 @@ export class Eks {
dependsOn: [deployment],
})
}
const service = this.createService(execUnit, lib.klothoVPC, args.nodeType, deployment)
const service = this.createService(execUnit, lib.klothoVPC, args, deployment)
serviceName = service.metadata.name
dependencyParent = service
}
Expand Down Expand Up @@ -941,7 +942,7 @@ export class Eks {
public createService(
execUnit: string,
vpc: awsx.ec2.Vpc,
nodeType: 'fargate' | 'node',
args: EksExecUnitArgs,
parent,
dependsOn: (pulumi.Resource | pulumi.Output<pulumi.CustomResource[]>)[] = [],
serviceDiscoveryDomain?: pulumi.Output<string>,
Expand Down Expand Up @@ -976,8 +977,9 @@ export class Eks {
return k8s.createService(
execUnit,
this.provider,
generateLabels(execUnit, nodeType === 'fargate'),
generateLabels(execUnit, args.nodeType === 'fargate'),
metadataAnnotations,
args.stickinessTimeout ? args.stickinessTimeout : 0,
parent,
dependsOn
)
Expand Down
14 changes: 14 additions & 0 deletions pkg/infra/pulumi_aws/iac/kubernetes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,22 @@ export const createService = (
k8sProvider: k8s.Provider,
appLabels: { [key: string]: string },
annotations,
stickinessTimeout: number,
parent,
dependsOn
): k8s.core.v1.Service => {
let sessionAffinityFields = {}
if (stickinessTimeout > 0) {
sessionAffinityFields = {
sessionAffinity: 'ClientIP',
sessionAffinityConfig: {
clientIP: {
timeoutSeconds: stickinessTimeout,
},
},
}
}

return new k8s.core.v1.Service(
execUnit.replace('-', '').toLowerCase(),
{
Expand All @@ -91,6 +104,7 @@ export const createService = (
},
],
selector: appLabels,
...sessionAffinityFields,
},
},
{ provider: k8sProvider, parent, dependsOn }
Expand Down

0 comments on commit 3dab0c1

Please sign in to comment.