Skip to content

Commit

Permalink
Merge pull request kubernetes#45044 from juju-solutions/gkk/e2e-snap
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue (batch tested with PRs 42740, 44980, 45039, 41627, 45044)

Update kubernetes-e2e charm to use snaps

**What this PR does / why we need it**:

This updates the kubernetes-e2e charm to use snaps instead of Juju resources for payload delivery.

The main advantage of this is that it decouples the charm from the e2e payload, allowing us to support multiple versions of Kubernetes with a single release of the charm.

**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #

**Special notes for your reviewer**:

**Release note**:

```release-note
Update kubernetes-e2e charm to use snaps
```
  • Loading branch information
Kubernetes Submit Queue authored Apr 27, 2017
2 parents 8b9625d + 8d9abda commit 963e056
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 56 deletions.
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

0 comments on commit 963e056

Please sign in to comment.