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

Adding create Namespace support for Metrics-Server addon #773

Merged
Merged
Changes from 1 commit
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
55 changes: 41 additions & 14 deletions lib/addons/metrics-server/index.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,60 @@
import { ClusterInfo } from "../../spi";
import { HelmAddOn, HelmAddOnProps, HelmAddOnUserProps } from "../helm-addon";
import { Construct } from 'constructs';
import merge from 'ts-deepmerge';
import { ClusterInfo, Values } from '../../spi';
import { HelmAddOn, HelmAddOnProps, HelmAddOnUserProps } from '../helm-addon';
import { createNamespace } from '../../utils';

/**
* Configuration options for the add-on.
*/
type MetricsServerAddOnProps = HelmAddOnUserProps;

export interface MetricsServerAddOnProps extends HelmAddOnUserProps {
/**
* To Create Namespace using CDK
*/
createNamespace?: boolean;
}

/**
* Defaults options for the add-on
*/
const defaultProps: HelmAddOnProps = {
chart: "metrics-server",
repository: "https://kubernetes-sigs.github.io/metrics-server",
version: "3.10.0",
const defaultProps: HelmAddOnProps & MetricsServerAddOnProps = {
chart: 'metrics-server',
repository: 'https://kubernetes-sigs.github.io/metrics-server',
version: '3.10.0',
release: 'blueprints-addon-metrics-server',
name: 'metrics-server',
namespace: 'kube-system'
namespace: 'kube-system',
createNamespace: false,
};

export class MetricsServerAddOn extends HelmAddOn {

private options: MetricsServerAddOnProps;
readonly options: MetricsServerAddOnProps;

constructor(props?: MetricsServerAddOnProps) {
super({ ...defaultProps, ...props });
this.options = this.props;
this.options = this.props as MetricsServerAddOnProps;
}

deploy(clusterInfo: ClusterInfo): void {
this.addHelmChart(clusterInfo, this.options.values);
// deploy(clusterInfo: ClusterInfo): void {
elamaran11 marked this conversation as resolved.
Show resolved Hide resolved
// this.addHelmChart(clusterInfo, this.options.values);
// }

deploy(clusterInfo: ClusterInfo): Promise<Construct> {
const cluster = clusterInfo.cluster;
let values: Values = this.options ?? {};
values = merge(values, this.props.values ?? {});

if (this.options.createNamespace == true) {
// Let CDK Create the Namespace
const namespace = createNamespace(this.options.namespace!, cluster);
const chart = this.addHelmChart(clusterInfo, values);
chart.node.addDependency(namespace);
elamaran11 marked this conversation as resolved.
Show resolved Hide resolved
return Promise.resolve(chart);
} else {
//Namespace is already created
const chart = this.addHelmChart(clusterInfo, values);
return Promise.resolve(chart);
elamaran11 marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}