Add juju action to start petstore example

This is @chuckbutler's work, with some small fixes

`juju action do kubernetes-master/0 petstore` launches the example code
This commit is contained in:
Whit Morriss 2015-05-19 09:47:08 -05:00
parent 10339d72b6
commit 5d19597ffa
7 changed files with 88 additions and 2 deletions

View File

@ -18,7 +18,8 @@ kubernetes-local:
"gui-x": "0"
"gui-y": "0"
flannel-docker:
charm: cs:trusty/flannel-docker
charm: flannel-docker
branch: https://github.com/chuckbutler/flannel-docker-charm.git
annotations:
"gui-x": "0"
"gui-y": "300"
@ -35,8 +36,12 @@ kubernetes-local:
relations:
- - "flannel-docker:network"
- "docker:network"
- - "flannel-docker:network"
- "kubernetes-master:network"
- - "flannel-docker:docker-host"
- "docker:juju-info"
- - "flannel-docker:docker-host"
- "kubernetes-master:juju-info"
- - "flannel-docker:db"
- "etcd:client"
- - "kubernetes:docker-host"

View File

@ -0,0 +1,3 @@
petstore:
description: Deploy the Kubernetes Petstore app

View File

@ -0,0 +1,17 @@
#!/usr/bin/env python
import json
import sys
def parse_pod_output():
out = sys.stdin.readlines()
foo = json.loads(' '.join(out))
for item in foo['items']:
name_slugs = set(item['metadata']['name'].split('-'))
if 'fectrl' in name_slugs:
if item['status']['phase'] == "Running":
print item['status']['podIP']
if __name__ == "__main__":
parse_pod_output()

View File

@ -0,0 +1,40 @@
#!/bin/bash
set -eux
export KUBE_MASTER_IP=0.0.0.0
export KUBERNETES_MASTER=http://$KUBE_MASTER_IP
# The test is a bit spammy with files, head over to /tmp to discard when done
cd /tmp
# Need to update the script with the proposed IP of the web-head pod
# Currently its set to 10.1.4.89
sed -i 's/pass_http=0/exit 0/' /opt/kubernetes/examples/k8petstore/k8petstore.sh
/opt/kubernetes/examples/k8petstore/k8petstore.sh
# Loop until the daemon has come online
counter=0
KUBE_POD_STATUS="Pending"
while [ "$KUBE_POD_STATUS" == "Pending" ]
do
if [[ counter -eq 200 ]]; then
echo "Pod failed to come online. Timeout reached"
exit 1
fi
CUR_STATUS=$(kubectl get pods -o json | $CHARM_DIR/actions/lib/parse_get_pods)
if [ ! -z "$CUR_STATUS" ]; then
KUBE_POD_STATUS=$CUR_STATUS
fi
sleep 1
counter+=1
done
sed -i 's/exit 0/pass_http=0/' /opt/kubernetes/examples/k8petstore/k8petstore.sh
sed -i "s/PUBLIC_IP=\"10.1.4.89\"/PUBLIC_IP=\"$KUBE_POD_STATUS\"/" /opt/kubernetes/examples/k8petstore/k8petstore.sh
/opt/kubernetes/examples/k8petstore/k8petstore.sh
# Return execution to the CHARM_DIR for further actions
cd $CHARM_DIR

View File

@ -141,6 +141,11 @@ def relation_changed():
# Send api endpoint to minions
notify_minions()
@hooks.hook('network-relation-changed')
def network_relation_changed():
relation_id = hookenv.relation_id()
hookenv.relation_set(relation_id, ignore_errors=True)
def notify_minions():
print("Notify minions.")

View File

@ -17,3 +17,5 @@ provides:
requires:
etcd:
interface: etcd
network:
interface: overlay-network

View File

@ -5,7 +5,6 @@ wide number of clouds, supporting service orchestration once the bundle of
services has been deployed.
### Prerequisites
> Note: If you're running kube-up, on ubuntu - all of the dependencies
@ -165,8 +164,23 @@ We can add minion units like so:
juju add-unit docker # creates unit docker/2, kubernetes/2, docker-flannel/2
## Launch the "petstore" example app
The petstore example is available as a
[juju action](https://jujucharms.com/docs/devel/actions).
juju action do kubernetes-master/0
Note: this example includes curl statements to exercise the app.
## Tear down cluster
./kube-down.sh
or
juju destroy-environment --force `juju env`