Skip to content

Commit

Permalink
Add helper and tests to helm chart (#3)
Browse files Browse the repository at this point in the history
* Add helper and tests to helm chart

* Fix registry vs repository name problem
  • Loading branch information
TerryHowe authored Apr 14, 2022
1 parent 8b5348f commit e37bb5c
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 61 deletions.
63 changes: 63 additions & 0 deletions charts/hello-eks-anywhere/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,66 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "hello-eks-anywhere.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 "hello-eks-anywhere.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 "hello-eks-anywhere.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

{{/*
Selector labels
*/}}
{{- define "hello-eks-anywhere.selectorLabels" -}}
app.kubernetes.io/name: {{ include "hello-eks-anywhere.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

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

{{/*
Create image name
*/}}
Expand Down
54 changes: 0 additions & 54 deletions charts/hello-eks-anywhere/templates/app.yaml

This file was deleted.

42 changes: 42 additions & 0 deletions charts/hello-eks-anywhere/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-eks-anywhere
labels:
app: hello-eks-anywhere
spec:
replicas: 1
selector:
matchLabels:
app: hello-eks-anywhere
template:
metadata:
labels:
app: hello-eks-anywhere
spec:
containers:
- name: hello
image: {{.Values.sourceRegistry}}{{ template "template.image" .Values }}
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
env:
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: TITLE
value: {{ .Values.title | quote}}
- name: SUBTITLE
value: {{ .Values.subtitle | quote}}
resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
cpu: "500m"
10 changes: 10 additions & 0 deletions charts/hello-eks-anywhere/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "hello-eks-anywhere.fullname" . }}
spec:
type: LoadBalancer
selector:
app: hello-eks-anywhere
ports:
- port: 80
15 changes: 15 additions & 0 deletions charts/hello-eks-anywhere/templates/tests/test-connection.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Pod
metadata:
name: "{{ include "hello-eks-anywhere.fullname" . }}-test-connection"
labels:
{{- include "hello-eks-anywhere.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": test
spec:
containers:
- name: curl
image: public.ecr.aws/eks-distro-build-tooling/eks-distro-base:latest
command: ['curl']
args: ['{{ include "hello-eks-anywhere.fullname" . }}:80']
restartPolicy: Never
9 changes: 2 additions & 7 deletions charts/hello-eks-anywhere/values.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
namespace: eksa-packages

sourceRegistry: "public.ecr.aws/aws-containers"

repository: "hello-eks-anywhere"

tag: "{{hello-eks-anywhere}}"

config1: "test1"

config2: "test2"
title: "Amazon EKS Anywhere"
subtitle: "Run EKS in your datacenter"

0 comments on commit e37bb5c

Please sign in to comment.