Skip to content

Commit

Permalink
expanded e2e test and fixed aggressive pod polling (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcgrath207 authored Mar 29, 2024
1 parent 3f4fa5d commit 70be146
Show file tree
Hide file tree
Showing 11 changed files with 368 additions and 29 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ deploy_e2e: init ginkgo crane minikube_new
deploy_e2e_dirty: init
ENV='e2e' ./scripts/deploy.sh

deploy_test_chart:
helm install test ./tests/chart/test -n test --create-namespace

destroy_test_chart:
helm delete -n test test

release-docker:
GITHUB_TOKEN="${GITHUB_TOKEN}" VERSION="${VERSION}" ./scripts/release-docker.sh

Expand Down
14 changes: 2 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,11 @@ func podWatch() {
podDataWaitGroup.Wait()
stopCh := make(chan struct{})
defer close(stopCh)
sharedInformerFactory := informers.NewSharedInformerFactory(clientset, 2*time.Second)
sharedInformerFactory := informers.NewSharedInformerFactory(clientset, time.Duration(sampleInterval)*time.Second)
podInformer := sharedInformerFactory.Core().V1().Pods().Informer()

// Define event handlers for Pod events
eventHandler := cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
p := obj.(*v1.Pod)
getPodData(*p)
},
UpdateFunc: func(oldObj, newObj interface{}) {
p := newObj.(*v1.Pod)
getPodData(*p)
Expand All @@ -263,15 +259,9 @@ func podWatch() {
// Start the informer to begin watching for Pod events
go sharedInformerFactory.Start(stopCh)

// Use a ticker to trigger the watcher every 15 seconds
ticker := time.NewTicker(time.Duration(sampleInterval) * time.Second)
defer ticker.Stop()

// TODO: make this more event driven instead of polling
for {
time.Sleep(time.Duration(sampleInterval) * time.Second)
select {
case <-ticker.C:
log.Debug().Msg("Watching podWatch for Pod events...")
case <-stopCh:
log.Error().Msg("Watcher podWatch stopped.")
os.Exit(1)
Expand Down
11 changes: 7 additions & 4 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function main() {
local external_registry
local internal_registry
local status_code
local time_tag

trap 'trap_func' EXIT ERR

Expand Down Expand Up @@ -55,7 +56,9 @@ function main() {

### Build and Load Images ###

grow_repo_image="k8s-ephemeral-storage-grow-test:latest"
time_tag=$(date +%Y%m%d%H%M%S)

grow_repo_image="k8s-ephemeral-storage-grow-test:${time_tag}"

docker build --build-arg TARGETOS=linux --build-arg TARGETARCH=amd64 -f ../DockerfileTestGrow \
-t "${external_registry}/${grow_repo_image}" -t "${internal_registry}/${grow_repo_image}" ../.
Expand All @@ -64,7 +67,7 @@ function main() {
"${LOCALBIN}/crane" push --insecure /tmp/image.tar "${external_registry}/${grow_repo_image}"
rm /tmp/image.tar

shrink_repo_image="k8s-ephemeral-storage-shrink-test:latest"
shrink_repo_image="k8s-ephemeral-storage-shrink-test:${time_tag}"

docker build --build-arg TARGETOS=linux --build-arg TARGETARCH=amd64 -f ../DockerfileTestShrink \
-t "${external_registry}/${shrink_repo_image}" -t "${internal_registry}/${shrink_repo_image}" ../.
Expand All @@ -74,10 +77,10 @@ function main() {
rm /tmp/image.tar

if [[ $ENV == "debug" ]]; then
image_tag="debug-latest"
image_tag="debug-${time_tag}"
dockerfile="DockerfileDebug"
else
image_tag="latest"
image_tag="${time_tag}"
dockerfile="Dockerfile"
fi

Expand Down
23 changes: 23 additions & 0 deletions tests/chart/test/.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/
24 changes: 24 additions & 0 deletions tests/chart/test/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: test
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.16.0"
62 changes: 62 additions & 0 deletions tests/chart/test/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "test.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 "test.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 "test.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "test.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "test.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
68 changes: 68 additions & 0 deletions tests/chart/test/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "test.fullname" . }}
labels:
{{- include "test.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "test.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "test.labels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "test.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: {{ .Values.service.port }}
protocol: TCP
livenessProbe:
{{- toYaml .Values.livenessProbe | nindent 12 }}
readinessProbe:
{{- toYaml .Values.readinessProbe | nindent 12 }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.volumeMounts }}
volumeMounts:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.volumes }}
volumes:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
13 changes: 13 additions & 0 deletions tests/chart/test/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "test.serviceAccountName" . }}
labels:
{{- include "test.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
automountServiceAccountToken: {{ .Values.serviceAccount.automount }}
{{- end }}
15 changes: 15 additions & 0 deletions tests/chart/test/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 "test.fullname" . }}-test-connection"
labels:
{{- include "test.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": test
spec:
containers:
- name: wget
image: busybox
command: ['wget']
args: ['{{ include "test.fullname" . }}:{{ .Values.service.port }}']
restartPolicy: Never
Loading

0 comments on commit 70be146

Please sign in to comment.