Skip to content

Commit

Permalink
AWS Cost Reporter (#44)
Browse files Browse the repository at this point in the history
* aws cost explorer chart added

* [aws-cost-reporter] remove timezone setting

* exclude aws-cost-reporter chart from testing
  • Loading branch information
cicdteam authored Nov 12, 2023
1 parent fc52469 commit 18c0ff4
Show file tree
Hide file tree
Showing 10 changed files with 391 additions and 0 deletions.
23 changes: 23 additions & 0 deletions charts/aws-cost-reporter/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
8 changes: 8 additions & 0 deletions charts/aws-cost-reporter/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v2
name: aws-cost-reporter
description: AWS Cost Reporter
type: application
version: 1.0.0
appVersion: "v0.1.0"
sources:
- https://github.com/neondatabase/aws-cost-reporter
64 changes: 64 additions & 0 deletions charts/aws-cost-reporter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# aws-cost-reporter

![Version: 1.0.0](https://img.shields.io/badge/Version-1.0.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) [![Lint and Test Charts](https://github.com/neondatabase/helm-charts/actions/workflows/lint-test.yaml/badge.svg)](https://github.com/neondatabase/helm-charts/actions/workflows/lint-test.yaml)

AWS Cost Reporter

## Source Code

* <https://github.com/neondatabase/aws-cost-reporter>

## Installing the Chart

Add Neondatabase chart repository:
```console
$ helm repo add neondatabase https://neondatabase.github.io/helm-charts
```

Install the chart with the release name `aws-cost-reporter` using IRSA to access AWS resources:

```console
$ helm install aws-cost-reporter neondatabase/aws-cost-reporter \
--set slack.token="<Slack App token>" \
--set serviceAccount.roleArn="arn:aws:iam::<AWS account id>:role/<IRSA role name>"
```

Install the chart with the release name `aws-cost-reporter` using AWS credentials to access AWS resources:

```console
$ helm install aws-cost-reporter neondatabase/aws-cost-reporter \
--set slack.token="<Slack App token>" \
--set aws.awsAccessKey="<AWS access key id>" \
--set aws.awsSecretKey="<AWS secret access key>" \
--set aws.awsRegion="eu-east-1"
```

## Values

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| affinity | object | `{}` | Affinity for pod assignment |
| aws | object | `{}` | AWS Credentials if IRSA not used |
| fullnameOverride | string | `""` | String to fully override aws-cost-reporter.fullname template |
| image.pullPolicy | string | `"IfNotPresent"` | image pull policy |
| image.repository | string | `"neondatabase/aws-cost-reporter"` | Image repository |
| image.tag | string | `""` | Overrides the image tag whose default is the chart appVersion. |
| imagePullSecrets | list | `[]` | Specify docker-registry secret names as an array |
| nameOverride | string | `""` | String to partially override aws-cost-reporter.fullname template (will maintain the release name) |
| nodeSelector | object | `{}` | Node labels for pod assignment. |
| podAnnotations | object | `{}` | Annotations for aws-cost-reporter pods |
| podSecurityContext | object | `{}` | aws-cost-reporter's pods Security Context |
| replicaCount | int | `1` | |
| resources | object | `{}` | |
| securityContext | object | `{}` | aws-cost-reporter's containers Security Context |
| serviceAccount.annotations | object | `{}` | Annotations to add to the service account |
| serviceAccount.create | bool | `true` | Specifies whether a service account should be created |
| serviceAccount.name | string | `""` | The name of the service account to use. If not set and create is true, a name is generated using the fullname template |
| serviceAccount.roleArn | string | `""` | AWS IAM Role arn (IRSA) used to access AWS Cost Explorer service |
| slack.channelID | string | `"#general"` | Slack channel ID |
| slack.header | string | `"AWS Cost and Usage :moneybag:"` | Slack message header |
| slack.token | string | `""` | Slack App token |
| tolerations | list | `[]` | Tolerations for pod assignment. |

----------------------------------------------
Autogenerated from chart metadata using [helm-docs v1.9.1](https://github.com/norwoodj/helm-docs/releases/v1.9.1)
37 changes: 37 additions & 0 deletions charts/aws-cost-reporter/README.md.gotmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{{ template "chart.header" . }}
{{ template "chart.versionBadge" . }}{{ template "chart.typeBadge" . }}[![Lint and Test Charts](https://github.com/neondatabase/helm-charts/actions/workflows/lint-test.yaml/badge.svg)](https://github.com/neondatabase/helm-charts/actions/workflows/lint-test.yaml)

{{ template "chart.description" . }}

{{ template "chart.sourcesSection" . }}

## Installing the Chart

Add Neondatabase chart repository:
```console
$ helm repo add neondatabase https://neondatabase.github.io/helm-charts
```

Install the chart with the release name `{{ template "chart.name" . }}` using IRSA to access AWS resources:

```console
$ helm install {{ template "chart.name" . }} neondatabase/aws-cost-reporter \
--set slack.token="<Slack App token>" \
--set serviceAccount.roleArn="arn:aws:iam::<AWS account id>:role/<IRSA role name>"
```

Install the chart with the release name `{{ template "chart.name" . }}` using AWS credentials to access AWS resources:

```console
$ helm install {{ template "chart.name" . }} neondatabase/aws-cost-reporter \
--set slack.token="<Slack App token>" \
--set aws.awsAccessKey="<AWS access key id>" \
--set aws.awsSecretKey="<AWS secret access key>" \
--set aws.awsRegion="eu-east-1"
```

{{ template "chart.requirementsSection" . }}

{{ template "chart.valuesSection" . }}

{{ template "helm-docs.versionFooter" . }}
62 changes: 62 additions & 0 deletions charts/aws-cost-reporter/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "aws-cost-reporter.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "aws-cost-reporter.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "aws-cost-reporter.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "aws-cost-reporter.labels" -}}
helm.sh/chart: {{ include "aws-cost-reporter.chart" . }}
{{ include "aws-cost-reporter.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "aws-cost-reporter.selectorLabels" -}}
app.kubernetes.io/name: {{ include "aws-cost-reporter.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "aws-cost-reporter.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "aws-cost-reporter.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
82 changes: 82 additions & 0 deletions charts/aws-cost-reporter/templates/cronjob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
apiVersion: batch/v1
kind: CronJob
metadata:
name: {{ include "aws-cost-reporter.fullname" . }}
labels:
{{- include "aws-cost-reporter.labels" . | nindent 4 }}
spec:
#timeZone: "Etc/UTC"
schedule: '0 12 * * *'
jobTemplate:
metadata:
name: {{ include "aws-cost-reporter.fullname" . }}
labels:
{{- include "aws-cost-reporter.labels" . | nindent 8 }}
spec:
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 12 }}
{{- end }}
labels:
{{- include "aws-cost-reporter.selectorLabels" . | nindent 12 }}
spec:
restartPolicy: Never
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 12 }}
{{- end }}
serviceAccountName: {{ include "aws-cost-reporter.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 12 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 16 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
env:
- name: SLACK_TOKEN
valueFrom:
secretKeyRef:
name: {{ include "aws-cost-reporter.fullname" . }}
key: slackToken
- name: SLACK_CHANNEL_ID
value: {{ .Values.slack.channelID | quote }}
- name: SLACK_MESSAGE_HEADER
value: {{ .Values.slack.header | quote }}
{{- if .Values.aws }}
{{- if .Values.aws.awsAccessKey }}
- name: AWS_ACCESS_KEY_ID
valueFrom:
secretKeyRef:
name: {{ include "aws-cost-reporter.fullname" . }}
key: awsAccessKey
{{- end }}
{{- if .Values.aws.awsSecretKey }}
- name: AWS_SECRET_ACCESS_KEY
valueFrom:
secretKeyRef:
name: {{ include "aws-cost-reporter.fullname" . }}
key: awsSecretKey
{{- end }}
{{- if .Values.aws.awsRegion }}
- name: AWS_REGION
value: {{ .Values.aws.awsRegion }}
{{- end }}
{{- end }}
resources:
{{- toYaml .Values.resources | nindent 16 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 12 }}
{{- end }}
12 changes: 12 additions & 0 deletions charts/aws-cost-reporter/templates/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ include "aws-cost-reporter.fullname" . }}
labels:
{{- include "aws-cost-reporter.labels" . | nindent 4 }}
type: Opaque
stringData:
slackToken: {{ .Values.slack.token | quote }}
{{- with .Values.aws }}
{{- toYaml . | nindent 2 }}
{{- end }}
18 changes: 18 additions & 0 deletions charts/aws-cost-reporter/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "aws-cost-reporter.serviceAccountName" . }}
labels:
{{- include "aws-cost-reporter.labels" . | nindent 4 }}
{{- if or .Values.serviceAccount.annotations .Values.serviceAccount.roleArn }}
annotations:
{{- with .Values.serviceAccount.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- if .Values.serviceAccount.roleArn }}
eks.amazonaws.com/role-arn: {{ .Values.serviceAccount.roleArn | quote }}
{{- end }}
{{- end }}
automountServiceAccountToken: false
{{- end }}
82 changes: 82 additions & 0 deletions charts/aws-cost-reporter/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Default values for aws-cost-reporter.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

replicaCount: 1

image:
# -- Image repository
repository: neondatabase/aws-cost-reporter
# -- image pull policy
pullPolicy: IfNotPresent
# -- Overrides the image tag whose default is the chart appVersion.
tag: ""

# -- Specify docker-registry secret names as an array
imagePullSecrets: []
# -- String to partially override aws-cost-reporter.fullname template (will maintain the release name)
nameOverride: ""
# -- String to fully override aws-cost-reporter.fullname template
fullnameOverride: ""

serviceAccount:
# -- Specifies whether a service account should be created
create: true
# -- Annotations to add to the service account
annotations: {}
# -- The name of the service account to use.
# If not set and create is true, a name is generated using the fullname template
name: ""
# -- AWS IAM Role arn (IRSA) used to access AWS Cost Explorer service
roleArn: ""

slack:
# -- Slack App token
token: ""
# -- Slack channel ID
channelID: "#general"
# -- Slack message header
header: "AWS Cost and Usage :moneybag:"

# -- AWS Credentials if IRSA not used
aws: {}
# awsAccessKey: YOURACCESSKEY
# awsSecretKey: YourSecretKey
# awsRegion: eu-east-1

# -- Annotations for aws-cost-reporter pods
podAnnotations: {}

# -- aws-cost-reporter's pods Security Context
podSecurityContext: {}
# fsGroup: 2000

# -- aws-cost-reporter's containers Security Context
securityContext: {}
# capabilities:
# drop:
# - ALL
# readOnlyRootFilesystem: true
# runAsNonRoot: true
# runAsUser: 1000

resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi

# -- Node labels for pod assignment.
nodeSelector: {}

# -- Tolerations for pod assignment.
tolerations: []

# -- Affinity for pod assignment
affinity: {}
Loading

0 comments on commit 18c0ff4

Please sign in to comment.