-
Notifications
You must be signed in to change notification settings - Fork 1
Add scaleset configurations #221
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
Open
yhaliaw
wants to merge
5
commits into
main
Choose a base branch
from
feat/garm-configurator-scaleset-config
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+275
−0
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -19,6 +19,17 @@ | |
| GITHUB_APP_INSTALLATION_ID_CONFIG_NAME = "github-app-installation-id" | ||
| GITHUB_APP_PRIVATE_KEY_CONFIG_NAME = "github-app-private-key" # nosec | ||
|
|
||
| SCALESET_NAME_CONFIG_NAME = "name" | ||
| SCALESET_FLAVOR_CONFIG_NAME = "flavor" | ||
| SCALESET_OS_ARCH_CONFIG_NAME = "os-arch" | ||
| SCALESET_MIN_IDLE_RUNNER_CONFIG_NAME = "min-idle-runner" | ||
| SCALESET_MAX_RUNNER_CONFIG_NAME = "max-runner" | ||
| SCALESET_LABELS_CONFIG_NAME = "labels" | ||
| SCALESET_REPO_CONFIG_NAME = "repo" | ||
| SCALESET_ORG_CONFIG_NAME = "org" | ||
| SCALESET_RUNNER_GROUP_CONFIG_NAME = "runner-group" | ||
| SCALESET_PRE_INSTALL_SCRIPTS_CONFIG_NAME = "pre-install-scripts" | ||
|
|
||
|
|
||
| class CharmConfigInvalidError(Exception): | ||
| """Raised when charm configuration is invalid. | ||
|
|
@@ -176,28 +187,130 @@ def from_charm(cls, charm: ops.CharmBase) -> "GithubAppConfig": | |
| ) | ||
|
|
||
|
|
||
| class ScalesetConfig(BaseModel): | ||
| """Scaleset configuration. | ||
|
|
||
| Attributes: | ||
| name: The name of the scaleset. | ||
| flavor: The resource flavor for runners. | ||
| os_arch: The CPU architecture for runners. | ||
| min_idle_runner: Minimum number of idle runners. | ||
| max_runner: Maximum number of runners. | ||
| labels: Comma-separated list of labels for runners. | ||
| repo: Repository to register runners to. | ||
| org: Organization to register runners to. | ||
| runner_group: Runner group for org registration. | ||
| pre_install_scripts: Script name to bash script pairs for pre-installation. | ||
| """ | ||
|
|
||
| name: str | ||
| flavor: str | ||
| os_arch: str | ||
| min_idle_runner: int | ||
| max_runner: int | ||
| labels: str = "" | ||
| repo: str | None = None | ||
| org: str | None = None | ||
| runner_group: str = "default" | ||
| pre_install_scripts: str | None = None | ||
|
|
||
| @classmethod | ||
| def from_charm(cls, charm: ops.CharmBase) -> "ScalesetConfig": | ||
| """Initialize the scaleset config from charm. | ||
|
|
||
| Args: | ||
| charm: The charm instance. | ||
|
|
||
| Raises: | ||
| CharmConfigInvalidError: If any configuration is missing or invalid. | ||
|
|
||
| Returns: | ||
| The parsed scaleset configuration. | ||
| """ | ||
| required_string_configs = ( | ||
| SCALESET_NAME_CONFIG_NAME, | ||
| SCALESET_FLAVOR_CONFIG_NAME, | ||
| SCALESET_OS_ARCH_CONFIG_NAME, | ||
| ) | ||
| for key in required_string_configs: | ||
| value = charm.config.get(key) | ||
| if not value or not str(value).strip(): | ||
| raise CharmConfigInvalidError(f"Missing required configuration: {key}") | ||
|
|
||
| min_idle_runner = int(charm.config.get(SCALESET_MIN_IDLE_RUNNER_CONFIG_NAME, 0)) | ||
| if min_idle_runner < 0: | ||
| raise CharmConfigInvalidError( | ||
| f"{SCALESET_MIN_IDLE_RUNNER_CONFIG_NAME} must be non-negative" | ||
| ) | ||
|
|
||
| max_runner = int(charm.config.get(SCALESET_MAX_RUNNER_CONFIG_NAME, 0)) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we add a check that max >= min? |
||
| if max_runner < 0: | ||
| raise CharmConfigInvalidError( | ||
| f"{SCALESET_MAX_RUNNER_CONFIG_NAME} must be non-negative" | ||
| ) | ||
|
|
||
| repo = charm.config.get(SCALESET_REPO_CONFIG_NAME) | ||
| repo = str(repo).strip() if repo else None | ||
| org = charm.config.get(SCALESET_ORG_CONFIG_NAME) | ||
| org = str(org).strip() if org else None | ||
| runner_group = str(charm.config.get(SCALESET_RUNNER_GROUP_CONFIG_NAME, "default")).strip() | ||
|
|
||
| if repo and org: | ||
| raise CharmConfigInvalidError( | ||
| f"{SCALESET_REPO_CONFIG_NAME} and {SCALESET_ORG_CONFIG_NAME} " | ||
| f"are mutually exclusive" | ||
| ) | ||
| if not repo and not org: | ||
| raise CharmConfigInvalidError( | ||
| f"At least one of {SCALESET_REPO_CONFIG_NAME} or " | ||
| f"{SCALESET_ORG_CONFIG_NAME} must be provided" | ||
| ) | ||
|
|
||
| labels = charm.config.get(SCALESET_LABELS_CONFIG_NAME) | ||
| labels = str(labels).strip() if labels else "" | ||
| pre_install_scripts = charm.config.get(SCALESET_PRE_INSTALL_SCRIPTS_CONFIG_NAME) | ||
| pre_install_scripts = str(pre_install_scripts) if pre_install_scripts else None | ||
|
|
||
| return cls( | ||
| name=str(charm.config.get(SCALESET_NAME_CONFIG_NAME)).strip(), | ||
| flavor=str(charm.config.get(SCALESET_FLAVOR_CONFIG_NAME)).strip(), | ||
| os_arch=str(charm.config.get(SCALESET_OS_ARCH_CONFIG_NAME)).strip(), | ||
| min_idle_runner=min_idle_runner, | ||
| max_runner=max_runner, | ||
| labels=labels, | ||
| repo=repo, | ||
| org=org, | ||
| runner_group=runner_group, | ||
| pre_install_scripts=pre_install_scripts, | ||
| ) | ||
|
|
||
|
|
||
| class CharmState: | ||
| """The charm state. | ||
|
|
||
| Attributes: | ||
| provider_config: OpenStack provider configuration. | ||
| github_app_config: GitHub App configuration. | ||
| scaleset_config: Scaleset configuration. | ||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| *, | ||
| provider_config: ProviderConfig, | ||
| github_app_config: GithubAppConfig, | ||
| scaleset_config: ScalesetConfig, | ||
| ) -> None: | ||
| """Initialize the charm state. | ||
|
|
||
| Args: | ||
| provider_config: The OpenStack provider configuration. | ||
| github_app_config: The GitHub App configuration. | ||
| scaleset_config: The scaleset configuration. | ||
| """ | ||
| self.provider_config = provider_config | ||
| self.github_app_config = github_app_config | ||
| self.scaleset_config = scaleset_config | ||
|
|
||
| @classmethod | ||
| def from_charm(cls, charm: ops.CharmBase) -> "CharmState": | ||
|
|
@@ -214,7 +327,9 @@ def from_charm(cls, charm: ops.CharmBase) -> "CharmState": | |
| """ | ||
| provider_config = ProviderConfig.from_charm(charm) | ||
| github_app_config = GithubAppConfig.from_charm(charm) | ||
| scaleset_config = ScalesetConfig.from_charm(charm) | ||
| return cls( | ||
| provider_config=provider_config, | ||
| github_app_config=github_app_config, | ||
| scaleset_config=scaleset_config, | ||
| ) | ||
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.