Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node termination handler configuration #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 63 additions & 25 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ export interface EKSClusterLauncherArgs {
}
}
}
/** nodeTerminationHandler - monitors ec2 instance metadata to drain kubernetes nodes before they are removed
*
* __default__: { enabled: true, spotInterruptionDraining: true, rebalanceDraining: false, scheduledEventDraining: false, prometheusServer: false, emitKubernetesEvents: false}
* Ref: https://github.com/aws/aws-node-termination-handler/tree/main/config/helm/aws-node-termination-handler
*/
nodeTerminationHandler: {
enabled: boolean
spotInterruptionDraining: boolean
rebalanceDraining: boolean
scheduledEventDraining: boolean
prometheusServer: boolean
emitKubernetesEvents: boolean
}
/** profile is the local profile to use configured in ~/.aws/credentials file
*
* __default__: 'default'
Expand Down Expand Up @@ -125,10 +138,12 @@ export class EKSClusterLauncher extends pulumi.ComponentResource {

const defaults: DeepRequired<Omit<EKSClusterLauncherArgs, 'rootDomainName' | 'instanceTypes' | 'email'>> = {
allAZs: false,
profile: 'default',
region: 'us-east-1',
autoscaling: {
enabled: false,
maxInstances: 3,
minInstances: 1
},
cidrBlock: '10.0.0.0/16',
numInstancesPerAZ: 1,
logging: {
enabled: false,
persistentVolume: false,
Expand All @@ -149,11 +164,17 @@ export class EKSClusterLauncher extends pulumi.ComponentResource {
}
}
},
autoscaling: {
enabled: false,
maxInstances: 3,
minInstances: 1
nodeTerminationHandler: {
enabled: true,
spotInterruptionDraining: true,
rebalanceDraining: false,
scheduledEventDraining: false,
prometheusServer: false,
emitKubernetesEvents: false
},
numInstancesPerAZ: 1,
profile: 'default',
region: 'us-east-1',
traefik: {
whitelist: [],
replicas: 3,
Expand All @@ -165,8 +186,15 @@ export class EKSClusterLauncher extends pulumi.ComponentResource {
}

const argsWithDefaults: DeepRequired<Omit<EKSClusterLauncherArgs, 'email'>> & { email: string | undefined } = {
allAZs: args.allAZs ?? defaults.allAZs,
autoscaling: {
enabled: args.autoscaling?.enabled ?? defaults.autoscaling.enabled,
maxInstances: args.autoscaling?.maxInstances ?? defaults.autoscaling.maxInstances,
minInstances: args.autoscaling?.minInstances ?? defaults.autoscaling.minInstances
},
cidrBlock: args.cidrBlock ?? defaults.cidrBlock,
email: args.email,
instanceTypes: args.instanceTypes,
rootDomainName: args.rootDomainName,
logging: {
enabled: args.logging?.enabled ?? defaults.logging.enabled,
persistentVolume: args.logging?.persistentVolume ?? defaults.logging.persistentVolume,
Expand All @@ -178,17 +206,18 @@ export class EKSClusterLauncher extends pulumi.ComponentResource {
promtail: args.logging?.resources?.promtail ?? defaults.logging.resources.promtail
}
},
allAZs: args.allAZs ?? defaults.allAZs,
nodeTerminationHandler: {
enabled: args.nodeTerminationHandler.enabled ?? defaults.nodeTerminationHandler.enabled,
spotInterruptionDraining: args.nodeTerminationHandler.spotInterruptionDraining ?? defaults.nodeTerminationHandler.spotInterruptionDraining,
rebalanceDraining: args.nodeTerminationHandler.rebalanceDraining ?? defaults.nodeTerminationHandler.rebalanceDraining,
scheduledEventDraining: args.nodeTerminationHandler.scheduledEventDraining ?? defaults.nodeTerminationHandler.scheduledEventDraining,
prometheusServer: args.nodeTerminationHandler.prometheusServer ?? defaults.nodeTerminationHandler.prometheusServer,
emitKubernetesEvents: args.nodeTerminationHandler.emitKubernetesEvents ?? defaults.nodeTerminationHandler.emitKubernetesEvents
},
numInstancesPerAZ: args.numInstancesPerAZ ?? defaults.numInstancesPerAZ,
profile: args.profile ?? defaults.profile,
region: args.region ?? defaults.region,
cidrBlock: args.cidrBlock ?? defaults.cidrBlock,
numInstancesPerAZ: args.numInstancesPerAZ ?? defaults.numInstancesPerAZ,
autoscaling: {
enabled: args.autoscaling?.enabled ?? defaults.autoscaling.enabled,
maxInstances: args.autoscaling?.maxInstances ?? defaults.autoscaling.maxInstances,
minInstances: args.autoscaling?.minInstances ?? defaults.autoscaling.minInstances
},
email: args.email,
rootDomainName: args.rootDomainName,
traefik: {
whitelist: args.traefik?.whitelist ?? defaults.traefik.whitelist,
replicas: args.traefik?.replicas ?? defaults.traefik.replicas,
Expand Down Expand Up @@ -273,14 +302,23 @@ export class EKSClusterLauncher extends pulumi.ComponentResource {
{ ...opts, provider: awsProvider }
)

new nodeTerminationHandler.Deployment(
name,
{
cluster: cluster,
namespace: namespace
},
{ ...opts, provider: k8sProvider }
)
if (argsWithDefaults.nodeTerminationHandler.enabled) {
new nodeTerminationHandler.Deployment(
name,
{
cluster: cluster,
namespace: namespace,
events: {
spotInterruptionDraining: argsWithDefaults.nodeTerminationHandler.spotInterruptionDraining,
rebalanceDraining: argsWithDefaults.nodeTerminationHandler.rebalanceDraining,
scheduledEventDraining: argsWithDefaults.nodeTerminationHandler.scheduledEventDraining
},
enablePrometheusServer: argsWithDefaults.nodeTerminationHandler.prometheusServer,
emitKubernetesEvents: argsWithDefaults.nodeTerminationHandler.emitKubernetesEvents
},
{ ...opts, provider: k8sProvider }
)
}

if (argsWithDefaults.logging.enabled) {
new loki.Deployment(
Expand Down
17 changes: 12 additions & 5 deletions src/nodeTerminationHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ import { Cluster } from '@pulumi/eks'
export interface deploymentArgs {
namespace: pulumi.Input<string>
cluster: Cluster
events: {
spotInterruptionDraining: boolean
rebalanceDraining: boolean
scheduledEventDraining: boolean
}
enablePrometheusServer: boolean
emitKubernetesEvents: boolean
}

export class Deployment extends k8s.helm.v3.Chart {
Expand All @@ -18,13 +25,13 @@ export class Deployment extends k8s.helm.v3.Chart {
namespace: args.namespace,
version: '0.15.3',
values: {
enableSpotInterruptionDraining: 'true',
enableRebalanceDraining: 'false',
enableScheduledEventDraining: 'false', //Experimental feature
enableSpotInterruptionDraining: args.events.spotInterruptionDraining,
enableRebalanceDraining: args.events.rebalanceDraining,
enableScheduledEventDraining: args.events.scheduledEventDraining, //Experimental feature
podTerminationGracePeriod: '-1', //If negative, use value defined in pod
nodeTerminationGracePeriod: '120',
enablePrometheusServer: 'false', //For later use
emitKubernetesEvents: 'false' //For later use
enablePrometheusServer: args.enablePrometheusServer,
emitKubernetesEvents: args.emitKubernetesEvents
}
},
{ ...opts, parent: args.cluster }
Expand Down