Skip to content
This repository has been archived by the owner on Feb 22, 2022. It is now read-only.

Commit

Permalink
[WIP][CI] Use factored out testing lib
Browse files Browse the repository at this point in the history
  • Loading branch information
unguiculus committed Apr 24, 2018
1 parent 41707b2 commit 37c1e0e
Show file tree
Hide file tree
Showing 29 changed files with 420 additions and 832 deletions.
25 changes: 14 additions & 11 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
version: 2
jobs:
build:
docker:
- image: circleci/python:3.6.4
steps:
- checkout
- run:
name: install tools
command: test/circle/install.sh
- run:
name: lint
command: test/circle/lint.sh
build:
docker:
- image: unguiculus/chart-testing
steps:
- checkout
- run:
name: environment
command: env && ls -al /testing
- run:
name: lint
command: |
git remote add k8s https://github.com/kubernetes/charts
git fetch k8s master
chart_test.sh --config test/.testenv --no-install
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ Session.vim
.netrwhist

# Chart dependencies
**/charts/*.tgz
**/charts/*.tgz

.history
21 changes: 21 additions & 0 deletions stable/dummy/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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
*~
# Various IDEs
.project
.idea/
*.tmproj
8 changes: 8 additions & 0 deletions stable/dummy/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
appVersion: "1.0"
description: A Helm chart for Kubernetes
name: dummy
version: 0.1.0
home: https://github.com/kubernetes/charts
maintainers:
- name: unguiculus
Empty file added stable/dummy/ci/ci-values.yaml
Empty file.
19 changes: 19 additions & 0 deletions stable/dummy/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range .Values.ingress.hosts }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ . }}{{ $.Values.ingress.path }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "dummy.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get svc -w {{ template "dummy.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "dummy.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app={{ template "dummy.name" . }},release={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl port-forward $POD_NAME 8080:80
{{- end }}
32 changes: 32 additions & 0 deletions stable/dummy/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "dummy.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 "dummy.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 "dummy.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
51 changes: 51 additions & 0 deletions stable/dummy/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: {{ template "dummy.fullname" . }}
labels:
app: {{ template "dummy.name" . }}
chart: {{ template "dummy.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: {{ template "dummy.name" . }}
release: {{ .Release.Name }}
template:
metadata:
labels:
app: {{ template "dummy.name" . }}
release: {{ .Release.Name }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: 80
protocol: TCP
livenessProbe:
httpGet:
path: /
port: http
readinessProbe:
httpGet:
path: /
port: http
resources:
{{ toYaml .Values.resources | indent 12 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{ toYaml . | indent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{ toYaml . | indent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{ toYaml . | indent 8 }}
{{- end }}
39 changes: 39 additions & 0 deletions stable/dummy/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "dummy.fullname" . -}}
{{- $servicePort := .Values.service.port -}}
{{- $ingressPath := .Values.ingress.path -}}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
app: {{ template "dummy.name" . }}
chart: {{ template "dummy.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
{{- with .Values.ingress.annotations }}
annotations:
{{ toYaml . | indent 4 }}
{{- end }}
spec:
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ . }}
http:
paths:
- path: {{ $ingressPath }}
backend:
serviceName: {{ $fullName }}
servicePort: http
{{- end }}
{{- end }}
19 changes: 19 additions & 0 deletions stable/dummy/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: v1
kind: Service
metadata:
name: {{ template "dummy.fullname" . }}
labels:
app: {{ template "dummy.name" . }}
chart: {{ template "dummy.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
app: {{ template "dummy.name" . }}
release: {{ .Release.Name }}
45 changes: 45 additions & 0 deletions stable/dummy/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Default values for dummy.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

replicaCount: 1

image:
repository: nginx
tag: stable
pullPolicy: IfNotPresent

service:
type: ClusterIP
port: 80

ingress:
enabled: false
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
path: /
hosts:
- chart-example.local
tls: []
# - secretName: chart-example-tls
# hosts:
# - chart-example.local

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

nodeSelector: {}

tolerations: []

affinity: {}
2 changes: 2 additions & 0 deletions test/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
! .testenv
17 changes: 17 additions & 0 deletions test/.testenv
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# The name of the Git remote
REMOTE=k8s

# The name of the Git target branch
TARGET_BRANCH=master

# Chart directories separated by a space
CHART_DIRS="stable incubator"

# Charts the should be skipped
EXCLUDED_CHART_DIRS=

# Additional chart repos to add (<name>=<url>), separated by a space
CHART_REPOS=incubator=https://kubernetes-charts-incubator.storage.googleapis.com/

TIMEOUT=600

59 changes: 19 additions & 40 deletions test/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016 The Kubernetes Authors All rights reserved.
# Copyright 2018 The Kubernetes Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -12,45 +12,24 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM debian:8.5
FROM gcr.io/kubernetes-charts-ci/chart-testing:v1.0.0-alpha.1

ENV CLOUDSDK_CORE_DISABLE_PROMPTS=1 \
PATH=/opt/google-cloud-sdk/bin:$PATH \
GOOGLE_CLOUD_SDK_VERSION=154.0.0 \
GOOGLE_PROJECT=kubernetes-charts-ci
USER root

RUN set -x \
&& cd /opt \
&& echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections \
&& apt-get update \
&& apt-get install --no-install-recommends -y jq wget python git localepurge ca-certificates \
&& wget -q https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-${GOOGLE_CLOUD_SDK_VERSION}-linux-x86_64.tar.gz \
&& tar zxfv google-cloud-sdk-${GOOGLE_CLOUD_SDK_VERSION}-linux-x86_64.tar.gz \
&& ./google-cloud-sdk/install.sh \
&& gcloud components install kubectl \
&& gcloud config set project ${GOOGLE_PROJECT}
RUN apt-get -y purge localepurge \
&& apt-get clean \
&& cd / \
&& rm -rf \
/opt/google-cloud-sdk-${GOOGLE_CLOUD_SDK_VERSION}-linux-x86_64.tar.gz \
/opt/helm-${HELM_VERSION}-linux-amd64.tar.gz \
doc \
man \
info \
locale \
/var/lib/apt/lists/* \
/var/log/* \
/var/cache/debconf/* \
common-licenses \
~/.bashrc \
/etc/systemd \
/lib/lsb \
/lib/udev \
/usr/share/doc/ \
/usr/share/doc-base/ \
/usr/share/man/ \
/tmp/*
ENV PATH /google-cloud-sdk/bin:$PATH
ARG CLOUD_SDK_VERSION=198.0.0
RUN curl -LO "https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-$CLOUD_SDK_VERSION-linux-x86_64.tar.gz" && \
tar xzf "google-cloud-sdk-$CLOUD_SDK_VERSION-linux-x86_64.tar.gz" && \
rm "google-cloud-sdk-$CLOUD_SDK_VERSION-linux-x86_64.tar.gz" && \
ln -s /lib /lib64 && \
rm -rf /google-cloud-sdk/.install/.backup && \
gcloud version

VOLUME "/src"
WORKDIR "/src"
USER testing

RUN gcloud config set core/disable_usage_reporting true && \
gcloud config set component_manager/disable_update_check true && \
gcloud config set metrics/environment github_docker_image

WORKDIR /workdir
COPY .testenv /workdir/
13 changes: 2 additions & 11 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,10 @@ The configuration of the Pull Request trigger is [in the config.json](https://gi

This snippet tells Test Infra to run the [test/e2e.sh](https://github.com/kubernetes/charts/blob/master/test/e2e.sh)
when testing is triggered on a pull request. The e2e.sh script will use the [Charts test image](https://github.com/kubernetes/charts/blob/master/test/Dockerfile)
to run the [test/changed.sh](https://github.com/kubernetes/charts/blob/master/test/changed.sh) script. This script
to run the [chart_test.sh](https://github.com/kubernetes-helm/chart-testing/blob/master/chart_test.sh) script. This script
is the main logic for validation of a pull request. It intends to only test charts that have changed in this PR.

The logic is as follows:

1. [Get credentials for the Kubernetes cluster used for testing.](https://github.com/kubernetes/charts/blob/master/test/changed.sh#L128)
1. [Install and initialize Helm](https://github.com/kubernetes/charts/blob/master/test/changed.sh#L143)
1. [For any charts that have changed](https://github.com/kubernetes/charts/blob/master/test/changed.sh#L161):
- Download dependent charts, if any, with `helm dep build`
- Run `helm install` in a new namespace for this PR build
- Use the [test/verify-release.sh](https://github.com/kubernetes/charts/blob/master/test/verify-release.sh) to ensure that if any pods were launched that they get to the `Running` state
- Run `helm test` on the release
- Delete the release
The testing logic has been extrated to the [chart-testing](https://github.com/kubernetes-helm/chart-testing) project. A bash library provides the required logic to lint, install, and test charts. It is provided as a Docker image and can be run by anyone on their own charts.

#### Providing Custom Test Values

Expand Down
Loading

0 comments on commit 37c1e0e

Please sign in to comment.