Skip to content

Commit

Permalink
feat(aws-eks): support aws/aws-node-termination-handler as the defaul…
Browse files Browse the repository at this point in the history
…t spot draining handler (#4931)
  • Loading branch information
pahud authored and mergify[bot] committed Nov 10, 2019
1 parent 0040585 commit f4a41d1
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 20 deletions.
136 changes: 118 additions & 18 deletions packages/@aws-cdk/aws-eks/lib/spot-interrupt-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,65 +11,165 @@ export function spotInterruptHandler(nodeSelector: { [name: string]: string } =
kind: "ClusterRole",
apiVersion: "rbac.authorization.k8s.io/v1",
metadata: {
name: "spot-interrupt-handler",
name: "node-termination-handler",
namespace: "default"
},
rules: [
{ apiGroups: [ "" ], resources: [ "*" ], verbs: [ "*" ] },
{ apiGroups: [ "rbac.authorization.k8s.io" ], resources: [ "*" ], verbs: [ "*" ] },
{ apiGroups: [ "apiextensions.k8s.io" ], resources: [ "customresourcedefinitions" ], verbs: [ "get", "list", "watch", "create", "delete" ] }
{
apiGroups: [
"apps"
],
resources: [
"daemonsets"
],
verbs: [
"get",
"delete"
]
},
{
apiGroups: [
""
],
resources: [
"*"
],
verbs: [
"*"
]
},
{
apiGroups: [
"rbac.authorization.k8s.io"
],
resources: [
"*"
],
verbs: [
"*"
]
},
{
apiGroups: [
"apiextensions.k8s.io"
],
resources: [
"customresourcedefinitions"
],
verbs: [
"get",
"list",
"watch",
"create",
"delete"
]
}
]
},
{
apiVersion: "v1",
kind: "ServiceAccount",
metadata: {
name: "spot-interrupt-handler"
name: "node-termination-handler"
}
},
{
kind: "ClusterRoleBinding",
apiVersion: "rbac.authorization.k8s.io/v1",
metadata: {
name: "spot-interrupt-handler",
name: "node-termination-handler",
namespace: "default"
},
subjects: [ { kind: "ServiceAccount", name: "spot-interrupt-handler", namespace: "default" } ],
roleRef: { kind: "ClusterRole", name: "spot-interrupt-handler", apiGroup: "rbac.authorization.k8s.io" }
subjects: [
{
kind: "ServiceAccount",
name: "node-termination-handler",
namespace: "default"
}
],
roleRef: {
kind: "ClusterRole",
name: "node-termination-handler",
apiGroup: "rbac.authorization.k8s.io"
}
},
{
apiVersion: "apps/v1beta2",
kind: "DaemonSet",
metadata: {
name: "spot-interrupt-handler",
name: "node-termination-handler",
namespace: "default"
},
spec: {
selector: {
matchLabels: { app: "spot-interrupt-handler" }
matchLabels: {
app: "node-termination-handler"
}
},
template: {
metadata: {
labels: { app: "spot-interrupt-handler" }
labels: {
app: "node-termination-handler"
}
},
spec: {
serviceAccountName: "spot-interrupt-handler",
serviceAccountName: "node-termination-handler",
containers: [
{
name: "spot-interrupt-handler",
image: "madhuriperi/samplek8spotinterrupt:latest",
name: "node-termination-handler",
image: "amazon/aws-node-termination-handler:v1.0.0",
imagePullPolicy: "Always",
env: [
{ name: "POD_NAME", valueFrom: { fieldRef: { fieldPath: "metadata.name" } } },
{ name: "NAMESPACE", valueFrom: { fieldRef: { fieldPath: "metadata.namespace" } } },
{ name: "SPOT_POD_IP", valueFrom: { fieldRef: { fieldPath: "status.podIP" } } }
]
{
name: "NODE_NAME",
valueFrom: {
fieldRef: {
fieldPath: "spec.nodeName"
}
}
},
{
name: "POD_NAME",
valueFrom: {
fieldRef: {
fieldPath: "metadata.name"
}
}
},
{
name: "NAMESPACE",
valueFrom: {
fieldRef: {
fieldPath: "metadata.namespace"
}
}
},
{
name: "SPOT_POD_IP",
valueFrom: {
fieldRef: {
fieldPath: "status.podIP"
}
}
}
],
resources: {
requests: {
memory: "64Mi",
cpu: "50m"
},
limits: {
memory: "128Mi",
cpu: "100m"
}
}
}
],
nodeSelector
}
}
}
}

];
}
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-eks/test/integ.eks-spot.expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,7 @@
"Arn"
]
},
"Manifest": "[{\"kind\":\"ClusterRole\",\"apiVersion\":\"rbac.authorization.k8s.io/v1\",\"metadata\":{\"name\":\"spot-interrupt-handler\",\"namespace\":\"default\"},\"rules\":[{\"apiGroups\":[\"\"],\"resources\":[\"*\"],\"verbs\":[\"*\"]},{\"apiGroups\":[\"rbac.authorization.k8s.io\"],\"resources\":[\"*\"],\"verbs\":[\"*\"]},{\"apiGroups\":[\"apiextensions.k8s.io\"],\"resources\":[\"customresourcedefinitions\"],\"verbs\":[\"get\",\"list\",\"watch\",\"create\",\"delete\"]}]},{\"apiVersion\":\"v1\",\"kind\":\"ServiceAccount\",\"metadata\":{\"name\":\"spot-interrupt-handler\"}},{\"kind\":\"ClusterRoleBinding\",\"apiVersion\":\"rbac.authorization.k8s.io/v1\",\"metadata\":{\"name\":\"spot-interrupt-handler\",\"namespace\":\"default\"},\"subjects\":[{\"kind\":\"ServiceAccount\",\"name\":\"spot-interrupt-handler\",\"namespace\":\"default\"}],\"roleRef\":{\"kind\":\"ClusterRole\",\"name\":\"spot-interrupt-handler\",\"apiGroup\":\"rbac.authorization.k8s.io\"}},{\"apiVersion\":\"apps/v1beta2\",\"kind\":\"DaemonSet\",\"metadata\":{\"name\":\"spot-interrupt-handler\",\"namespace\":\"default\"},\"spec\":{\"selector\":{\"matchLabels\":{\"app\":\"spot-interrupt-handler\"}},\"template\":{\"metadata\":{\"labels\":{\"app\":\"spot-interrupt-handler\"}},\"spec\":{\"serviceAccountName\":\"spot-interrupt-handler\",\"containers\":[{\"name\":\"spot-interrupt-handler\",\"image\":\"madhuriperi/samplek8spotinterrupt:latest\",\"imagePullPolicy\":\"Always\",\"env\":[{\"name\":\"POD_NAME\",\"valueFrom\":{\"fieldRef\":{\"fieldPath\":\"metadata.name\"}}},{\"name\":\"NAMESPACE\",\"valueFrom\":{\"fieldRef\":{\"fieldPath\":\"metadata.namespace\"}}},{\"name\":\"SPOT_POD_IP\",\"valueFrom\":{\"fieldRef\":{\"fieldPath\":\"status.podIP\"}}}]}],\"nodeSelector\":{\"lifecycle\":\"Ec2Spot\"}}}}}]"
"Manifest": "[{\"kind\":\"ClusterRole\",\"apiVersion\":\"rbac.authorization.k8s.io/v1\",\"metadata\":{\"name\":\"node-termination-handler\",\"namespace\":\"default\"},\"rules\":[{\"apiGroups\":[\"apps\"],\"resources\":[\"daemonsets\"],\"verbs\":[\"get\",\"delete\"]},{\"apiGroups\":[\"\"],\"resources\":[\"*\"],\"verbs\":[\"*\"]},{\"apiGroups\":[\"rbac.authorization.k8s.io\"],\"resources\":[\"*\"],\"verbs\":[\"*\"]},{\"apiGroups\":[\"apiextensions.k8s.io\"],\"resources\":[\"customresourcedefinitions\"],\"verbs\":[\"get\",\"list\",\"watch\",\"create\",\"delete\"]}]},{\"apiVersion\":\"v1\",\"kind\":\"ServiceAccount\",\"metadata\":{\"name\":\"node-termination-handler\"}},{\"kind\":\"ClusterRoleBinding\",\"apiVersion\":\"rbac.authorization.k8s.io/v1\",\"metadata\":{\"name\":\"node-termination-handler\",\"namespace\":\"default\"},\"subjects\":[{\"kind\":\"ServiceAccount\",\"name\":\"node-termination-handler\",\"namespace\":\"default\"}],\"roleRef\":{\"kind\":\"ClusterRole\",\"name\":\"node-termination-handler\",\"apiGroup\":\"rbac.authorization.k8s.io\"}},{\"apiVersion\":\"apps/v1beta2\",\"kind\":\"DaemonSet\",\"metadata\":{\"name\":\"node-termination-handler\",\"namespace\":\"default\"},\"spec\":{\"selector\":{\"matchLabels\":{\"app\":\"node-termination-handler\"}},\"template\":{\"metadata\":{\"labels\":{\"app\":\"node-termination-handler\"}},\"spec\":{\"serviceAccountName\":\"node-termination-handler\",\"containers\":[{\"name\":\"node-termination-handler\",\"image\":\"amazon/aws-node-termination-handler:v1.0.0\",\"imagePullPolicy\":\"Always\",\"env\":[{\"name\":\"NODE_NAME\",\"valueFrom\":{\"fieldRef\":{\"fieldPath\":\"spec.nodeName\"}}},{\"name\":\"POD_NAME\",\"valueFrom\":{\"fieldRef\":{\"fieldPath\":\"metadata.name\"}}},{\"name\":\"NAMESPACE\",\"valueFrom\":{\"fieldRef\":{\"fieldPath\":\"metadata.namespace\"}}},{\"name\":\"SPOT_POD_IP\",\"valueFrom\":{\"fieldRef\":{\"fieldPath\":\"status.podIP\"}}}],\"resources\":{\"requests\":{\"memory\":\"64Mi\",\"cpu\":\"50m\"},\"limits\":{\"memory\":\"128Mi\",\"cpu\":\"100m\"}}}],\"nodeSelector\":{\"lifecycle\":\"Ec2Spot\"}}}}}]"
},
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
Expand Down Expand Up @@ -1405,4 +1405,4 @@
"Default": "/aws/service/eks/optimized-ami/1.14/amazon-linux-2/recommended/image_id"
}
}
}
}

0 comments on commit f4a41d1

Please sign in to comment.