Skip to content

Commit

Permalink
update canal with recent improvements to flannel (#77)
Browse files Browse the repository at this point in the history
* align gh workflow and tox with current flannel

- dupe recent charm-flannel improvements for building resources
- drop crashdump in favor of a simple debug-log for failed runner jobs
- bump resource script to known-good charm-flannel commit
- tox tweaks to be consistent with other charms

* follow ck best practices for integration tests (overlay k8s-core with locally built charm/resources)

* use etcd3 calls to align with flannel changes

* dont run tests on l33t commits to main
  • Loading branch information
kwmonroe authored Feb 9, 2023
1 parent af5533a commit ab082ac
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 231 deletions.
102 changes: 78 additions & 24 deletions .github/workflows/tox.yaml
Original file line number Diff line number Diff line change
@@ -1,52 +1,106 @@
name: Run tests with Tox

on:
push:
branches: [main]
pull_request:
branches: [main]
branches:
- main

jobs:
call-inclusive-naming-check:
name: Inclusive Naming
name: Inclusive naming
uses: canonical-web-and-design/Inclusive-naming/.github/workflows/woke.yaml@main
with:
fail-on-error: "true"

validate-wheelhouse:
name: Validate Wheelhouse
uses: charmed-kubernetes/workflows/.github/workflows/validate-wheelhouse.yaml@main

lint-unit:
name: Lint Unit
uses: charmed-kubernetes/workflows/.github/workflows/lint-unit.yaml@main

validate-wheelhouse:
uses: charmed-kubernetes/workflows/.github/workflows/validate-wheelhouse.yaml@main
resources-build:
name: Build Resources with docker
runs-on: ubuntu-22.04
needs:
- lint-unit
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Install Docker
run: sudo snap install docker
- name: Build Resources
run: sudo ./build-canal-resources.sh
- name: Upload flannel artifact
uses: actions/upload-artifact@v3
with:
name: flannel-resources
path: ./flannel-*.tar.gz
- name: Upload calico artifact
uses: actions/upload-artifact@v3
with:
name: calico-resources
path: ./calico*.tar.gz
- name: Upload calico-node-image artifact
uses: actions/upload-artifact@v3
with:
name: calico-node-image-resources
path: ./calico-node-image.tar.gz

integration-test:
name: Integration test with VMWare
integration-tests:
name: Integration test with Vsphere
runs-on: self-hosted
timeout-minutes: 60
needs:
- call-inclusive-naming-check
- lint-unit
- validate-wheelhouse
timeout-minutes: 360
- resources-build
steps:
- name: Check out code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.8

- name: Setup operator environment
uses: charmed-kubernetes/actions-operator@main
with:
provider: vsphere
credentials-yaml: ${{ secrets.CREDENTIALS_YAML }}
clouds-yaml: ${{ secrets.CLOUDS_YAML }}
bootstrap-options: "--model-default datastore=vsanDatastore --model-default primary-network=VLAN_2764"
- name: Install docker (flannel resources)
run: sudo snap install docker
- name: Install juju-crashdump
run: sudo snap install juju-crashdump --classic
- name: Run test
bootstrap-options: "${{ secrets.FOCAL_BOOTSTRAP_OPTIONS }} --model-default datastore=vsanDatastore --model-default primary-network=VLAN_2764"
bootstrap-constraints: "arch=amd64 cores=2 mem=4G"

- name: Download flannel artifacts
uses: actions/download-artifact@v3
with:
name: flannel-resources

- name: Download calico artifacts
uses: actions/download-artifact@v3
with:
name: calico-resources

- name: Download calico-node-image artifacts
uses: actions/download-artifact@v3
with:
name: calico-node-image-resources

- name: Run integration test
run: tox -e integration
- name: Upload crashdump
if: ${{ failure() }}
uses: actions/upload-artifact@v2

- name: Setup Debug Artifact Collection
if: failure()
run: mkdir tmp

- name: Collect Juju Logs
if: failure()
run: juju debug-log --replay --no-tail | tee tmp/juju-status.txt

- name: Upload debug artifacts
if: failure()
uses: actions/upload-artifact@v3
with:
name: crashdump
path: juju-crashdump-*.tar.xz
name: test-run-artifacts
path: tmp
4 changes: 2 additions & 2 deletions build-canal-resources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ mkdir -p "${canal_temp}"
# FLANNEL RESOURCES:
# The flannel version in the canal and flannel charms are the same; use flannel's
# build-flannel-resource.sh so we build identical resources for the canal charm.
FLANNEL_COMMIT="16d6841f019acc4ff6e5b04059ff4bee6b50057e"
FLANNEL_COMMIT="db7a8123e2391c412462bb1cd5bce721ff8dd268"
FLANNEL_REPO="https://github.com/charmed-kubernetes/charm-flannel.git"

git clone $FLANNEL_REPO "${canal_temp}/flannel"
pushd ${canal_temp}/flannel
git checkout "$FLANNEL_COMMIT"
ARCH="$ARCH" ./build-flannel-resources.sh
mv flannel-*.gz ${canal_root}
mv flannel-*.tar.gz ${canal_root}
popd


Expand Down
13 changes: 7 additions & 6 deletions reactive/flannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,14 @@ def configure_network(etcd):
}
})
cmd = "etcdctl "
cmd += "--endpoint '{0}' ".format(etcd.get_connection_string())
cmd += "--cert-file {0} ".format(ETCD_CERT_PATH)
cmd += "--key-file {0} ".format(ETCD_KEY_PATH)
cmd += "--ca-file {0} ".format(ETCD_CA_PATH)
cmd += "set /coreos.com/network/config '{0}'".format(data)
cmd += "--endpoints '{0}' ".format(etcd.get_connection_string())
cmd += "--cert {0} ".format(ETCD_CERT_PATH)
cmd += "--key {0} ".format(ETCD_KEY_PATH)
cmd += "--cacert {0} ".format(ETCD_CA_PATH)
cmd += "put /coreos.com/network/config '{0}'".format(data)
env = dict(os.environ, ETCDCTL_API="3")
try:
check_call(split(cmd))
check_call(split(cmd), env=env)
return True

