Skip to content

Commit

Permalink
Revert "Use chart repository for cloudwatch adapter"
Browse files Browse the repository at this point in the history
This reverts commit a47fe21.
  • Loading branch information
OlamideOl1 committed Oct 31, 2023
1 parent a47fe21 commit 9709073
Show file tree
Hide file tree
Showing 15 changed files with 428 additions and 36 deletions.
4 changes: 0 additions & 4 deletions charts.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,5 @@
"chart": "sloth",
"repository": "https://slok.github.io/sloth",
"version": "0.7.0"
"k8s-cloudwatch-adapter": {
"chart": "k8s-cloudwatch-adapter",
"repository": "https://charts.deliveryhero.io",
"version": "0.2.1"
}
}
5 changes: 0 additions & 5 deletions platform/modules/cloudwatch-adapter/chart.json

This file was deleted.

11 changes: 11 additions & 0 deletions platform/modules/cloudwatch-adapter/chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v2
name: cloudwatch-adapter
description: Configuration for cloudwatch adapter to fetch AWS Cloudwatch metrics in kubernetes

type: application

version: 0.1.0

appVersion: 1.0.0

# Downloaded from https://artifacthub.io/packages/helm/deliveryhero/k8s-cloudwatch-adapter
61 changes: 61 additions & 0 deletions platform/modules/cloudwatch-adapter/chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "k8s-cloudwatch-adapter.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 "k8s-cloudwatch-adapter.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 "k8s-cloudwatch-adapter.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Common labels
*/}}
{{- define "k8s-cloudwatch-adapter.labels" -}}
app.kubernetes.io/name: {{ include "k8s-cloudwatch-adapter.name" . }}
helm.sh/chart: {{ include "k8s-cloudwatch-adapter.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- if .Values.extraLabels }}
{{ toYaml .Values.extraLabels }}
{{- end }}
{{- end -}}

{{/*
Create the name of the service account to use
*/}}
{{- define "k8s-cloudwatch-adapter.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "k8s-cloudwatch-adapter.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
name: v1beta1.external.metrics.k8s.io
spec:
service:
name: {{ include "k8s-cloudwatch-adapter.fullname" . }}
namespace: "{{ .Release.Namespace }}"
group: external.metrics.k8s.io
version: v1beta1
insecureSkipTLSVerify: true
groupPriorityMinimum: 100
versionPriority: 100

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ include "k8s-cloudwatch-adapter.fullname" . }}:crd-metrics-reader
labels:
app: {{ .Release.Name }}
rules:
- apiGroups:
- metrics.aws
resources:
- "externalmetrics"
verbs:
- list
- get
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ include "k8s-cloudwatch-adapter.fullname" . }}-resource-reader
rules:
- apiGroups:
- ""
resources:
- namespaces
- pods
- services
verbs:
- get
- list
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ include "k8s-cloudwatch-adapter.fullname" . }}:external-metrics-reader
rules:
- apiGroups:
- external.metrics.k8s.io
resources: ["*"]
verbs: ["*"]

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ include "k8s-cloudwatch-adapter.fullname" . }}:crd-metrics-reader
labels:
app: {{ .Release.Name }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ include "k8s-cloudwatch-adapter.fullname" . }}:crd-metrics-reader
subjects:
- name: {{ template "k8s-cloudwatch-adapter.serviceAccountName" . }}
namespace: "{{ .Release.Namespace }}"
kind: ServiceAccount
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ include "k8s-cloudwatch-adapter.fullname" . }}-resource-reader
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ include "k8s-cloudwatch-adapter.fullname" . }}-resource-reader
subjects:
- kind: ServiceAccount
name: {{ template "k8s-cloudwatch-adapter.serviceAccountName" . }}
namespace: "{{ .Release.Namespace }}"
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ include "k8s-cloudwatch-adapter.fullname" . }}:external-metrics-reader
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ include "k8s-cloudwatch-adapter.fullname" . }}:external-metrics-reader
subjects:
- kind: ServiceAccount
name: horizontal-pod-autoscaler
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ include "k8s-cloudwatch-adapter.fullname" . }}:system:auth-delegator
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:auth-delegator
subjects:
- kind: ServiceAccount
name: {{ template "k8s-cloudwatch-adapter.serviceAccountName" . }}
namespace: "{{ .Release.Namespace }}"


84 changes: 84 additions & 0 deletions platform/modules/cloudwatch-adapter/chart/templates/crd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{{- if .Capabilities.APIVersions.Has "apiextensions.k8s.io/v1" }}
apiVersion: apiextensions.k8s.io/v1
{{- else }}
apiVersion: apiextensions.k8s.io/v1beta1
{{- end }}
kind: CustomResourceDefinition
metadata:
name: externalmetrics.metrics.aws
spec:
group: metrics.aws
{{- if .Capabilities.APIVersions.Has "apiextensions.k8s.io/v1" }}
versions:
- name: v1alpha1
served: true
storage: true
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
required:
- name
- queries
properties:
name:
type: string
roleArn:
type: string
region:
type: string
queries:
type: array
items:
type: object
properties:
expression:
type: string
id:
type: string
label:
type: string
metricStat:
type: object
properties:
metric:
type: object
required:
- metricName
properties:
dimensions:
type: array
items:
type: object
required:
- name
- value
properties:
name:
type: string
value:
type: string
metricName:
type: string
namespace:
type: string
period:
type: integer
stat:
type: string
unit:
type: string
returnData:
type: boolean
{{- else }}
version: v1alpha1
{{- end }}
names:
kind: ExternalMetric
plural: externalmetrics
singular: externalmetric
scope: Namespaced


Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "k8s-cloudwatch-adapter.fullname" . }}
labels:
{{ include "k8s-cloudwatch-adapter.labels" . | indent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app.kubernetes.io/name: {{ include "k8s-cloudwatch-adapter.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "k8s-cloudwatch-adapter.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ template "k8s-cloudwatch-adapter.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
args:
- /adapter
{{- range $key, $val := .Values.adapter.args }}
- --{{ $key }}={{ $val }}
{{- end }}
ports:
- containerPort: 6443
name: https
- containerPort: 8080
name: http
volumeMounts:
- mountPath: /tmp
name: temp-vol
resources:
{{- toYaml .Values.resources | nindent 10 }}
volumes:
- name: temp-vol
emptyDir: {}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}


Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ include "k8s-cloudwatch-adapter.fullname" . }}-auth-reader
namespace: kube-system
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: extension-apiserver-authentication-reader
subjects:
- kind: ServiceAccount
name: {{ include "k8s-cloudwatch-adapter.fullname" . }}
namespace: "{{ .Release.Namespace }}"

19 changes: 19 additions & 0 deletions platform/modules/cloudwatch-adapter/chart/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "k8s-cloudwatch-adapter.fullname" . }}
labels:
{{ include "k8s-cloudwatch-adapter.labels" . | indent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- name: https
port: 443
targetPort: 6443
- name: http
port: 80
targetPort: 8080
selector:
app.kubernetes.io/name: {{ include "k8s-cloudwatch-adapter.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ template "k8s-cloudwatch-adapter.serviceAccountName" . }}
{{- with .Values.serviceAccount.annotations }}
annotations: {{ toYaml . | nindent 4 }}
{{- end }}
labels:
{{ include "k8s-cloudwatch-adapter.labels" . | indent 4 }}
{{- end -}}

Loading

0 comments on commit 9709073

Please sign in to comment.