Merge pull request #45044 from juju-solutions/gkk/e2e-snap

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
```
This commit is contained in:
Kubernetes Submit Queue 2017-04-27 13:27:09 -07:00 committed by GitHub
commit 963e056515
5 changed files with 29 additions and 56 deletions

View File

@ -2,6 +2,8 @@
set -ex set -ex
export PATH="$PATH:/snap/bin"
# Grab the action parameter values # Grab the action parameter values
FOCUS=$(action-get focus) FOCUS=$(action-get focus)
SKIP=$(action-get skip) SKIP=$(action-get skip)
@ -26,7 +28,7 @@ ACTION_JUNIT_TGZ=$ACTION_JUNIT.tar.gz
# This initializes an e2e build log with the START TIMESTAMP. # This initializes an e2e build log with the START TIMESTAMP.
echo "JUJU_E2E_START=$(date -u +%s)" | tee $ACTION_LOG 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 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 \ -kubeconfig /home/ubuntu/.kube/config \
-host $SERVER \ -host $SERVER \
-ginkgo.focus $FOCUS \ -ginkgo.focus $FOCUS \

View File

@ -0,0 +1,6 @@
options:
channel:
type: string
default: "stable"
description: |
Snap channel to install Kubernetes snaps from

View File

@ -2,6 +2,7 @@ repo: https://github.com/juju-solutions/layer-kubernetes-e2e
includes: includes:
- layer:basic - layer:basic
- layer:tls-client - layer:tls-client
- layer:snap
- interface:http - interface:http
options: options:
tls-client: tls-client:

View File

@ -15,15 +15,11 @@ requires:
kubernetes-master: kubernetes-master:
interface: http interface: http
resources: resources:
e2e_amd64: kubectl:
type: file type: file
filename: e2e_amd64.tar.gz filename: kubectl.snap
description: Tarball of the e2e binary, and kubectl binary for amd64 description: kubectl snap
e2e_ppc64el: kubernetes-test:
type: file type: file
filename: e2e_ppc64le.tar.gz filename: kubernetes-test.snap
description: Tarball of the e2e binary, and kubectl binary for ppc64le description: kubernetes-test snap
e2e_s390x:
type: file
filename: e2e_s390x.tar.gz
description: Tarball of the e2e binary, and kubectl binary for s390x

View File

@ -17,6 +17,7 @@
import os import os
from charms import layer from charms import layer
from charms.layer import snap
from charms.reactive import hook from charms.reactive import hook
from charms.reactive import is_state from charms.reactive import is_state
@ -37,7 +38,7 @@ from subprocess import check_output
@hook('upgrade-charm') @hook('upgrade-charm')
def reset_delivery_states(): def reset_delivery_states():
''' Remove the state set when resources are unpacked. ''' ''' Remove the state set when resources are unpacked. '''
remove_state('kubernetes-e2e.installed') install_snaps()
@when('kubernetes-e2e.installed') @when('kubernetes-e2e.installed')
@ -65,52 +66,19 @@ def messaging():
hookenv.status_set('active', 'Ready to test.') hookenv.status_set('active', 'Ready to test.')
@when_not('kubernetes-e2e.installed') @when('config.changed.channel')
def install_kubernetes_e2e(): def channel_changed():
install_snaps()
def install_snaps():
''' Deliver the e2e and kubectl components from the binary resource stream ''' Deliver the e2e and kubectl components from the binary resource stream
packages declared in the charm ''' packages declared in the charm '''
charm_dir = os.getenv('CHARM_DIR') channel = hookenv.config('channel')
arch = determine_arch() hookenv.status_set('maintenance', 'Installing kubectl snap')
snap.install('kubectl', channel=channel, classic=True)
# Get the resource via resource_get hookenv.status_set('maintenance', 'Installing kubernetes-test snap')
resource = 'e2e_{}'.format(arch) snap.install('kubernetes-test', channel=channel, classic=True)
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)
set_state('kubernetes-e2e.installed') set_state('kubernetes-e2e.installed')