Skip to content

Commit

Permalink
config.labels as List, not Map, see change in Libseqera
Browse files Browse the repository at this point in the history
Signed-off-by: Dr Marco Claudio De La Pierre <marco.delapierre@gmail.com>
  • Loading branch information
marcodelapierre committed Apr 11, 2024
1 parent 72fc9e2 commit 4560207
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 29 deletions.
29 changes: 8 additions & 21 deletions app/src/main/java/io/seqera/wave/cli/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -384,13 +384,6 @@ protected void validateArgs() {
if( !isEmpty(platform) && !VALID_PLATFORMS.contains(platform) )
throw new IllegalCliArgumentException(String.format("Unsupported container platform: '%s'", platform));

// check labels
if( labels!=null ) {
for( String it : labels) {
if( !isLabel(it) ) throw new IllegalCliArgumentException("Invalid container image label syntax - offending value: " + it);
}
}

}

protected Client client() {
Expand Down Expand Up @@ -538,6 +531,14 @@ protected ContainerConfig prepareConfig() {
result.env = environment;
}

//add labels if specified
if( labels!=null ) {
for( String it : labels) {
if( !isLabel(it) ) throw new IllegalCliArgumentException("Invalid container image label syntax - offending value: " + it);
}
result.labels = labels;
}

//add the working directory if specified
if( workingDir != null ){
if( "".equals(workingDir.trim()) ) throw new IllegalCliArgumentException("The working directory cannot be empty string");
Expand Down Expand Up @@ -571,24 +572,10 @@ protected ContainerConfig prepareConfig() {
if( size>=10 * _1MB )
throw new RuntimeException("Compressed container layers cannot exceed 10 MiB");

result.labels = createLabelsMap(labels);
// return the result
return !result.empty() ? result : null;
}

private Map<String, String> createLabelsMap(List<String> labelList) {
if( labelList != null){
return labelList.stream()
.map(entry -> entry.split("="))
.filter(keyValue -> keyValue.length == 2)
.collect(Collectors.toMap(
keyValue -> keyValue[0],
keyValue -> keyValue[1]));
}
return null;
}


private ContainerInspectRequest inspectRequest(String image) {
return new ContainerInspectRequest()
.withContainerImage(image)
Expand Down
14 changes: 6 additions & 8 deletions app/src/test/groovy/io/seqera/wave/cli/AppTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -274,24 +274,22 @@ class AppTest extends Specification {
def "test valid labels"(){
given:
def app = new App()
String[] args = ["--label", "key1=value1","--label", "key2=value2","--label", "key3=this value", "--label", "maintainer=name@company.com"]
String[] args = ["--config-label", "key1=value1","--config-label", "key2=this value2", "--config-label", "maintainer=name@company.com"]

when:
new CommandLine(app).parseArgs(args)
then:
app.@labels[0] == "key1=value1"
app.@labels[1] == "key2=value2"
app.@labels[2] == "key3=this value"
app.@labels[3] == "maintainer=name@company.com"
app.@labels[1] == "key2=this value2"
app.@labels[2] == "maintainer=name@company.com"

when:
def config = app.prepareConfig()
then:
config.labels == [
"key1":"value1",
"key2":"value2",
"key3":"this value",
"maintainer":"name@company.com"
"key1=value1",
"key2=this value2",
"maintainer=name@company.com"
]
}
}

0 comments on commit 4560207

Please sign in to comment.