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

Update kubernetes-e2e charm to use snaps #45044

Merged
merged 1 commit into from
Apr 27, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion cluster/juju/layers/kubernetes-e2e/actions/test
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

set -ex

export PATH="$PATH:/snap/bin"

# Grab the action parameter values
FOCUS=$(action-get focus)
SKIP=$(action-get skip)
Expand All @@ -26,7 +28,7 @@ ACTION_JUNIT_TGZ=$ACTION_JUNIT.tar.gz
# This initializes an e2e build log with the START TIMESTAMP.
echo "JUJU_E2E_START=$(date -u +%s)" | tee $ACTION_LOG
echo "JUJU_E2E_VERSION=$(kubectl version | grep Server | cut -d " " -f 5 | cut -d ":" -f 2 | sed s/\"// | sed s/\",//)" | tee -a $ACTION_LOG
ginkgo -nodes=$PARALLELISM $(which e2e.test) -- \
GINKGO_ARGS="-nodes=$PARALLELISM" kubernetes-test.e2e \
-kubeconfig /home/ubuntu/.kube/config \
-host $SERVER \
-ginkgo.focus $FOCUS \
Expand Down
6 changes: 6 additions & 0 deletions cluster/juju/layers/kubernetes-e2e/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
options:
channel:
type: string
default: "stable"
description: |
Snap channel to install Kubernetes snaps from
1 change: 1 addition & 0 deletions cluster/juju/layers/kubernetes-e2e/layer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ repo: https://github.com/juju-solutions/layer-kubernetes-e2e
includes:
- layer:basic
- layer:tls-client
- layer:snap
- interface:http
options:
tls-client:
Expand Down
16 changes: 6 additions & 10 deletions cluster/juju/layers/kubernetes-e2e/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,11 @@ requires:
kubernetes-master:
interface: http
resources:
e2e_amd64:
kubectl:
type: file
filename: e2e_amd64.tar.gz
description: Tarball of the e2e binary, and kubectl binary for amd64
e2e_ppc64el:
filename: kubectl.snap
description: kubectl snap
kubernetes-test:
type: file
filename: e2e_ppc64le.tar.gz
description: Tarball of the e2e binary, and kubectl binary for ppc64le
e2e_s390x:
type: file
filename: e2e_s390x.tar.gz
description: Tarball of the e2e binary, and kubectl binary for s390x
filename: kubernetes-test.snap
description: kubernetes-test snap
58 changes: 13 additions & 45 deletions cluster/juju/layers/kubernetes-e2e/reactive/kubernetes_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import os

from charms import layer
from charms.layer import snap

from charms.reactive import hook
from charms.reactive import is_state
Expand All @@ -37,7 +38,7 @@
@hook('upgrade-charm')
def reset_delivery_states():
''' Remove the state set when resources are unpacked. '''
remove_state('kubernetes-e2e.installed')
install_snaps()


@when('kubernetes-e2e.installed')
Expand Down Expand Up @@ -65,52 +66,19 @@ def messaging():
hookenv.status_set('active', 'Ready to test.')


@when_not('kubernetes-e2e.installed')
def install_kubernetes_e2e():
''' Deliver the e2e and kubectl components from the binary resource stream
packages declared in the charm '''
charm_dir = os.getenv('CHARM_DIR')
arch = determine_arch()
@when('config.changed.channel')
def channel_changed():
install_snaps()

# Get the resource via resource_get
resource = 'e2e_{}'.format(arch)
try:
archive = hookenv.resource_get(resource)
except Exception:
message = 'Error fetching the {} resource.'.format(resource)
hookenv.log(message)
hookenv.status_set('blocked', message)
return

if not archive:
hookenv.log('Missing {} resource.'.format(resource))
hookenv.status_set('blocked', 'Missing {} resource.'.format(resource))
return

# Handle null resource publication, we check if filesize < 1mb
filesize = os.stat(archive).st_size
if filesize < 1000000:
hookenv.status_set('blocked',
'Incomplete {} resource.'.format(resource))
return

hookenv.status_set('maintenance',
'Unpacking {} resource.'.format(resource))

unpack_path = '{}/files/kubernetes'.format(charm_dir)
os.makedirs(unpack_path, exist_ok=True)
cmd = ['tar', 'xfvz', archive, '-C', unpack_path]
hookenv.log(cmd)
check_call(cmd)

services = ['e2e.test', 'ginkgo', 'kubectl']

for service in services:
unpacked = '{}/{}'.format(unpack_path, service)
app_path = '/usr/local/bin/{}'.format(service)
install = ['install', '-v', unpacked, app_path]
call(install)

def install_snaps():
''' Deliver the e2e and kubectl components from the binary resource stream
packages declared in the charm '''
channel = hookenv.config('channel')
hookenv.status_set('maintenance', 'Installing kubectl snap')
snap.install('kubectl', channel=channel, classic=True)
hookenv.status_set('maintenance', 'Installing kubernetes-test snap')
snap.install('kubernetes-test', channel=channel, classic=True)
set_state('kubernetes-e2e.installed')


Expand Down