diff --git a/src/constructs/eks-cluster.ts b/src/constructs/eks-cluster.ts index a4fc301..a4cad11 100644 --- a/src/constructs/eks-cluster.ts +++ b/src/constructs/eks-cluster.ts @@ -10,6 +10,7 @@ import { CoreDnsAddon, KubeProxyAddon } from './core-addon'; import { VpcCniAddonVersion, VpcEniAddon, + KubeCostAddon, } from '../constructs/eks-managed-addon'; import { @@ -105,6 +106,7 @@ export interface EKSClusterProps { readonly addonProps?: AddonProps; readonly coreDnsAddonProps?: CoreAddonValuesProps; readonly kubeProxyAddonProps?: CoreAddonValuesProps; + readonly kubeCostAddonProps?: KubeCostAddonProps; readonly region: string; } @@ -113,6 +115,11 @@ export interface AddonProps { readonly configurationValues?: string; } +export interface KubeCostAddonProps { + readonly addonVersion?: VpcCniAddonVersion; + readonly configurationValues?: string; +} + export interface CoreAddonValuesProps { readonly addonVersion?: string; readonly configurationValues?: string; @@ -411,6 +418,17 @@ export class EKSCluster extends Construct { }); } + if (props.kubeCostAddonProps) { + const kubeCostAddonConfig = this.props.kubeCostAddonProps?.addonVersion && this.props.kubeCostAddonProps?.configurationValues + ? { addonVersion: this.props.kubeCostAddonProps?.addonVersion, configurationValues: this.props.kubeCostAddonProps?.configurationValues } + : { addonVersion: this.props.kubeCostAddonProps?.addonVersion }; + new KubeCostAddon(this, 'KubeCostAddon', { + cluster: this.cluster, + ...kubeCostAddonConfig, + resolveConflicts: true, + }); + } + const storageclassDefault = new eks.KubernetesManifest(this, 'gp2', { overwrite: true, cluster: this.cluster, diff --git a/src/constructs/eks-managed-addon.ts b/src/constructs/eks-managed-addon.ts index 63ceb7b..7afb350 100644 --- a/src/constructs/eks-managed-addon.ts +++ b/src/constructs/eks-managed-addon.ts @@ -209,3 +209,16 @@ export class VpcEniAddon extends EksManagedAddonAbstract { }); } } + +export class KubeCostAddon extends EksManagedAddonAbstract { + /** + * + */ + constructor(scope: Construct, id: string, props: VpcCniAddonProps) { + super(scope, id, { + ...props, + addonName: 'kubecost_kubecost', + serviceAccountName: 'aws-node', + }); + } +}