Skip to content

Commit

Permalink
KF-739 (#1)
Browse files Browse the repository at this point in the history
- Create sidecar charm for ResourceDispatcher
- Deploy composite controller talking to /sync endpoint of the resource dispatcher image 
- Add CI + unit and integration tests
- Publish to charmhub
  • Loading branch information
misohu authored Mar 23, 2023
1 parent 1fc154b commit bd8c9ff
Show file tree
Hide file tree
Showing 35 changed files with 2,491 additions and 2 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/get-charm-paths.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash -x

# Finds the charms in this repo, outputting them as JSON
# Will return one of:
# * the relative paths of the directories listed in `./charms`, if that directory exists
# * "./", if the root directory has a "metadata.yaml" file
# * otherwise, error
#
# Modified from: https://stackoverflow.com/questions/63517732/github-actions-build-matrix-for-lambda-functions/63736071#63736071
CHARMS_DIR="./charms"
if [ -d "$CHARMS_DIR" ];
then
CHARM_PATHS=$(find $CHARMS_DIR -maxdepth 1 -type d -not -path '*/\.*' -not -path "$CHARMS_DIR")
else
if [ -f "./metadata.yaml" ]
then
CHARM_PATHS="./"
else
echo "Cannot find valid charm directories - aborting"
exit 1
fi
fi

# Convert output to JSON string format
# { charm_paths: [...] }
CHARM_PATHS_LIST=$(echo "$CHARM_PATHS" | jq -c --slurp --raw-input 'split("\n")[:-1]')

echo "Found CHARM_PATHS_LIST: $CHARM_PATHS_LIST"

echo "::set-output name=CHARM_PATHS_LIST::$CHARM_PATHS_LIST"
94 changes: 94 additions & 0 deletions .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# reusable workflow triggered by other actions
name: CI

on:
workflow_call:
secrets:
charmcraft-credentials:
required: true

jobs:

lib-check:
name: Check libraries
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Check libs
uses: canonical/charming-actions/[email protected]
with:
credentials: "${{ secrets.charmcraft-credentials }}"
github-token: "${{ secrets.GITHUB_TOKEN }}"

lint:
name: Lint Check
runs-on: ubuntu-20.04

steps:
- name: Check out code
uses: actions/checkout@v2

- name: Install dependencies
run: sudo apt-get install python3-pip tox

- name: Lint code
run: tox -e lint

unit:
name: Unit Test
runs-on: ubuntu-20.04

steps:
- name: Check out code
uses: actions/checkout@v2

- name: Install dependencies
run: sudo apt-get install python3-pip tox

- name: Run unit tests
run: tox -e unit

integration:
name: Integration Test (build and deploy)
runs-on: ubuntu-20.04

steps:
- name: Check out repo
uses: actions/checkout@v2

- name: Setup operator environment
uses: charmed-kubernetes/actions-operator@main
with:
provider: microk8s
channel: 1.24/stable
# Pinned until this bug is resolved: https://bugs.launchpad.net/juju/+bug/1992833
bootstrap-options: "--agent-version=2.9.34"
microk8s-addons: "dns storage rbac metallb:10.64.140.43-10.64.140.49"

- name: Run integration tests
run: tox -vve integration -- --model testing

# On failure, capture debugging resources
- name: Get all
run: kubectl get all -A
if: failure()

- name: Get juju status
run: juju status
if: failure()

- name: Get workload logs
run: kubectl logs --tail 100 -ntesting -lapp.kubernetes.io/name=resource-dispatcher
if: failure()

- name: Get operator logs
run: kubectl logs --tail 100 -ntesting -loperator.juju.is/name=resource-dispatcher
if: failure()

- name: Setup tmate session
uses: mxschmitt/action-tmate@v3
if: failure()
timeout-minutes: 40
17 changes: 17 additions & 0 deletions .github/workflows/issues_to_jira.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# this workflow requires to provide JIRA webhook URL via JIRA_URL GitHub Secret
# read more: https://support.atlassian.com/cloud-automation/docs/jira-automation-triggers/#Automationtriggers-Incomingwebhook
# original code source: https://github.com/beliaev-maksim/github-to-jira-automation

name: Issues to JIRA

on:
issues:
# available via github.event.action
types: [opened, reopened, closed]

jobs:
update:
name: Update Issue
uses: beliaev-maksim/github-to-jira-automation/.github/workflows/issues_to_jira.yaml@master
secrets:
JIRA_URL: ${{ secrets.JIRA_URL }}
23 changes: 23 additions & 0 deletions .github/workflows/on_pull_request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: On Pull Request

# On pull_request, we:
# * always publish to charmhub at latest/edge/branchname
# * always run tests

on:
pull_request:

jobs:

tests:
name: Run Tests
uses: ./.github/workflows/integrate.yaml
secrets:
charmcraft-credentials: ${{ secrets.CHARMCRAFT_CREDENTIALS }}

# publish runs in parallel with tests, as we always publish in this situation
publish-charm:
name: Publish Charm
uses: ./.github/workflows/publish.yaml
secrets:
CHARMCRAFT_CREDENTIALS: ${{ secrets.CHARMCRAFT_CREDENTIALS }}
30 changes: 30 additions & 0 deletions .github/workflows/on_push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: On Push

# On push to a "special" branch, we:
# * always publish to charmhub at latest/edge/branchname
# * always run tests
# where a "special" branch is one of main/master or track/**, as
# by convention these branches are the source for a corresponding
# charmhub edge channel.

on:
push:
branches:
- master
- main
- track/**

jobs:
tests:
name: Run Tests
uses: ./.github/workflows/integrate.yaml
secrets:
charmcraft-credentials: ${{ secrets.CHARMCRAFT_CREDENTIALS }}

# publish runs in series with tests, and only publishes if tests passes
publish-charm:
name: Publish Charm
needs: tests
uses: ./.github/workflows/publish.yaml
secrets:
CHARMCRAFT_CREDENTIALS: ${{ secrets.CHARMCRAFT_CREDENTIALS }}
93 changes: 93 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# reusable workflow for publishing all charms in this repo
name: Publish

on:
workflow_call:
inputs:
source_branch:
description: Github branch from this repo to publish. If blank, will use the default branch
default: ''
required: false
type: string
secrets:
CHARMCRAFT_CREDENTIALS:
required: true
workflow_dispatch:
inputs:
destination_channel:
description: CharmHub channel to publish to
required: false
default: 'latest/edge'
type: string
source_branch:
description: Github branch from this repo to publish. If blank, will use the default branch
required: false
default: ''
type: string

jobs:
get-charm-paths:
name: Generate the Charm Matrix
runs-on: ubuntu-20.04
outputs:
charm_paths_list: ${{ steps.get-charm-paths.outputs.CHARM_PATHS_LIST }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
ref: ${{ inputs.source_branch }}
- name: Get paths for all charms in repo
id: get-charm-paths
run: bash .github/workflows/get-charm-paths.sh


publish-charm:
name: Publish Charm
runs-on: ubuntu-20.04
needs: get-charm-paths
strategy:
fail-fast: false
matrix:
charm-path: ${{ fromJson(needs.get-charm-paths.outputs.charm_paths_list) }}

steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
ref: ${{ inputs.source_branch }}

- name: Select charmhub channel
uses: canonical/charming-actions/[email protected]
id: select-channel
if: ${{ inputs.destination_channel == '' }}

# Combine inputs from different sources to a single canonical value so later steps don't
# need logic for picking the right one
- name: Parse and combine inputs
id: parse-inputs
run: |
# destination_channel
destination_channel="${{ inputs.destination_channel || steps.select-channel.outputs.name }}"
echo "setting output of destination_channel=$destination_channel"
echo "::set-output name=destination_channel::$destination_channel"
# tag_prefix
# if charm_path = ./ --> tag_prefix = '' (null)
# if charm_path != ./some-charm (eg: a charm in a ./charms dir) --> tag_prefix = 'some-charm'
if [ ${{ matrix.charm-path }} == './' ]; then
tag_prefix=''
else
tag_prefix=$(basename ${{ matrix.charm-path }} )
fi
echo "setting output of tag_prefix=$tag_prefix"
echo "::set-output name=tag_prefix::$tag_prefix"
- name: Upload charm to charmhub
uses: canonical/charming-actions/[email protected]
with:
credentials: ${{ secrets.CHARMCRAFT_CREDENTIALS }}
github-token: ${{ secrets.GITHUB_TOKEN }}
charm-path: ${{ matrix.charm-path }}
channel: ${{ steps.parse-inputs.outputs.destination_channel }}
tag-prefix: ${{ steps.parse-inputs.outputs.tag_prefix }}
26 changes: 26 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# reusable workflow triggered manually
name: Release charm to other tracks and channels

on:
workflow_dispatch:
inputs:
destination-channel:
description: 'Destination Channel'
required: true
origin-channel:
description: 'Origin Channel'
required: true

jobs:
promote-charm:
name: Promote charm
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Release charm to channel
uses: canonical/charming-actions/[email protected]
with:
credentials: ${{ secrets.CHARMCRAFT_CREDENTIALS }}
github-token: ${{ secrets.GITHUB_TOKEN }}
destination-channel: ${{ github.event.inputs.destination-channel }}
origin-channel: ${{ github.event.inputs.origin-channel }}
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
venv/
build/
*.charm
.tox/
.coverage
__pycache__/
*.py[cod]
.idea
.vscode/

kubeconfig.tmp
new_config
.mypy_cache
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @canonical/kubeflow
Loading

0 comments on commit bd8c9ff

Please sign in to comment.