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

PENG-2364 create the Vantage Agent Charm #1

Merged
merged 12 commits into from
Sep 12, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Release to Charmhub

on:
workflow_dispatch:
inputs:
channel:
description: 'The channel where the charm is going to be released to'
required: true
default: 'stable'
type: choice
options:
- stable
- candidate
- beta
- edge

jobs:
ci-tests:
uses: ./.github/workflows/test.yaml

release-to-charmhub:
name: Release to CharmHub
needs:
- ci-tests
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Charmcraft
run: |
sudo snap install charmcraft --channel 3.x/stable --classic

- name: Build bundle
run: |
charmcraft pack
mv vantage-agent_*.charm vantage-agent.charm

- name: Create bundle revision
run: |
charmcraft upload --name=vantage-agent --release=${{ github.event.inputs.channel }} vantage-agent.charm
env:
CHARMCRAFT_AUTH: ${{ secrets.CHARMCRAFT_AUTH }}
21 changes: 21 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Test

on:
pull_request:
workflow_call:

jobs:
lint-charms:
name: "Lint the charms"
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
architecture: 'x64'

- name: "Install tox, run 'make lint'"
run: |
pip install tox==4.18.0
tox -e lint
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*/.mypy_cache/
build/
*.charm
vantage-manager-agent.yaml
version
.venv
.tox
.ruff_cache
7 changes: 7 additions & 0 deletions .jujuignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/.pytest_cache
/build
/.tox
__pycache__

/vantage-agent
/.vscode
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12.3
fschuch marked this conversation as resolved.
Show resolved Hide resolved
12 changes: 12 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
==========
Change Log
==========

This file keeps track of all notable changes to the Vantage Agents Charm.

Unreleased
----------

1.0.0 - 2023-03-07
------------------
* Create the project
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 OmniVector Corp

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'

.PHONY: lint
lint: ## Run linter
tox -e lint

version: ## Create/update version file
@git describe --tags --dirty --always > version

.PHONY: clean
clean: ## Remove build dirs, temp files, and charms
rm -rf .venv/
rm -rf build
rm -rf version
find . -name "*.charm" -delete

.PHONY: charm
charm: version ## Pack the charm
@charmcraft pack
@mv vantage-agent_*.charm vantage-agent.charm
68 changes: 67 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,68 @@
# charm-vantage-agent
Charm for the Vantage Agent

# Usage

Follow the steps below to get started.

### Build the charm

Running the following command will produce a .charm file, `vantage-agent.charm`

```bash
charmcraft build
```

### Create the vantage-agent charm config

`vantage-agent.yaml`

```yaml
vantage-agent:
base-api-url: "<base-api-url>"
oidc-domain: "<oidc-domain>"
oidc-client-id: "<oidc-client-id>"
oidc-client-secret: "<oidc-client-secret>"
```

e.g.

```yaml
vantage-agent:
base-api-url: "https://apis.vantagehpc.io/cluster"
oidc-domain: "auth.vantagehpc.io"
oidc-client-id: "ae4e7c40-7889-45ae-bd36-1ad2f25dc679"
oidc-client-secret: "LMmPxusATyKz_dp63hjeJO7cFUayiYvudGv4r3gUk_4"
```

### Deploy the charm

Using the built charm and the defined config, run the command to deploy the charm.

```bash
juju deploy ./vantage-agent.charm \
--config ./vantage-agent.yaml \
--series jammy
```

### Charm Actions

The vantage-agent charm exposes additional functionality to facilitate vantage-agent
package upgrades.

To upgrade the vantage-agent to a new version or release:

```bash
juju run-action vantage-agent/leader upgrade version="7.7.7"
```

This will result in the vantage-agent package upgrade to 7.7.7.

Manually triggers the cleaning of vantage-agent's cache dir:

```bash
juju run-action vantage-agent/leader clear-cache-dir
```

#### License

