Skip to content

Commit

Permalink
Merge pull request helm#9 from runseb/master
Browse files Browse the repository at this point in the history
Merge original charts from https://github.com/helm/charts.git to Kubernetes charts repository
  • Loading branch information
sebgoa committed Apr 6, 2016
2 parents 646a0e1 + 4c5f0ad commit b7ee119
Show file tree
Hide file tree
Showing 135 changed files with 2,575 additions and 257 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ pkg/*
*.pyc
bin/*
.project
/.bin
/_test/secrets/*.json
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
language: bash

script:
- make lint test
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.PHONY: test
test:
@_test/test-charts $(TEST_CHARTS)

.PHONY: lint
lint:
@_test/lint-charts $(TEST_CHARTS)
30 changes: 30 additions & 0 deletions _test/config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export TEST_ROOT_DIR="$(cd "$(dirname $(dirname $0))"; pwd)"
export HELM_ARTIFACT_REPO="${HELM_ARTIFACT_REPO:-helm-ci}"
CLUSTER_NAME="${CLUSTER_NAME:-helm-testing}"
GOOGLE_SDK_DIR="${HOME}/google-cloud-sdk"
export HELM_BIN="${TEST_ROOT_DIR}/helm.bin"
export TEST_DIR="${TEST_ROOT_DIR}/_test"
export SECRETS_DIR="${TEST_DIR}/secrets"
SKIP_DESTROY=${SKIP_DESTROY:-false}

export HEALTHCHECK_TIMEOUT_SEC=120

GCLOUD_CREDENTIALS_FILE="${GCLOUD_CREDENTIALS_FILE:-"${SECRETS_DIR}/gcloud-credentials.json"}"

GCLOUD_PROJECT_ID="${GCLOUD_PROJECT_ID:-${CLUSTER_NAME}}"
K8S_ZONE="${K8S_ZONE:-us-central1-b}"
K8S_CLUSTER_NAME="${K8S_CLUSTER_NAME:-${GCLOUD_PROJECT_ID}-$(openssl rand -hex 2)}"



# Text color variables
txtund=$(tput sgr 0 1) # Underline
txtbld=$(tput bold) # Bold
bldred=${txtbld}$(tput setaf 1) # red
bldblu=${txtbld}$(tput setaf 4) # blue
bldwht=${txtbld}$(tput setaf 7) # white
txtrst=$(tput sgr0) # Reset

pass="${bldblu}-->${txtrst}"
warn="${bldred}-->${txtrst}"
ques="${bldblu}???${txtrst}"
50 changes: 50 additions & 0 deletions _test/gke.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
function gke::install {
if [ ! -d "${GOOGLE_SDK_DIR}" ]; then
export CLOUDSDK_CORE_DISABLE_PROMPTS=1
curl https://sdk.cloud.google.com | bash
fi

export PATH="${GOOGLE_SDK_DIR}/bin:$PATH"
gcloud -q components update kubectl
}

function gke::login {
if [ -f ${GCLOUD_CREDENTIALS_FILE} ]; then
gcloud -q auth activate-service-account --key-file "${GCLOUD_CREDENTIALS_FILE}"
else
log-warn "No credentials file located at ${GCLOUD_CREDENTIALS_FILE}"
log-warn "You can set this via GCLOUD_CREDENTIALS_FILE"
return 1
fi
}

function gke::config {
gcloud -q config set project "${GCLOUD_PROJECT_ID}"
gcloud -q config set compute/zone "${K8S_ZONE}"
}

function gke::create-cluster {
log-lifecycle "Creating cluster ${K8S_CLUSTER_NAME}"
gcloud -q container clusters create "${K8S_CLUSTER_NAME}"
gcloud -q config set container/cluster "${K8S_CLUSTER_NAME}"
gcloud -q container clusters get-credentials "${K8S_CLUSTER_NAME}"
}

function gke::destroy {
if [ "${SKIP_DESTROY}" == false ]; then
log-lifecycle "Destroying cluster ${K8S_CLUSTER_NAME}"
if command -v gcloud &>/dev/null; then
gcloud -q container clusters delete "${K8S_CLUSTER_NAME}" --no-wait
log-info "Cluster ${K8S_CLUSTER_NAME} scheduled for destruction. Muahaha."
log-info "Set SKIP_DESTROY=true if you don't want cluster destruction-on-exit behavior"
fi
else
log-warn "Skipping destruction of ${K8S_CLUSTER_NAME} (SKIP_DESTROY=${SKIP_DESTROY})"
fi
}

function gke::setup {
gke::install
gke::login
gke::config
}
155 changes: 155 additions & 0 deletions _test/lib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
function move-files {
helm doctor # need proper ~/.helm directory structure and config.yml

log-info "Staging chart directory"
rsync -av . ${HOME}/.helm/cache/charts/
}

function helm::setup {
# Uses HELM_ARTIFACT_REPO to determine which repository to grab helm from

log-lifecycle "Installing helm into $(pwd)/.bin"

mkdir -p .bin
(
cd .bin
curl -s https://get.helm.sh | bash
)
export PATH="$(pwd)/.bin:${PATH}"

move-files
}

function helm::get-changed-charts {
git diff --name-only HEAD origin/HEAD -- charts \
| cut -d/ -f 1-2 \
| sort \
| uniq
}

function ensure-dirs-exist {
local dirs="${@}"
local pruned

# ensure directories exist and just output directory name
for dir in ${dirs}; do
if [ -d ${dir} ]; then
pruned+="$(basename "${dir}")\n"
fi
done

echo -e "${pruned}"
}

function generate-test-plan {
ensure-dirs-exist "$(helm::get-changed-charts)"
}

function get-all-charts {
local chartlist="$(find . -name Chart.yaml)"
local cleanedlist

if [ -z "${TEST_CHARTS}" ]; then
local chart
for chart in ${chartlist}; do
cleanedlist+="$(basename $(dirname ${chart})) "
done
else
cleanedlist="${TEST_CHARTS}"
fi

echo "${cleanedlist}"
}

function helm::test-chart {
log-warn "Start: ${1}"
.bin/helm fetch "${1}"
.bin/helm install "${1}"
helm::healthcheck "${1}"
.bin/helm uninstall -y "${1}"
log-warn "Done: ${1}"
}

function helm::test {
local test_plan

if is-pull-request; then
test_plan="$(generate-test-plan)"
else
test_plan="$(get-all-charts)"
fi

log-lifecycle "Running test plan"
log-info "Charts to be tested:"
echo "${test_plan}"

local plan
for plan in ${test_plan}; do
helm::test-chart ${plan}
done
}

function is-pull-request {
if [ ! -z ${TRAVIS} ] && \
[ ${TRAVIS_PULL_REQUEST} != false ]; then
log-warn "This is a pull request."
return 0
else
return 1
fi
}

function helm::is-pod-running {
local name="${1}"

if kubectl get pods "${name}" &> /dev/null; then
log-info "Looking for pod named ${name}"
local jq_name_query=".status.phase"
kubectl get pods ${name} -o json | jq -r "${jq_name_query}" | grep -q "Running" && return 0
fi

log-info "Looking for label: app=${name}"
local jq_app_label_query=".items[] | select(.metadata.labels.app == \"${name}\") | .status.phase"
kubectl get pods -o json | jq -r "${jq_app_label_query}" | grep -q "Running" && return 0

log-info "Looking for label: provider=${name}"
local jq_provider_label_query=".items[] | select(.metadata.labels.provider == \"${name}\") | .status.phase"
kubectl get pods -o json | jq -r "${jq_provider_label_query}" | grep -q "Running" && return 0

log-info "Looking for label: name=${name}"
local jq_provider_label_query=".items[] | select(.metadata.labels.name == \"${name}\") | .status.phase"
kubectl get pods -o json | jq -r "${jq_provider_label_query}" | grep -q "Running" && return 0
}

function helm::healthcheck {
WAIT_TIME=1
log-lifecycle "Checking: ${1}"
until helm::is-pod-running "${1}"; do
sleep 1
(( WAIT_TIME += 1 ))
if [ ${WAIT_TIME} -gt ${HEALTHCHECK_TIMEOUT_SEC} ]; then
return 1
fi
done
log-lifecycle "Checked!: ${1}"
}

function helm::lint {
local chart
for chart in $(get-all-charts); do
.bin/helm fetch "${chart}"
.bin/helm lint "${chart}"
done
}

function log-lifecycle {
echo "${bldblu}==> ${@}...${txtrst}"
}

function log-info {
echo "${wht}--> ${@}${txtrst}"
}

function log-warn {
echo "${bldred}--> ${@}${txtrst}"
}
16 changes: 16 additions & 0 deletions _test/lint-charts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

set -eo pipefail

source _test/config.sh

cd "${TEST_ROOT_DIR}"

source _test/lib.sh
source _test/gke.sh

gke::install # "need" kubectl for helm

helm::setup

helm::lint
Binary file added _test/secrets/gcloud-credentials.json.enc
Binary file not shown.
33 changes: 33 additions & 0 deletions _test/test-charts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

set -eo pipefail

source _test/config.sh

cd "${TEST_ROOT_DIR}"

source _test/lib.sh
source _test/gke.sh

if [ "${TRAVIS}" == true ]; then
if [ "${TRAVIS_PULL_REQUEST}" != false ]; then
log-lifecycle "This is a pull request build. Skipping chart tests."
exit 0
fi

# decrypt gcloud credentials if on Travis and building the master branch
openssl aes-256-cbc -K $encrypted_e967971bb2cd_key \
-iv $encrypted_e967971bb2cd_iv \
-in _test/secrets/gcloud-credentials.json.enc \
-out _test/secrets/gcloud-credentials.json -d
fi

trap gke::destroy EXIT ERR

gke::setup

helm::setup

gke::create-cluster

helm::test
24 changes: 24 additions & 0 deletions alpine/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: alpine
description: Simple pod running Alpine Linux.
version: 0.1.0
keywords:
- package
- provides
- basic
- alpine
- linux
- image
- used
- basic
- debugging
- troubleshooting
- default
- starts
- sleeps
- long
- time
- eventually
- stops
source:
- https://github.com/kubernetes/charts/tree/master/alpine
home: http://www.alpinelinux.org/
8 changes: 8 additions & 0 deletions alpine/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Alpine

This Chart provides a Pod running Alpine Linux.

## Usage

This pod is for testing and debugging. The standard usage is to connect
using `kubectl exec` and then install the tools you want using `apk`.
12 changes: 12 additions & 0 deletions alpine/templates/alpine-pod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Pod
metadata:
name: alpine
labels:
heritage: helm
spec:
restartPolicy: Never
containers:
- name: waiter
image: "alpine:3.2"
command: ["/bin/sleep","9000"]
11 changes: 11 additions & 0 deletions cassandra/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: cassandra
description: The Apache Cassandra Project.
version: 0.2.1
keywords:
- package
- deploys
- cassandra
- kubernetes
source:
- https://github.com/kubernetes/charts/tree/master/cassandra
home: http://cassandra.apache.org/
3 changes: 3 additions & 0 deletions cassandra/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Cassandra

This Chart deploys Cassandra to kubernetes.
26 changes: 26 additions & 0 deletions cassandra/templates/cassandra-rc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiVersion: v1
kind: ReplicationController
metadata:
name: cassandra
labels:
provider: cassandra
heritage: helm
spec:
replicas: 1
selector:
provider: cassandra
template:
metadata:
name: cassandra
labels:
provider: cassandra
spec:
containers:
- name: cassandra
image: cassandra
ports:
- containerPort: 7000
- containerPort: 7001
- containerPort: 7199
- containerPort: 9042
- containerPort: 9160
Loading

0 comments on commit b7ee119

Please sign in to comment.