From a5b20395dfe68c74a6d957c5e8d8faddfdcddb5c Mon Sep 17 00:00:00 2001 From: shapirov Date: Mon, 21 Oct 2024 23:53:45 -0400 Subject: [PATCH] Fixes #1077 - added createNamespace option, if set to true will create namespace --- lib/addons/efs-csi-driver/index.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/addons/efs-csi-driver/index.ts b/lib/addons/efs-csi-driver/index.ts index b2e58c014..8ac886031 100644 --- a/lib/addons/efs-csi-driver/index.ts +++ b/lib/addons/efs-csi-driver/index.ts @@ -4,7 +4,7 @@ import { HelmAddOn, HelmAddOnUserProps } from "../helm-addon"; import { getEfsDriverPolicyStatements } from "./iam-policy"; import { registries } from "../../utils/registry-utils"; import * as iam from "aws-cdk-lib/aws-iam"; -import { setPath, supportsALL} from "../../utils"; +import { createNamespace, setPath, supportsALL} from "../../utils"; import * as kms from "aws-cdk-lib/aws-kms"; @@ -31,6 +31,11 @@ export interface EfsCsiDriverProps extends HelmAddOnUserProps { */ kmsKeys?: kms.Key[]; + /** + * Create Namespace with the provided one (will not if namespace is kube-system) + */ + createNamespace?: boolean + } /** @@ -42,7 +47,8 @@ const defaultProps: EfsCsiDriverProps = { repository: "https://kubernetes-sigs.github.io/aws-efs-csi-driver/", name: EFS_CSI_DRIVER, chart: EFS_CSI_DRIVER, - replicaCount: 2 + replicaCount: 2, + createNamespace: false }; @supportsALL @@ -62,10 +68,16 @@ export class EfsCsiDriverAddOn extends HelmAddOn { name: EFS_CSI_CONTROLLER_SA, namespace: this.options.namespace, }); + getEfsDriverPolicyStatements(this.options?.kmsKeys).forEach((statement) => { serviceAccount.addToPrincipalPolicy(iam.PolicyStatement.fromJson(statement)); }); + // Create namespace + if (this.options.createNamespace) { + const ns = createNamespace(this.options.namespace!, cluster, true); + serviceAccount.node.addDependency(ns); + } // Lookup appropriate image repo const repo = registries.get(clusterInfo.cluster.stack.region) + EFS_REGISTRY_SUFFIX;