Skip to content

Commit

Permalink
fix(container.provider): Fixed empty gpus field in container provider (
Browse files Browse the repository at this point in the history
…#4090)

* Fixed empty gpus filed in container provider

Signed-off-by: pierantoniomerlino <[email protected]>

* Updated gpu field description

Signed-off-by: pierantoniomerlino <[email protected]>
  • Loading branch information
pierantoniomerlino authored Aug 4, 2022
1 parent 62afedb commit 98f3fa6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,16 @@
<AD id="container.memory" name="Memory"
description="The maximum amount of memory the container can use in bytes. Set it as a positive integer, optionally followed by a suffix of b, k, m, g, to indicate bytes, kilobytes, megabytes, or gigabytes.
The minimum allowed value is platform dependent (i.e. 6m). If left empty, the memory assigned to the container will be set to a default value by the native container orchestrator."
type="String" cardinality="1"
type="String" cardinality="0"
required="false" default="" />

<AD id="container.cpus" name="CPUs"
description="Specify how many CPUs a container can use. Decimal values are allowed, so if set to 1.5, the container will use at most one and a half cpu resource."
type="Float" cardinality="1"
type="Float" cardinality="0"
required="false" default="" />

<AD id="container.gpus" name="GPUs"
description="Specify how many Nvidia GPUs a container can use. Allowed values are 'all' or an integer number."
description="Specify how many Nvidia GPUs a container can use. Allowed values are 'all' or an integer number. If there's no Nvidia GPU installed, leave the field empty."
type="String" cardinality="1"
required="false" default="" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public ContainerInstanceOptions(final Map<String, Object> properties) {
this.restartOnFailure = CONTAINER_RESTART_FAILURE.get(properties);
this.containerMemory = parseMemoryString(CONTAINER_MEMORY.getOptional(properties));
this.containerCpus = CONTAINER_CPUS.getOptional(properties);
this.containerGpus = CONTAINER_GPUS.getOptional(properties);
this.containerGpus = parseGpusString(CONTAINER_GPUS.getOptional(properties));
}

private Map<String, String> parseVolume(String volumeString) {
Expand Down Expand Up @@ -212,6 +212,14 @@ private Optional<Long> parseMemoryString(Optional<String> value) {
}
}

private Optional<String> parseGpusString(Optional<String> gpus) {
if (gpus.isPresent() && gpus.get().isEmpty()) {
return Optional.empty();
} else {
return gpus;
}
}

public boolean isEnabled() {
return this.enabled;
}
Expand Down

0 comments on commit 98f3fa6

Please sign in to comment.