Skip to content

Commit

Permalink
refactored keda addon to add createNamespace option
Browse files Browse the repository at this point in the history
  • Loading branch information
shapirov103 committed Oct 23, 2024
1 parent 1180981 commit 4c33a34
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions lib/addons/keda/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ export interface KedaAddOnProps extends HelmAddOnUserProps {
*/
irsaRoles?: string[];

/**
* If set to true the namespace will be created. Default is true, since namespace is set to keda.
* Set to false if installing to kube-system or other existing namespace.
*/
createNamespace?: boolean,
}

/**
Expand All @@ -64,7 +69,8 @@ const defaultProps: HelmAddOnProps & KedaAddOnProps = {
values: {},
kedaOperatorName: "keda-operator",
kedaServiceAccountName: "keda-operator",
irsaRoles: []
irsaRoles: [],
createNamespace: true
};

/**
Expand All @@ -85,25 +91,26 @@ export class KedaAddOn extends HelmAddOn {
let values: Values = populateValues(this.options);
values = merge(values, this.props.values ?? {});

const namespace = createNamespace(this.options.namespace! , cluster);
let namespace: Construct | undefined = undefined;

if(this.options.createNamespace) {
namespace = createNamespace(this.options.namespace! , cluster);
}
const chart = this.addHelmChart(clusterInfo, values);

if (this.options.irsaRoles!.length > 0) {
//Create Service Account with IRSA
const opts = { name: this.options.kedaOperatorName, namespace: this.options.namespace };
const sa = cluster.addServiceAccount(this.options.kedaServiceAccountName!, opts);
setRoles(sa,this.options.irsaRoles!);
sa.node.addDependency(namespace);

const chart = this.addHelmChart(clusterInfo, values);
setRoles(sa, this.options.irsaRoles!);
if(namespace) {
sa.node.addDependency(namespace);
}
chart.node.addDependency(sa);
return Promise.resolve(chart);

} else {
//Let Keda Create Service account for you. This is controlled by flag helmOptions.createServiceAccount (refer line no:118)
const chart = this.addHelmChart(clusterInfo, values);
} else if(namespace) {
chart.node.addDependency(namespace);
return Promise.resolve(chart);
}
return Promise.resolve(chart);
}
}

Expand Down

0 comments on commit 4c33a34

Please sign in to comment.