Skip to content

Commit fdbdecb

Browse files
committed
fix(eks): separate yaml file
1 parent 79e57bd commit fdbdecb

5 files changed

Lines changed: 171 additions & 46 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# source: https://awsdocs-neuron.readthedocs-hosted.com/en/latest/containers/tutorials/k8s-setup.html
2+
kind: ClusterRoleBinding
3+
apiVersion: rbac.authorization.k8s.io/v1
4+
metadata:
5+
name: neuron-device-plugin
6+
namespace: kube-system
7+
roleRef:
8+
apiGroup: rbac.authorization.k8s.io
9+
kind: ClusterRole
10+
name: neuron-device-plugin
11+
subjects:
12+
- kind: ServiceAccount
13+
name: neuron-device-plugin
14+
namespace: kube-system

packages/aws-cdk-lib/aws-eks/lib/addons/neuron-device-plugin-rbac.yaml renamed to packages/aws-cdk-lib/aws-eks/lib/addons/neuron-device-plugin-rbac-cluster-role.yaml

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# source: https://awsdocs-neuron.readthedocs-hosted.com/en/latest/containers/tutorials/k8s-setup.html
2-
---
32
kind: ClusterRole
43
apiVersion: rbac.authorization.k8s.io/v1
54
metadata:
@@ -37,23 +36,3 @@ rules:
3736
verbs:
3837
- patch
3938
- update
40-
---
41-
apiVersion: v1
42-
kind: ServiceAccount
43-
metadata:
44-
name: neuron-device-plugin
45-
namespace: kube-system
46-
---
47-
kind: ClusterRoleBinding
48-
apiVersion: rbac.authorization.k8s.io/v1
49-
metadata:
50-
name: neuron-device-plugin
51-
namespace: kube-system
52-
roleRef:
53-
apiGroup: rbac.authorization.k8s.io
54-
kind: ClusterRole
55-
name: neuron-device-plugin
56-
subjects:
57-
- kind: ServiceAccount
58-
name: neuron-device-plugin
59-
namespace: kube-system
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# source: https://awsdocs-neuron.readthedocs-hosted.com/en/latest/containers/tutorials/k8s-setup.html
2+
apiVersion: v1
3+
kind: ServiceAccount
4+
metadata:
5+
name: neuron-device-plugin
6+
namespace: kube-system

