|
| 1 | +import { Construct } from 'constructs'; |
| 2 | +import { aws_iam as iam, Stack, StackProps } from 'aws-cdk-lib'; |
| 3 | +import { aws_eks as eks } from 'aws-cdk-lib'; |
| 4 | + |
| 5 | +export interface AWSFluentBitProps extends StackProps { |
| 6 | + cluster: eks.Cluster |
| 7 | + namespace: string |
| 8 | +} |
| 9 | + |
| 10 | +export class AWSFluentBit extends Construct { |
| 11 | + constructor(scope: Construct, id: string, props: AWSFluentBitProps) { |
| 12 | + super(scope, id) |
| 13 | + const ns = props.cluster.addManifest('aws-fluent-bit-namespace', { |
| 14 | + apiVersion: 'v1', |
| 15 | + kind: 'Namespace', |
| 16 | + metadata: { |
| 17 | + name: props.namespace |
| 18 | + } |
| 19 | + }) |
| 20 | + |
| 21 | + // Controller Role |
| 22 | + const sa = props.cluster.addServiceAccount('aws-fluent-bit-sa', { |
| 23 | + name: "fluent-bit", |
| 24 | + namespace: props.namespace |
| 25 | + }) |
| 26 | + sa.node.addDependency(ns) |
| 27 | + sa.role.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('CloudWatchAgentServerPolicy')) |
| 28 | + sa.role.attachInlinePolicy(new iam.Policy(this, 'aws-fluent-bit-inline-policy', { |
| 29 | + statements: [ |
| 30 | + new iam.PolicyStatement({ |
| 31 | + resources: ['*'], |
| 32 | + actions: [ |
| 33 | + "logs:PutRetentionPolicy", |
| 34 | + ], |
| 35 | + }), |
| 36 | + ], |
| 37 | + })); |
| 38 | + |
| 39 | + |
| 40 | + const chart = props.cluster.addHelmChart('aws-fluent-bit-chart', { |
| 41 | + chart: 'aws-for-fluent-bit', |
| 42 | + release: 'aws-fluent-bit', |
| 43 | + repository: 'https://aws.github.io/eks-charts', |
| 44 | + namespace: props.namespace, |
| 45 | + createNamespace: false, |
| 46 | + values: { |
| 47 | + serviceAccount: { |
| 48 | + create: false, |
| 49 | + name: 'fluent-bit', |
| 50 | + }, |
| 51 | + cloudWatch: { |
| 52 | + region: Stack.of(this).region, |
| 53 | + logRetentionDays: "90", |
| 54 | + logKey: "log", |
| 55 | + logGroupName: Stack.of(this).stackName, |
| 56 | + }, |
| 57 | + firehose: { |
| 58 | + enabled: false, |
| 59 | + }, |
| 60 | + kinesis: { |
| 61 | + enabled: false, |
| 62 | + }, |
| 63 | + elasticsearch: { |
| 64 | + enabled: false, |
| 65 | + }, |
| 66 | + tolerations: [ |
| 67 | + { |
| 68 | + key: 'CriticalAddonsOnly', |
| 69 | + operator: 'Exists', |
| 70 | + }, |
| 71 | + ], |
| 72 | + } |
| 73 | + }) |
| 74 | + chart.node.addDependency(ns) |
| 75 | + } |
| 76 | +} |
0 commit comments