Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to match kubernetes 'charts' repo #59

Merged
merged 8 commits into from
Feb 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.swp
.DS_Store
106 changes: 97 additions & 9 deletions helm-charts/deploy_charts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Mihir Shah
# Dhyey Shah
#
# Version: 5 September 2017
# Version: 7 December 2017
#

#
Expand All @@ -19,6 +19,46 @@ function checkDependencies() {
type helm >/dev/null 2>&1 || { echo >&2 "I require helm but it is not installed. Aborting."; exit 1; }
}

#
# colorEcho: Prints the user specified string to the screen using the specified color.
# If no color is provided, the default no color option is used.
#
# Parameters: ${1} - The string to print.
# ${2} - The color to use for printing the string.
#
# NOTE: The following color options are available:
#
# [0|1]30, [dark|light] black
# [0|1]31, [dark|light] red
# [0|1]32, [dark|light] green
# [0|1]33, [dark|light] brown
# [0|1]34, [dark|light] blue
# [0|1]35, [dark|light] purple
# [0|1]36, [dark|light] cyan
#
function colorEcho() {
# Check for proper usage
if [[ ${#} == 0 || ${#} > 2 ]]; then
echo "usage: ${FUNCNAME} <string> [<0|1>3<0-6>]"
return -1
fi

# Set default color to white
MSSG=${1}
CLRCODE=${2}
LIGHTDARK=1
MSGCOLOR=0

# If color code was provided, then set it
if [[ ${#} == 2 ]]; then
LIGHTDARK=${CLRCODE:0:1}
MSGCOLOR=${CLRCODE:1}
fi

# Print out the message
echo -e -n "${MSSG}" | awk '{print "\033['${LIGHTDARK}';'${MSGCOLOR}'m" $0 "\033[1;0m"}'
}

#
# cleanEnvironment: Cleans the services, volumes, and pods from the Kubernetes cluster.
#
Expand All @@ -30,11 +70,12 @@ function cleanEnvironment() {
echo -n "Deleting the following helm releases: "
echo ${HELM_RELEASES}...
helm delete --purge ${HELM_RELEASES}
sleep 2
fi

# Wipe the /shared persistent volume if it exists (it should be removed with chart removal)
kubectl get pv shared > /dev/null 2>&1
if [[ $? -eq 0 ]]; then
if [[ ${?} -eq 0 ]]; then
kubectl create -f ../cs-offerings/kube-configs/wipe_shared.yaml

# Wait for the wipe shared pod to finish
Expand Down Expand Up @@ -81,33 +122,75 @@ function checkPodStatus() {
# Wait for the pods to initialize
while [ "${PODS_RUNNING}" -ne ${NUM_RUNNING} ] || [ "${PODS_COMPLETED}" -ne ${NUM_COMPLETED} ]; do
if [ "${PODS_ERROR}" -gt 0 ]; then
echo "$(basename $0): error: the following pods failed with errors:"
echo "$(echo "$PODS" | grep Error)"
colorEcho "\n$(basename $0): error: the following pods failed with errors:" 131
colorEcho "$(echo "$PODS" | grep Error)" 131

# Show the logs for failed pods
for i in $(echo "$PODS" | grep Error | awk '{print $1}'); do
# colorEcho "\n$ kubectl describe pod ${i}" 132
# kubectl describe pod "${i}"

if [[ ${i} =~ .*channel-create.* ]]; then
colorEcho "\n$ kubectl logs ${i} createchanneltx" 132
kubectl logs "${i}" "createchanneltx"

colorEcho "\n$ kubectl logs ${i} createchannel" 132
kubectl logs "${i}" "createchannel"
else
colorEcho "\n$ kubectl logs ${i}" 132
kubectl logs "${i}"
fi
done


# Show the event warnings
# EVENT_WARNINGS=$(kubectl get events | grep Warning)
# if [[ ! -z ${EVENT_WARNINGS// /} ]]; then
# colorEcho "\n$ kubectl get events | grep Warning" 132
# echo "${EVENT_WARNINGS}"
# fi

exit -1
fi

echo "Waiting for the pods to initialize..."
sleep 1
colorEcho "Waiting for the pods to initialize..." 134
sleep 2

getPodStatus
done

colorEcho "Pods initialized successfully!\n" 134
}

#
# lintChart: Lints the helm chart in the current working directory.
#
function lintChart() {
LINT_OUTPUT=$(helm lint .)

if [[ ${?} -ne 0 ]]; then
colorEcho "\n$(basename $0): error: '$(basename $(pwd))' linting failed with errors:" 131
colorEcho "${LINT_OUTPUT}" 131
exit -1
fi
}

#
# startNetwork: Starts the CA, orderer, and peer containers.
#
function startNetwork() {
RELEASE_NAME="blockchain"
RELEASE_NAME="network"
TOTAL_RUNNING=4
TOTAL_COMPLETED=1

# Move into the directory
pushd ibm-blockchain-network >/dev/null 2>&1

# Install the chart
lintChart
colorEcho "\n$ helm install --name ${RELEASE_NAME} ." 132
helm install --name ${RELEASE_NAME} .


# Ensure the correct number of pods are running and completed
checkPodStatus ${TOTAL_RUNNING} ${TOTAL_COMPLETED}

Expand All @@ -126,9 +209,10 @@ function startChannel() {
pushd ibm-blockchain-channel >/dev/null 2>&1

# Install the chart
lintChart
colorEcho "\n$ helm install --name ${RELEASE_NAME} ." 132
helm install --name ${RELEASE_NAME} .


# Ensure the correct number of pods are running and completed
checkPodStatus ${TOTAL_RUNNING} ${TOTAL_COMPLETED}

Expand All @@ -147,6 +231,8 @@ function startChaincode() {
pushd ibm-blockchain-chaincode >/dev/null 2>&1

# Install the chart
lintChart
colorEcho "\n$ helm install --name ${RELEASE_NAME} ." 132
helm install --name ${RELEASE_NAME} .

# Ensure the correct number of pods are running and completed
Expand All @@ -167,6 +253,8 @@ function startComposer() {
pushd ibm-blockchain-composer >/dev/null 2>&1

# Install the chart
lintChart
colorEcho "\n$ helm install --name ${RELEASE_NAME} ." 132
helm install --name ${RELEASE_NAME} .

# Ensure the correct number of pods are running and completed
Expand Down
10 changes: 5 additions & 5 deletions helm-charts/ibm-blockchain-chaincode/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
name: ibm-blockchain-chaincode
version: 1.0.0
appVersion: 1.0.0
description: IBM Blockchain Chaincode Chart
keywords:
- blockchain
home: https://ibm-blockchain.github.io
sources:
- https://github.ibm.com/IBM-Blockchain/ibm-container-service
maintainers:
- name: Mihir Shah
maintainers:
- name: mrshah-at-ibm
email: mrshah@us.ibm.com
- name: Dhyey Shah
- name: dhyey20
email: dbshah@us.ibm.com
- name: Eddie Allen
- name: eddie-at-ibm
email: deallen@us.ibm.com
engine: gotpl
icon: https://www.ibm.com/blogs/bluemix/wp-content/uploads/2016/02/IBM_Blockchain_Hero.png
appVersion: 1.0.0
7 changes: 4 additions & 3 deletions helm-charts/ibm-blockchain-chaincode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This chart bootstraps a [ibm-blockchain](https://ibm-blockchain.github.io) deplo

## Prerequisites

- Kubernetes 1.4+ with Beta APIs enabled
- Kubernetes 1.7+

## Installing the Chart

Expand All @@ -40,11 +40,12 @@ The command removes all the Kubernetes components associated with the chart and

## Configuration

The following tables lists the configurable parameters of the IBM Blockchain chart and their default values.
The following table lists the configurable parameters of the IBM Blockchain Chaincode chart and their default values.

| Parameter | Description | Default |
|------------------------------------|------------------------------------------|----------------------------------------------------------|
| `blockchain.pullPolicy` | Blockchain image pull policy | `Always` |
| `blockchain.toolsImage` | Blockchain tools image | `ibmblockchain/fabric-tools:1.0.0` |
| `blockchain.pullPolicy` | Blockchain image pull policy | `IfNotPresent` |
| `blockchain.channelName` | Blockchain channel name | `channel1` |

The above parameters map to the env variables defined in [IBM-Blockchain/ibm-container-service](https://github.ibm.com/IBM-Blockchain/ibm-container-service). For more information please refer to the [IBM-Blockchain/ibm-container-service](https://github.ibm.com/IBM-Blockchain/ibm-container-service) documentation.
Expand Down
28 changes: 14 additions & 14 deletions helm-charts/ibm-blockchain-chaincode/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range .Values.ingress.hosts }}
http://{{ . }}
http://{{ . }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "ibm-blockchain-chaincode.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 "fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo http://$SERVICE_IP:{{ .Values.service.externalPort }}
You can watch the status by running 'kubectl get svc -w {{ template "ibm-blockchain-chaincode.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "ibm-blockchain-chaincode.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo http://$SERVICE_IP:{{ .Values.service.externalPort }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app={{ template "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:{{ .Values.service.externalPort }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app={{ template "ibm-blockchain-chaincode.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:{{ .Values.service.externalPort }}
{{- end }}

2. If pods complete with an error state, ensure you have first created an IBM Blockchain Network, created a channel, and that your peers have joined the channel by running these commands:
helm delete {{ .Release.Name }}
helm install stable/ibm-blockchain-network
helm install stable/ibm-blockchain-channel
helm install stable/ibm-blockchain-chaincode
helm delete {{ .Release.Name }}
helm install stable/ibm-blockchain-network
helm install stable/ibm-blockchain-channel
helm install stable/ibm-blockchain-chaincode
37 changes: 35 additions & 2 deletions helm-charts/ibm-blockchain-chaincode/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -1,16 +1,49 @@
{{/* vim: set filetype=mustache: */}}

{{/*
Expand the name of the chart.
*/}}
{{- define "name" -}}
{{- define "ibm-blockchain-chaincode.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).
*/}}
{{- define "fullname" -}}
{{- define "ibm-blockchain-chaincode.fullname" -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Expand the name of the shared volume.
*/}}
{{- define "ibm-blockchain-shared-pvc.name" -}}
{{- default "ibm-blockchain-shared-pvc" .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified shared volume name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
*/}}
{{- define "ibm-blockchain-shared-pvc.fullname" -}}
{{- $name := default "ibm-blockchain-shared-pvc" .Values.nameOverride -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Expand the name of the composer volume.
*/}}
{{- define "ibm-blockchain-composer-pvc.name" -}}
{{- default "ibm-blockchain-composer-pvc" .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified composer volume name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
*/}}
{{- define "ibm-blockchain-composer-pvc.fullname" -}}
{{- $name := default "ibm-blockchain-composer-pvc" .Values.nameOverride -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,35 @@
apiVersion: v1
kind: Pod
metadata:
name: chaincodeinstall-org1peer1
name: {{ template "ibm-blockchain-chaincode.fullname" . }}-install-org1peer1
labels:
app: {{ template "ibm-blockchain-chaincode.name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
spec:
restartPolicy: "Never"
volumes:
- name: shared
- name: {{ template "ibm-blockchain-shared-pvc.name" . }}
persistentVolumeClaim:
claimName: shared
claimName: {{ template "ibm-blockchain-shared-pvc.name" . }}

containers:
- name: chaincodeinstall-org1peer1
image: ibmblockchain/fabric-tools:1.0.1
imagePullPolicy: {{.Values.blockchain.pullPolicy}}
command: ["sh", "-c", "while [ ! -f /shared/status_joinchannel_org1peer1_complete ]; do echo Waiting for joinchannel; sleep 2; done; git clone -b v1.0.1 https://github.com/hyperledger/fabric $GOPATH/src/github.com/hyperledger/fabric/ && peer chaincode install -n ${CHAINCODE_NAME} -v ${CHAINCODE_VERSION} -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02/ && touch /shared/status_chaincodeinstall_o1p1_complete"]
image: {{ .Values.blockchain.toolsImage }}
imagePullPolicy: {{ .Values.blockchain.pullPolicy }}
command:
- sh
- -c
- |
while [ ! -f /shared/status_joinchannel_org1peer1_complete ]; do
echo Waiting for joinchannel
sleep 2
done

git clone -b v1.0.0 https://github.com/hyperledger/fabric $GOPATH/src/github.com/hyperledger/fabric/ &&
peer chaincode install -n ${CHAINCODE_NAME} -v ${CHAINCODE_VERSION} -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02/ &&
touch /shared/status_chaincodeinstall_o1p1_complete
env:
- name: CHAINCODE_NAME
value: example02
Expand All @@ -27,9 +43,9 @@ spec:
- name: CORE_PEER_LOCALMSPID
value: Org1MSP
- name: CORE_PEER_ADDRESS
value: blockchain-org1peer1:30110
value: {{ template "ibm-blockchain-network.name" . }}-org1peer1:5010
- name: GODEBUG
value: "netdns=go"
volumeMounts:
- mountPath: /shared
name: shared
name: {{ template "ibm-blockchain-shared-pvc.name" . }}
Loading