Skip to content

Commit

Permalink
labels arg renamed to provider-labels
Browse files Browse the repository at this point in the history
  • Loading branch information
rplevka committed Apr 3, 2024
1 parent e432d68 commit 83721f0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
12 changes: 6 additions & 6 deletions broker/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def cli(version):
@click.option("-c", "--count", type=int, help="Number of times broker repeats the checkout")
@click.option(
"-l",
"--labels",
"--provider-labels",
type=str,
help="A string representing the list"
" of k=v pairs (comma-separated) to be used as provider resource"
Expand All @@ -202,7 +202,7 @@ def cli(version):
)
@provider_options
@click.pass_context
def checkout(ctx, background, nick, count, args_file, labels, **kwargs):
def checkout(ctx, background, nick, count, args_file, provider_labels, **kwargs):
"""Checkout or "create" a Virtual Machine broker instance.
COMMAND: broker checkout --workflow "workflow-name" --workflow_arg1 something
Expand All @@ -216,10 +216,10 @@ def checkout(ctx, background, nick, count, args_file, labels, **kwargs):
broker_args["_count"] = count
if args_file:
broker_args["args_file"] = args_file
if labels:
broker_args["labels"] = {
f"broker.{label[0]}": "=".join(label[1:])
for label in [kv_pair.split("=") for kv_pair in labels.split(",")]
if provider_labels:
broker_args["provider_labels"] = {
label[0]: "=".join(label[1:])
for label in [kv_pair.split("=") for kv_pair in provider_labels.split(",")]
}

# if additional arguments were passed, include them in the broker args
Expand Down
2 changes: 1 addition & 1 deletion broker/providers/ansible_tower.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ def execute(self, **kwargs): # noqa: PLR0912,PLR0915 - Possible TODO refactor
if inventory := kwargs.pop("inventory", None):
payload["inventory"] = inventory
logger.info(f"Using tower inventory: {self._translate_inventory(inventory)}")
if labels := kwargs.pop("labels", None):
if labels := kwargs.pop("provider_labels", None):
payload["labels"] = self._resolve_labels(labels, target)
# record labels also as extra vars - use key=value format
kwargs.update(
Expand Down
11 changes: 10 additions & 1 deletion broker/providers/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,17 @@ def run_container(self, container_host, **kwargs):
if origin[1]:
envars["JENKINS_URL"] = origin[1]
kwargs["environment"] = envars
# prefix eventual label keys with 'broker.' to conform to the docker guidelines
# https://docs.docker.com/config/labels-custom-metadata/#key-format-recommendations
kwargs["provider_labels"] = {
f"broker.{label[0]}": label[1] for label in kwargs["provider_labels"].items()
}
# process eventual labels that were passed externally, split by "="
kwargs["labels"].update({"broker.origin": origin[0], "broker.jenkins.url": origin[1]})
kwargs["provider_labels"].update(
{"broker.origin": origin[0], "broker.jenkins.url": origin[1]}
)
# rename the dict key to the name of the arg recognized by provider
kwargs["labels"] = kwargs.pop("provider_labels")
container_inst = self.runtime.create_container(container_host, **kwargs)
container_inst.start()
return container_inst
Expand Down

0 comments on commit 83721f0

Please sign in to comment.