From fb4766ee3d7b4865d874b676c047f62fb1c05b15 Mon Sep 17 00:00:00 2001 From: sm-utkarsh Date: Wed, 27 Nov 2024 14:42:33 +0530 Subject: [PATCH] chore: onboarding kubecost addon --- src/constructs/core-addon.ts | 12 ++++++++++++ src/constructs/eks-cluster.ts | 16 ++++++---------- src/constructs/eks-managed-addon.ts | 16 ++-------------- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/constructs/core-addon.ts b/src/constructs/core-addon.ts index 7cbb7d4..1725b84 100644 --- a/src/constructs/core-addon.ts +++ b/src/constructs/core-addon.ts @@ -92,4 +92,16 @@ export class KubeProxyAddon extends CoreAddonAbstract { serviceAccountName: 'kube-proxy', }); } +} + +export class KubeCostAddon extends CoreAddonAbstract { + /** + * + */ + constructor(scope: Construct, id: string, props: CoreAddonProps) { + super(scope, id, { + ...props, + addonName: 'kubecost_kubecost', + }); + } } \ No newline at end of file diff --git a/src/constructs/eks-cluster.ts b/src/constructs/eks-cluster.ts index a4cad11..80293e9 100644 --- a/src/constructs/eks-cluster.ts +++ b/src/constructs/eks-cluster.ts @@ -6,11 +6,10 @@ import * as kms from 'aws-cdk-lib/aws-kms'; import * as lambda from 'aws-cdk-lib/aws-lambda'; import { Construct } from 'constructs'; import { CommonHelmCharts, StandardHelmProps } from './common-helm-charts'; -import { CoreDnsAddon, KubeProxyAddon } from './core-addon'; +import { CoreDnsAddon, KubeProxyAddon, KubeCostAddon } from './core-addon'; import { VpcCniAddonVersion, VpcEniAddon, - KubeCostAddon, } from '../constructs/eks-managed-addon'; import { @@ -106,7 +105,7 @@ export interface EKSClusterProps { readonly addonProps?: AddonProps; readonly coreDnsAddonProps?: CoreAddonValuesProps; readonly kubeProxyAddonProps?: CoreAddonValuesProps; - readonly kubeCostAddonProps?: KubeCostAddonProps; + readonly kubeCostAddonProps?: CoreAddonValuesProps; readonly region: string; } @@ -115,11 +114,6 @@ export interface AddonProps { readonly configurationValues?: string; } -export interface KubeCostAddonProps { - readonly addonVersion?: VpcCniAddonVersion; - readonly configurationValues?: string; -} - export interface CoreAddonValuesProps { readonly addonVersion?: string; readonly configurationValues?: string; @@ -419,16 +413,18 @@ export class EKSCluster extends Construct { } if (props.kubeCostAddonProps) { - const kubeCostAddonConfig = this.props.kubeCostAddonProps?.addonVersion && this.props.kubeCostAddonProps?.configurationValues + const kubeDnsAddonConfig = 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, + ...kubeDnsAddonConfig, 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 7afb350..ff3b401 100644 --- a/src/constructs/eks-managed-addon.ts +++ b/src/constructs/eks-managed-addon.ts @@ -2,6 +2,7 @@ import * as cdk from 'aws-cdk-lib'; import * as eks from 'aws-cdk-lib/aws-eks'; import * as iam from 'aws-cdk-lib/aws-iam'; import { Construct } from 'constructs'; + export interface VpcCniAddonProps extends EksManagedAddonProps { readonly addonVersion?: VpcCniAddonVersion; readonly configurationValues?: string; @@ -208,17 +209,4 @@ export class VpcEniAddon extends EksManagedAddonAbstract { awsManagedPolicyName: 'AmazonEKS_CNI_Policy', }); } -} - -export class KubeCostAddon extends EksManagedAddonAbstract { - /** - * - */ - constructor(scope: Construct, id: string, props: VpcCniAddonProps) { - super(scope, id, { - ...props, - addonName: 'kubecost_kubecost', - serviceAccountName: 'aws-node', - }); - } -} +} \ No newline at end of file