-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create relation "secrets" which allows to distribute secrets manifests to resource dispatcher. Secrets are distributed across namespaces. * On relation broken remove the secrets manifests of the relation from resource dispatcher container. * Create manifest tester charm for integration tests to test the relation.
- Loading branch information
Showing
17 changed files
with
567 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,5 @@ __pycache__/ | |
kubeconfig.tmp | ||
new_config | ||
.mypy_cache | ||
|
||
namespace-example.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
venv/ | ||
build/ | ||
*.charm | ||
.tox/ | ||
.coverage | ||
__pycache__/ | ||
*.py[cod] | ||
.idea | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright 2023 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
type: "charm" | ||
bases: | ||
- build-on: | ||
- name: "ubuntu" | ||
channel: "20.04" | ||
run-on: | ||
- name: "ubuntu" | ||
channel: "20.04" | ||
parts: | ||
charm: | ||
charm-python-packages: [setuptools, pip] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# This file defines charm config options, and populates the Configure tab on Charmhub. | ||
# If your charm does not require configuration options, delete this file entirely. | ||
# | ||
# See https://juju.is/docs/config for guidance. | ||
|
||
options: | ||
test_data: | ||
default: src/secrets | ||
type: string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright 2023 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
name: manifests-tester | ||
summary: | | ||
Charm for sending manifests to ResourceDispatcher relations. | ||
description: | | ||
Charm for sending manifests to ResourceDispatcher relations. | ||
provides: | ||
secrets: | ||
interface: secrets | ||
schema: | ||
v1: | ||
provides: | ||
type: object | ||
properties: | ||
secrets: | ||
type: string | ||
required: | ||
- secrets | ||
versions: [v1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ops | ||
pyyaml | ||
serialized-data-interface |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright 2023 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
# | ||
|
||
"""Mock relation provider charms.""" | ||
|
||
import glob | ||
import json | ||
import logging | ||
from pathlib import Path | ||
|
||
import yaml | ||
from ops.charm import CharmBase | ||
from ops.main import main | ||
from ops.model import ActiveStatus, BlockedStatus, WaitingStatus | ||
from serialized_data_interface import NoCompatibleVersions, NoVersionsListed, get_interfaces | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class ManifestsTesterCharm(CharmBase): | ||
"""Charm for sending manifests to ResourceDispatcher relations.""" | ||
|
||
def __init__(self, *args): | ||
super().__init__(*args) | ||
self._name = "manifests-tester" | ||
self._secrets_folder = self.model.config["test_data"] | ||
|
||
self.framework.observe(self.on.start, self._on_start) | ||
self.framework.observe(self.on.config_changed, self._on_event) | ||
|
||
for rel in self.model.relations.keys(): | ||
self.framework.observe(self.on[rel].relation_changed, self._on_event) | ||
|
||
def _on_start(self, _): | ||
"""Set active on start.""" | ||
self.model.unit.status = ActiveStatus() | ||
|
||
def _get_interfaces(self): | ||
"""Retrieve interface object.""" | ||
try: | ||
interfaces = get_interfaces(self) | ||
except NoVersionsListed: | ||
self.model.unit.status = WaitingStatus() | ||
return {"secrets": None} | ||
except NoCompatibleVersions: | ||
self.model.unit.status = BlockedStatus() | ||
return {"secrets": None} | ||
return interfaces | ||
|
||
def _send_manifests(self, interfaces, folder, relation): | ||
"""Send manifests from folder to desired relation.""" | ||
if relation in interfaces and interfaces[relation]: | ||
manifests = [] | ||
logger.info(f"Scanning folder {folder}") | ||
manifest_files = glob.glob(f"{folder}/*.yaml") | ||
for file in manifest_files: | ||
manifest = yaml.safe_load(Path(file).read_text()) | ||
manifests.append(manifest) | ||
data = {relation: json.dumps(manifests)} | ||
interfaces[relation].send_data(data) | ||
|
||
def _on_event(self, _) -> None: | ||
"""Perform all required actions for the Charm.""" | ||
interfaces = self._get_interfaces() | ||
self._send_manifests(interfaces, self._secrets_folder, "secrets") | ||
self.model.unit.status = ActiveStatus() | ||
|
||
|
||
if __name__ == "__main__": # pragma: nocover | ||
main(ManifestsTesterCharm) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: mlpipeline-minio-artifact | ||
stringData: | ||
AWS_ACCESS_KEY_ID: access_key | ||
AWS_SECRET_ACCESS_KEY: secret_access_key |
10 changes: 10 additions & 0 deletions
10
tests/integration/manifests-tester/src/secrets/secret2.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: seldon-rclone-secret | ||
stringData: | ||
RCLONE_CONFIG_MYS3_TYPE: test | ||
RCLONE_CONFIG_MYS3_PROVIDER: test | ||
RCLONE_CONFIG_MYS3_ACCESS_KEY_ID: test | ||
RCLONE_CONFIG_MYS3_SECRET_ACCESS_KEY: test | ||
RCLONE_CONFIG_MYS3_ENDPOINT: test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: mlpipeline-minio-artifact2 | ||
stringData: | ||
AWS_ACCESS_KEY_ID: access_key | ||
AWS_SECRET_ACCESS_KEY: secret_access_key |
10 changes: 10 additions & 0 deletions
10
tests/integration/manifests-tester/src/secrets2/secret2.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: seldon-rclone-secret2 | ||
stringData: | ||
RCLONE_CONFIG_MYS3_TYPE: test | ||
RCLONE_CONFIG_MYS3_PROVIDER: test | ||
RCLONE_CONFIG_MYS3_ACCESS_KEY_ID: test | ||
RCLONE_CONFIG_MYS3_SECRET_ACCESS_KEY: test | ||
RCLONE_CONFIG_MYS3_ENDPOINT: test |
Oops, something went wrong.