except CalledProcessError:
Expand Down
80 changes: 0 additions & 80 deletions tests/data/bundle.yaml

This file was deleted.

26 changes: 26 additions & 0 deletions tests/data/charm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
description: A minimal Kubernetes cluster with two machines with virtual networks provided by Canal.
series: &series {{ series }}
applications:
calico: null
kubernetes-control-plane:
options:
channel: {{ snap_channel }}
kubernetes-worker:
options:
channel: {{ snap_channel }}
canal:
charm: {{ charm }}
channel: null
resources:
flannel: {{flannel_amd64|default("0")}}
flannel-arm64: {{flannel_arm64|default("0")}}
calico: {{calico_amd64|default("0")}}
calico-arm64: {{calico_arm64|default("0")}}
calico-node-image: {{calico_node_image|default("0")}}
relations:
- - canal:etcd
- etcd:db
- - canal:cni
- kubernetes-control-plane:cni
- - canal:cni
- kubernetes-worker:cni
67 changes: 20 additions & 47 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,29 @@
import logging
from pathlib import Path
import pytest
import shlex

log = logging.getLogger(__name__)


def ensure_arch_names(current_resources):
for resource in current_resources:
if any(arch in resource.name for arch in ['s390x', 'arm64', 'amd64']):
continue
if resource.name == 'calico-node-image.tar.gz':
# doesn't have an associated arch
continue
# without an arch, assume 'amd64'
head, tail = resource.name.split('.', 1)
arched_name = "{}-amd64.{}".format(head, tail)
(resource.parent / arched_name).symlink_to(resource)
def pytest_addoption(parser):
parser.addoption(
"--series",
type=str,
default="focal",
help="Set series for the machine units",
)
parser.addoption(
"--snap-channel",
type=str,
default="1.24/stable",
help="Set snap channel for the control-plane & worker units",
)


@pytest.fixture()
async def setup_resources(ops_test):
"""Provides the flannel resources needed to deploy the charm."""
script_path = resource_path = Path.cwd()
current_resources = list(resource_path.glob("*.tar.gz"))
tmpdir = ops_test.tmp_path / "resources"
tmpdir.mkdir(parents=True, exist_ok=True)
if not current_resources:
# If they are not locally available, try to build them
log.info("Build Resources...")
build_script = script_path / "build-canal-resources.sh"
rc, stdout, stderr = await ops_test.run(
*shlex.split("sudo {}".format(build_script)), cwd=tmpdir, check=False
)
if rc != 0:
err = (stderr or stdout).strip()
log.warning("build-flannel-resources failed: {}".format(err))
current_resources = list(Path(tmpdir).glob("*.tar.gz"))
resource_path = tmpdir
if not current_resources:
# if we couldn't build them, just download a fixed version
log.info("Downloading Resources...")
fetch_script = script_path / "fetch-charm-store-resources.sh"
rc, stdout, stderr = await ops_test.run(
*shlex.split(str(fetch_script)), cwd=tmpdir, check=False
)
if rc != 0:
err = (stderr or stdout).strip()
log.warning("fetch-charm-store-resources failed: {}".format(err))
current_resources = list(Path(tmpdir).glob("*.tar.gz"))
resource_path = tmpdir
if not current_resources:
pytest.fail("Could not prepare necessary resources for testing charm")
ensure_arch_names(current_resources)
yield resource_path
def series(request):
return request.config.getoption("--series")


@pytest.fixture()
def snap_channel(request):
return request.config.getoption("--snap-channel")
Loading

0 comments on commit ab082ac

Please sign in to comment.