diff options
author | Viacheslav Hletenko <v.gletenko@vyos.io> | 2023-08-31 08:37:17 +0000 |
---|---|---|
committer | Viacheslav Hletenko <v.gletenko@vyos.io> | 2023-08-31 08:37:17 +0000 |
commit | 6dd0499f4cb97dd749f3f9aa5b649039ae7cf6c4 (patch) | |
tree | b4654a3f650537d04c405f5b131f4ef8cf2b06c7 | |
parent | af737cf57e53a08a53ec2037ee476ee9098d8216 (diff) | |
download | vyos-1x-6dd0499f4cb97dd749f3f9aa5b649039ae7cf6c4.tar.gz vyos-1x-6dd0499f4cb97dd749f3f9aa5b649039ae7cf6c4.zip |
T5531: Containers add label option
Ability to set labels for container
set container name c1 allow-host-networks
set container name c1 image 'busybox'
set container name c1 label mypods value 'My label for containers'
-rw-r--r-- | interface-definitions/container.xml.in | 20 | ||||
-rwxr-xr-x | src/conf_mode/container.py | 11 |
2 files changed, 31 insertions, 0 deletions
diff --git a/interface-definitions/container.xml.in b/interface-definitions/container.xml.in index baab6104f..8259e7bdf 100644 --- a/interface-definitions/container.xml.in +++ b/interface-definitions/container.xml.in @@ -145,6 +145,26 @@ <constraintErrorMessage>The command's arguments must be ascii characters, use &quot; and &apos for double and single quotes respectively</constraintErrorMessage> </properties> </leafNode> + <tagNode name="label"> + <properties> + <help>Add label variables</help> + <constraint> + <regex>[a-z0-9](?:[a-z0-9.-]*[a-z0-9])?</regex> + </constraint> + <constraintErrorMessage>Label variable name must be alphanumeric and can contain hyphen, dots and underscores</constraintErrorMessage> + </properties> + <children> + <leafNode name="value"> + <properties> + <help>Set label option value</help> + <valueHelp> + <format>txt</format> + <description>Set label option value</description> + </valueHelp> + </properties> + </leafNode> + </children> + </tagNode> <leafNode name="memory"> <properties> <help>Memory (RAM) available to this container</help> diff --git a/src/conf_mode/container.py b/src/conf_mode/container.py index 79b605ffb..46eb10714 100755 --- a/src/conf_mode/container.py +++ b/src/conf_mode/container.py @@ -178,6 +178,11 @@ def verify(container): if 'value' not in cfg: raise ConfigError(f'Environment variable {var} has no value assigned!') + if 'label' in container_config: + for var, cfg in container_config['label'].items(): + if 'value' not in cfg: + raise ConfigError(f'Label variable {var} has no value assigned!') + if 'volume' in container_config: for volume, volume_config in container_config['volume'].items(): if 'source' not in volume_config: @@ -268,6 +273,12 @@ def generate_run_arguments(name, container_config): for k, v in container_config['environment'].items(): env_opt += f" --env \"{k}={v['value']}\"" + # Check/set label options "--label foo=bar" + env_opt = '' + if 'label' in container_config: + for k, v in container_config['label'].items(): + env_opt += f" --label \"{k}={v['value']}\"" + hostname = '' if 'host_name' in container_config: hostname = container_config['host_name'] |