* MIT (see `LICENSE` file in this directory for full preamble)
9 changes: 9 additions & 0 deletions actions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
upgrade-vtg:
description: >
Upgrade vantage agent.
params:
version:
type: string
description: Version of vantage agent to upgrade to.
required:
- version
15 changes: 15 additions & 0 deletions charmcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
type: charm
bases:
- build-on:
- name: ubuntu
channel: "22.04"
run-on:
- name: ubuntu
channel: "20.04"
architectures: [amd64]
- name: ubuntu
channel: "22.04"
architectures: [amd64]
parts:
charm:
charm-python-packages: [setuptools]
49 changes: 49 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
options:
# Resource URL
base-api-url:
type: string
default: ""
description: |
The Vantage API URL

# Slurm related setings
scontrol-path:
type: string
default: "/usr/bin/scontrol"
description: |
Absolute path to the scontrol command

# Auth related settings
oidc-domain:
type: string
default: ""
description: |
Domain for the OIDC provider API where auth tokens will be fetched
oidc-client-id:
type: string
default: ""
description: |
The ID for the OIDC provider app client to which tokens will be issued
oidc-client-secret:
type: string
default: ""
description: |
The secret key for the OIDC provider app client to which tokens will be issued

task-jobs-interval-seconds:
type: int
default: 30
description: |
The interval in seconds at which the agent will run internal jobs
task-self-update-interval-seconds:
type: int
default: 30
description: |
The interval in seconds at which the agent will check for version updates

# Other settings
cache-dir:
type: string
default: "/var/cache/vantage-agent"
description: |
Absolute path to the cache directory
45 changes: 45 additions & 0 deletions dispatch
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash
# This hook installs the dependencies needed to run the charm,
# creates the dispatch executable, regenerates the symlinks for start and
# upgrade-charm, and kicks off the operator framework.

set -e

# Source the os-release information into the env
. /etc/os-release

PYTHON_BIN=/opt/python/python3.12/bin/python3.12

if ! [[ -f '.installed' ]]
then
if [[ ! -e $PYTHON_BIN ]]
then
if [[ $ID == 'rocky' ]]
then
# Install dependencies to build custom python
yum -y install epel-release
yum -y install wget gcc make tar bzip2-devel zlib-devel xz-devel openssl-devel libffi-devel sqlite-devel ncurses-devel xz-devel gdbm tk-devel readline-devel sqlite-devel libnsl2-devel

# Install yaml deps
yum -y install libyaml-devel
fi

if [[ $ID == 'ubuntu' ]]
then
# Install dependencies to build custom python
apt install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
fi

export PYTHON_VERSION=3.12.1
wget https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.xz -P /tmp
tar xvf /tmp/Python-${PYTHON_VERSION}.tar.xz -C /tmp
cd /tmp/Python-${PYTHON_VERSION}
./configure --prefix=/opt/python/python3.12 --enable-optimizations
make -C /tmp/Python-${PYTHON_VERSION} -j $(nproc) altinstall
cd $OLDPWD
rm -rf /tmp/Python*
fi
touch .installed
fi

JUJU_DISPATCH_PATH="${JUJU_DISPATCH_PATH:-$0}" PYTHONPATH=lib:venv $PYTHON_BIN ./src/charm.py
28 changes: 28 additions & 0 deletions metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: vantage-agent
display-name: Vantage Agent
summary: Vantage Agent package lifecycle encapsulated in a charm
maintainers:
- Omnivector Corp <[email protected]>
description: |
This charm provides the Vantage Agent component of vantage.
It is a wrapper around the vantage-agent package, which is the core agent component of Vantage alongside the Jobbergate Agent.
tags:
- vantage
- hpc

subordinate: true

series:
- centos7
- centos8
- focal
- jammy

requires:
juju-info:
interface: juju-info
scope: container
prolog-epilog:
interface: prolog-epilog
fluentbit:
interface: fluentbit
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ops==1.3.0
Loading