packages/aws-cdk-lib/aws-eks/lib/cluster.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,7 +1445,11 @@ export class Cluster extends ClusterBase {
14451445

14461446
private _neuronDevicePlugin?: KubernetesManifest;
14471447

1448-
private _neuronDevicePluginRbac?: KubernetesManifest;
1448+
private _neuronDevicePluginRbacClusterRole?: KubernetesManifest;
1449+
1450+
private _neuronDevicePluginRbacServiceAccount?: KubernetesManifest;
1451+
1452+
private _neuronDevicePluginRbacClusterRoleBinding?: KubernetesManifest;
14491453

14501454
private readonly endpointAccess: EndpointAccess;
14511455

@@ -1996,13 +2000,21 @@ export class Cluster extends ClusterBase {
19962000
* already added.
19972001
*/
19982002
private addNeuronDevicePluginRbac() {
1999-
if (!this._neuronDevicePluginRbac) {
2000-
const fileContents = fs.readFileSync(path.join(__dirname, 'addons', 'neuron-device-plugin-rbac.yaml'), 'utf8');
2001-
const sanitized = YAML.parse(fileContents);
2002-
this._neuronDevicePluginRbac = this.addManifest('NeuronDevicePluginRbac', sanitized);
2003+
if (!this._neuronDevicePluginRbacClusterRole) {
2004+
const clusterRoleFileContents = fs.readFileSync(path.join(__dirname, 'addons', 'neuron-device-plugin-rbac-cluster-role.yaml'), 'utf8');
2005+
const sanitizedClusterRole = YAML.parse(clusterRoleFileContents);
2006+
this._neuronDevicePluginRbacClusterRole = this.addManifest('NeuronDevicePluginRbacClusterRole', sanitizedClusterRole);
2007+
}
2008+
if (!this._neuronDevicePluginRbacClusterRoleBinding) {
2009+
const clusterRoleBindingFileContents = fs.readFileSync(path.join(__dirname, 'addons', 'neuron-device-plugin-rbac-cluster-role-binding.yaml'), 'utf8');
2010+
const sanitizedClusterRoleBinding = YAML.parse(clusterRoleBindingFileContents);
2011+
this._neuronDevicePluginRbacClusterRoleBinding = this.addManifest('NeuronDevicePluginRbacClusterRoleBinding', sanitizedClusterRoleBinding);
2012+
}
2013+
if (!this._neuronDevicePluginRbacServiceAccount) {
2014+
const clusterRoleBindingFileContents = fs.readFileSync(path.join(__dirname, 'addons', 'neuron-device-plugin-rbac-service-account.yaml'), 'utf8');
2015+
const sanitizedServiceAccount = YAML.parse(clusterRoleBindingFileContents);
2016+
this._neuronDevicePluginRbacServiceAccount = this.addManifest('NeuronDevicePluginRbacServiceAccount', sanitizedServiceAccount);
20032017
}
2004-
2005-
return this._neuronDevicePluginRbac;
20062018
}
20072019

20082020
/**

packages/aws-cdk-lib/aws-eks/test/cluster.test.ts

Lines changed: 132 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2183,12 +2183,31 @@ describe('cluster', () => {
21832183
instanceType: new ec2.InstanceType('inf1.2xlarge'),
21842184
minCapacity: 1,
21852185
});
2186-
const fileContents = fs.readFileSync(path.join(__dirname, '..', 'lib', 'addons', 'neuron-device-plugin.yaml'), 'utf8');
2187-
const sanitized = YAML.parse(fileContents);
2186+
2187+
const daemonSetFileContents = fs.readFileSync(path.join(__dirname, '..', 'lib', 'addons', 'neuron-device-plugin.yaml'), 'utf8');
2188+
const sanitizedDaemonSet = YAML.parse(daemonSetFileContents);
2189+
2190+
const clusterRoleFileContent = fs.readFileSync(path.join(__dirname, '..', 'lib', 'addons', 'neuron-device-plugin-rbac-cluster-role.yaml'), 'utf8');
2191+
const sanitizedClusterRole = YAML.parse(clusterRoleFileContent);
2192+
2193+
const clusterRoleBindingFileContents = fs.readFileSync(path.join(__dirname, '..', 'lib', 'addons', 'neuron-device-plugin-rbac-cluster-role-binding.yaml'), 'utf8');
2194+
const sanitizedClusterRoleBinding = YAML.parse(clusterRoleBindingFileContents);
2195+
2196+
const serviceAccountFileContents = fs.readFileSync(path.join(__dirname, '..', 'lib', 'addons', 'neuron-device-plugin-rbac-service-account.yaml'), 'utf8');
2197+
const sanitizedServiceAccount = YAML.parse(serviceAccountFileContents);
21882198

21892199
// THEN
21902200
Template.fromStack(stack).hasResourceProperties(eks.KubernetesManifest.RESOURCE_TYPE, {
2191-
Manifest: JSON.stringify([sanitized]),
2201+
Manifest: JSON.stringify([sanitizedDaemonSet]),
2202+
});
2203+
Template.fromStack(stack).hasResourceProperties(eks.KubernetesManifest.RESOURCE_TYPE, {
2204+
Manifest: JSON.stringify([sanitizedClusterRole]),
2205+
});
2206+
Template.fromStack(stack).hasResourceProperties(eks.KubernetesManifest.RESOURCE_TYPE, {
2207+
Manifest: JSON.stringify([sanitizedClusterRoleBinding]),
2208+
});
2209+
Template.fromStack(stack).hasResourceProperties(eks.KubernetesManifest.RESOURCE_TYPE, {
2210+
Manifest: JSON.stringify([sanitizedServiceAccount]),
21922211
});
21932212
});
21942213
test('inf2 instances are supported', () => {
@@ -2201,12 +2220,31 @@ describe('cluster', () => {
22012220
instanceType: new ec2.InstanceType('inf2.xlarge'),
22022221
minCapacity: 1,
22032222
});
2204-
const fileContents = fs.readFileSync(path.join(__dirname, '..', 'lib', 'addons', 'neuron-device-plugin.yaml'), 'utf8');
2205-
const sanitized = YAML.parse(fileContents);
2223+
2224+
const daemonSetFileContents = fs.readFileSync(path.join(__dirname, '..', 'lib', 'addons', 'neuron-device-plugin.yaml'), 'utf8');
2225+
const sanitizedDaemonSet = YAML.parse(daemonSetFileContents);
2226+
2227+
const clusterRoleFileContent = fs.readFileSync(path.join(__dirname, '..', 'lib', 'addons', 'neuron-device-plugin-rbac-cluster-role.yaml'), 'utf8');
2228+
const sanitizedClusterRole = YAML.parse(clusterRoleFileContent);
2229+
2230+
const clusterRoleBindingFileContents = fs.readFileSync(path.join(__dirname, '..', 'lib', 'addons', 'neuron-device-plugin-rbac-cluster-role-binding.yaml'), 'utf8');
2231+
const sanitizedClusterRoleBinding = YAML.parse(clusterRoleBindingFileContents);
2232+
2233+
const serviceAccountFileContents = fs.readFileSync(path.join(__dirname, '..', 'lib', 'addons', 'neuron-device-plugin-rbac-service-account.yaml'), 'utf8');
2234+
const sanitizedServiceAccount = YAML.parse(serviceAccountFileContents);
22062235

22072236
// THEN
22082237
Template.fromStack(stack).hasResourceProperties(eks.KubernetesManifest.RESOURCE_TYPE, {
2209-
Manifest: JSON.stringify([sanitized]),
2238+
Manifest: JSON.stringify([sanitizedDaemonSet]),
2239+
});
2240+
Template.fromStack(stack).hasResourceProperties(eks.KubernetesManifest.RESOURCE_TYPE, {
2241+
Manifest: JSON.stringify([sanitizedClusterRole]),
2242+
});
2243+
Template.fromStack(stack).hasResourceProperties(eks.KubernetesManifest.RESOURCE_TYPE, {
2244+
Manifest: JSON.stringify([sanitizedClusterRoleBinding]),
2245+
});
2246+
Template.fromStack(stack).hasResourceProperties(eks.KubernetesManifest.RESOURCE_TYPE, {
2247+
Manifest: JSON.stringify([sanitizedServiceAccount]),
22102248
});
22112249
});
22122250
test('trn1 instances are supported', () => {
@@ -2219,12 +2257,31 @@ describe('cluster', () => {
22192257
instanceType: new ec2.InstanceType('trn1.2xlarge'),
22202258
minCapacity: 1,
22212259
});
2222-
const fileContents = fs.readFileSync(path.join(__dirname, '..', 'lib', 'addons', 'neuron-device-plugin.yaml'), 'utf8');
2223-
const sanitized = YAML.parse(fileContents);
2260+
2261+
const daemonSetFileContents = fs.readFileSync(path.join(__dirname, '..', 'lib', 'addons', 'neuron-device-plugin.yaml'), 'utf8');
2262+
const sanitizedDaemonSet = YAML.parse(daemonSetFileContents);
2263+
2264+
const clusterRoleFileContent = fs.readFileSync(path.join(__dirname, '..', 'lib', 'addons', 'neuron-device-plugin-rbac-cluster-role.yaml'), 'utf8');
2265+
const sanitizedClusterRole = YAML.parse(clusterRoleFileContent);
2266+
2267+
const clusterRoleBindingFileContents = fs.readFileSync(path.join(__dirname, '..', 'lib', 'addons', 'neuron-device-plugin-rbac-cluster-role-binding.yaml'), 'utf8');
2268+
const sanitizedClusterRoleBinding = YAML.parse(clusterRoleBindingFileContents);
2269+
2270+
const serviceAccountFileContents = fs.readFileSync(path.join(__dirname, '..', 'lib', 'addons', 'neuron-device-plugin-rbac-service-account.yaml'), 'utf8');
2271+
const sanitizedServiceAccount = YAML.parse(serviceAccountFileContents);
22242272

22252273
// THEN
22262274
Template.fromStack(stack).hasResourceProperties(eks.KubernetesManifest.RESOURCE_TYPE, {
2227-
Manifest: JSON.stringify([sanitized]),
2275+
Manifest: JSON.stringify([sanitizedDaemonSet]),
2276+
});
2277+
Template.fromStack(stack).hasResourceProperties(eks.KubernetesManifest.RESOURCE_TYPE, {
2278+
Manifest: JSON.stringify([sanitizedClusterRole]),
2279+
});
2280+
Template.fromStack(stack).hasResourceProperties(eks.KubernetesManifest.RESOURCE_TYPE, {
2281+
Manifest: JSON.stringify([sanitizedClusterRoleBinding]),
2282+
});
2283+
Template.fromStack(stack).hasResourceProperties(eks.KubernetesManifest.RESOURCE_TYPE, {
2284+
Manifest: JSON.stringify([sanitizedServiceAccount]),
22282285
});
22292286
});
22302287
test('trn1n instances are supported', () => {
@@ -2237,12 +2294,31 @@ describe('cluster', () => {
22372294
instanceType: new ec2.InstanceType('trn1n.2xlarge'),
22382295
minCapacity: 1,
22392296
});
2240-
const fileContents = fs.readFileSync(path.join(__dirname, '..', 'lib', 'addons', 'neuron-device-plugin.yaml'), 'utf8');
2241-
const sanitized = YAML.parse(fileContents);
2297+
2298+
const daemonSetFileContents = fs.readFileSync(path.join(__dirname, '..', 'lib', 'addons', 'neuron-device-plugin.yaml'), 'utf8');
2299+
const sanitizedDaemonSet = YAML.parse(daemonSetFileContents);
2300+
2301+
const clusterRoleFileContent = fs.readFileSync(path.join(__dirname, '..', 'lib', 'addons', 'neuron-device-plugin-rbac-cluster-role.yaml'), 'utf8');
2302+
const sanitizedClusterRole = YAML.parse(clusterRoleFileContent);
2303+
2304+
const clusterRoleBindingFileContents = fs.readFileSync(path.join(__dirname, '..', 'lib', 'addons', 'neuron-device-plugin-rbac-cluster-role-binding.yaml'), 'utf8');
2305+
const sanitizedClusterRoleBinding = YAML.parse(clusterRoleBindingFileContents);
2306+
2307+
const serviceAccountFileContents = fs.readFileSync(path.join(__dirname, '..', 'lib', 'addons', 'neuron-device-plugin-rbac-service-account.yaml'), 'utf8');
2308+
const sanitizedServiceAccount = YAML.parse(serviceAccountFileContents);
22422309

22432310
// THEN
22442311
Template.fromStack(stack).hasResourceProperties(eks.KubernetesManifest.RESOURCE_TYPE, {
2245-
Manifest: JSON.stringify([sanitized]),
2312+
Manifest: JSON.stringify([sanitizedDaemonSet]),
2313+
});
2314+
Template.fromStack(stack).hasResourceProperties(eks.KubernetesManifest.RESOURCE_TYPE, {
2315+
Manifest: JSON.stringify([sanitizedClusterRole]),
2316+
});
2317+
Template.fromStack(stack).hasResourceProperties(eks.KubernetesManifest.RESOURCE_TYPE, {
2318+
Manifest: JSON.stringify([sanitizedClusterRoleBinding]),
2319+
});
2320+
Template.fromStack(stack).hasResourceProperties(eks.KubernetesManifest.RESOURCE_TYPE, {
2321+
Manifest: JSON.stringify([sanitizedServiceAccount]),
22462322
});
22472323
});
22482324

@@ -2255,12 +2331,31 @@ describe('cluster', () => {
22552331
cluster.addNodegroupCapacity('InferenceInstances', {
22562332
instanceTypes: [new ec2.InstanceType('inf1.2xlarge')],
22572333
});
2258-
const fileContents = fs.readFileSync(path.join(__dirname, '..', 'lib', 'addons', 'neuron-device-plugin.yaml'), 'utf8');
2259-
const sanitized = YAML.parse(fileContents);
2334+
2335+
const daemonSetFileContents = fs.readFileSync(path.join(__dirname, '..', 'lib', 'addons', 'neuron-device-plugin.yaml'), 'utf8');
2336+
const sanitizedDaemonSet = YAML.parse(daemonSetFileContents);
2337+
2338+
const clusterRoleFileContent = fs.readFileSync(path.join(__dirname, '..', 'lib', 'addons', 'neuron-device-plugin-rbac-cluster-role.yaml'), 'utf8');
2339+
const sanitizedClusterRole = YAML.parse(clusterRoleFileContent);
2340+
2341+
const clusterRoleBindingFileContents = fs.readFileSync(path.join(__dirname, '..', 'lib', 'addons', 'neuron-device-plugin-rbac-cluster-role-binding.yaml'), 'utf8');
2342+
const sanitizedClusterRoleBinding = YAML.parse(clusterRoleBindingFileContents);
2343+
2344+
const serviceAccountFileContents = fs.readFileSync(path.join(__dirname, '..', 'lib', 'addons', 'neuron-device-plugin-rbac-service-account.yaml'), 'utf8');
2345+
const sanitizedServiceAccount = YAML.parse(serviceAccountFileContents);
22602346

22612347
// THEN
22622348
Template.fromStack(stack).hasResourceProperties(eks.KubernetesManifest.RESOURCE_TYPE, {
2263-
Manifest: JSON.stringify([sanitized]),
2349+
Manifest: JSON.stringify([sanitizedDaemonSet]),
2350+
});
2351+
Template.fromStack(stack).hasResourceProperties(eks.KubernetesManifest.RESOURCE_TYPE, {
2352+
Manifest: JSON.stringify([sanitizedClusterRole]),
2353+
});
2354+
Template.fromStack(stack).hasResourceProperties(eks.KubernetesManifest.RESOURCE_TYPE, {
2355+
Manifest: JSON.stringify([sanitizedClusterRoleBinding]),
2356+
});
2357+
Template.fromStack(stack).hasResourceProperties(eks.KubernetesManifest.RESOURCE_TYPE, {
2358+
Manifest: JSON.stringify([sanitizedServiceAccount]),
22642359
});
22652360
});
22662361
test('inf2 instances are supported in addNodegroupCapacity', () => {
@@ -2272,12 +2367,31 @@ describe('cluster', () => {
22722367
cluster.addNodegroupCapacity('InferenceInstances', {
22732368
instanceTypes: [new ec2.InstanceType('inf2.xlarge')],
22742369
});
2275-
const fileContents = fs.readFileSync(path.join(__dirname, '..', 'lib', 'addons', 'neuron-device-plugin.yaml'), 'utf8');
2276-
const sanitized = YAML.parse(fileContents);
2370+
2371+
const daemonSetFileContents = fs.readFileSync(path.join(__dirname, '..', 'lib', 'addons', 'neuron-device-plugin.yaml'), 'utf8');
2372+
const sanitizedDaemonSet = YAML.parse(daemonSetFileContents);
2373+
2374+
const clusterRoleFileContent = fs.readFileSync(path.join(__dirname, '..', 'lib', 'addons', 'neuron-device-plugin-rbac-cluster-role.yaml'), 'utf8');
2375+
const sanitizedClusterRole = YAML.parse(clusterRoleFileContent);
2376+
2377+
const clusterRoleBindingFileContents = fs.readFileSync(path.join(__dirname, '..', 'lib', 'addons', 'neuron-device-plugin-rbac-cluster-role-binding.yaml'), 'utf8');
2378+
const sanitizedClusterRoleBinding = YAML.parse(clusterRoleBindingFileContents);
2379+
2380+
const serviceAccountFileContents = fs.readFileSync(path.join(__dirname, '..', 'lib', 'addons', 'neuron-device-plugin-rbac-service-account.yaml'), 'utf8');
2381+
const sanitizedServiceAccount = YAML.parse(serviceAccountFileContents);
22772382

22782383
// THEN
22792384
Template.fromStack(stack).hasResourceProperties(eks.KubernetesManifest.RESOURCE_TYPE, {
2280-
Manifest: JSON.stringify([sanitized]),
2385+
Manifest: JSON.stringify([sanitizedDaemonSet]),
2386+
});
2387+
Template.fromStack(stack).hasResourceProperties(eks.KubernetesManifest.RESOURCE_TYPE, {
2388+
Manifest: JSON.stringify([sanitizedClusterRole]),
2389+
});
2390+
Template.fromStack(stack).hasResourceProperties(eks.KubernetesManifest.RESOURCE_TYPE, {
2391+
Manifest: JSON.stringify([sanitizedClusterRoleBinding]),
2392+
});
2393+
Template.fromStack(stack).hasResourceProperties(eks.KubernetesManifest.RESOURCE_TYPE, {
2394+
Manifest: JSON.stringify([sanitizedServiceAccount]),
22812395
});
22822396
});
22832397

0 commit comments

Comments
 (0)