-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: munishchouhan <[email protected]>
- Loading branch information
1 parent
080d5cc
commit 68c6523
Showing
6 changed files
with
171 additions
and
8 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
src/main/groovy/io/seqera/wave/configuration/K8sTolerationsConfig.groovy
This file contains 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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Wave, containers provisioning service | ||
* Copyright (c) 2024, Seqera Labs | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package io.seqera.wave.configuration | ||
|
||
import io.micronaut.context.annotation.ConfigurationProperties | ||
import io.micronaut.core.annotation.Introspected | ||
/** | ||
* kubernetes toleration config | ||
* | ||
* @author Munish Chouhan <[email protected]> | ||
*/ | ||
@Introspected | ||
@ConfigurationProperties('wave.build.k8s.tolerations') | ||
class K8sTolerationsConfig { | ||
boolean enabled; | ||
List<Toleration> arm64; | ||
List<Toleration> amd64; | ||
|
||
static class Toleration { | ||
String key; | ||
String value; | ||
String operator; | ||
String effect; | ||
} | ||
} |
This file contains 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 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 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 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 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 |
---|---|---|
|
@@ -23,6 +23,7 @@ import spock.lang.Unroll | |
|
||
import java.nio.file.Path | ||
import java.time.Duration | ||
import java.time.Instant | ||
import java.time.OffsetDateTime | ||
|
||
import io.kubernetes.client.custom.Quantity | ||
|
@@ -40,6 +41,8 @@ import io.micronaut.context.ApplicationContext | |
import io.seqera.wave.configuration.BlobCacheConfig | ||
import io.seqera.wave.configuration.MirrorConfig | ||
import io.seqera.wave.configuration.ScanConfig | ||
import io.seqera.wave.core.ContainerPlatform | ||
|
||
/** | ||
* | ||
* @author Paolo Di Tommaso <[email protected]> | ||
|
@@ -583,7 +586,7 @@ class K8sServiceImplTest extends Specification { | |
def nodeSelector = [key: 'value'] | ||
|
||
when: | ||
def job = k8sService.buildJobSpec(name, containerImage, args, workDir, credsFile, timeout, nodeSelector) | ||
def job = k8sService.buildJobSpec(name, containerImage, args, workDir, credsFile, timeout, nodeSelector, ContainerPlatform.of('arm64')) | ||
|
||
then: | ||
job.spec.backoffLimit == 3 | ||
|
@@ -635,7 +638,7 @@ class K8sServiceImplTest extends Specification { | |
def nodeSelector = [key: 'value'] | ||
|
||
when: | ||
def job = k8sService.buildJobSpec(name, containerImage, args, workDir, credsFile, timeout, nodeSelector) | ||
def job = k8sService.buildJobSpec(name, containerImage, args, workDir, credsFile, timeout, nodeSelector, ContainerPlatform.of('amd64')) | ||
|
||
then: | ||
job.spec.template.spec.containers[0].image == containerImage | ||
|
@@ -992,4 +995,82 @@ class K8sServiceImplTest extends Specification { | |
jobStarted() | K8sService.JobStatus.Pending | ||
jobUnknown() | K8sService.JobStatus.Pending | ||
} | ||
|
||
def 'should add tolerations for arm64 in pod spec' () { | ||
given: | ||
def PROPS = [ | ||
'wave.build.workspace': '/build/work', | ||
'wave.build.k8s.namespace': 'foo', | ||
'wave.build.k8s.configPath': '/home/kube.config', | ||
'wave.build.k8s.storage.claimName': 'bar', | ||
'wave.build.k8s.storage.mountPath': '/build', | ||
'wave.build.k8s.tolerations.enabled': true, | ||
'wave.build.k8s.tolerations.arm64[0].key': 'arch', | ||
'wave.build.k8s.tolerations.arm64[0].value': 'arm64', | ||
'wave.build.k8s.tolerations.arm64[0].operator': 'Equal', | ||
'wave.build.k8s.tolerations.arm64[0].effect': 'NoSchedule'] | ||
and: | ||
def ctx = ApplicationContext.run(PROPS) | ||
def k8sService = ctx.getBean(K8sServiceImpl) | ||
|
||
when: | ||
def result = k8sService.buildJobSpec('foo', 'my-image:latest', ['this','that'], Path.of('/build/work/xyz'), Path.of('/build/work/xyz/config.json'), Duration.ofMinutes(1), [:], ContainerPlatform.of('arm64')) | ||
|
||
then: 'should set the tolerations for arm64' | ||
result.spec.template.spec.tolerations.get(0).key == 'arch' | ||
result.spec.template.spec.tolerations.get(0).value == 'arm64' | ||
result.spec.template.spec.tolerations.get(0).operator == 'Equal' | ||
result.spec.template.spec.tolerations.get(0).effect == 'NoSchedule' | ||
|
||
when: | ||
result = k8sService.buildJobSpec('foo', 'my-image:latest', ['this','that'], Path.of('/build/work/xyz'), Path.of('/build/work/xyz/config.json'), Duration.ofMinutes(1), [:], ContainerPlatform.of('amd64')) | ||
|
||
then: 'should not set the toleration for amd64' | ||
result.spec.template.spec.tolerations == null | ||
|
||
when: | ||
result = k8sService.buildJobSpec('foo', 'my-image:latest', ['this','that'], Path.of('/build/work/xyz'), Path.of('/build/work/xyz/config.json'), Duration.ofMinutes(1), [:], null) | ||
|
||
then: 'should not throw NPE' | ||
result.spec.template.spec.tolerations == null | ||
} | ||
|
||
def 'should add tolerations for amd64 in pod spec' () { | ||
given: | ||
def PROPS = [ | ||
'wave.build.workspace': '/build/work', | ||
'wave.build.k8s.namespace': 'foo', | ||
'wave.build.k8s.configPath': '/home/kube.config', | ||
'wave.build.k8s.storage.claimName': 'bar', | ||
'wave.build.k8s.storage.mountPath': '/build', | ||
'wave.build.k8s.tolerations.enabled': true, | ||
'wave.build.k8s.tolerations.amd64[0].key': 'arch', | ||
'wave.build.k8s.tolerations.amd64[0].value': 'amd64', | ||
'wave.build.k8s.tolerations.amd64[0].operator': 'Equal', | ||
'wave.build.k8s.tolerations.amd64[0].effect': 'NoSchedule'] | ||
and: | ||
def ctx = ApplicationContext.run(PROPS) | ||
def k8sService = ctx.getBean(K8sServiceImpl) | ||
|
||
when: | ||
def result = k8sService.buildJobSpec('foo', 'my-image:latest', ['this','that'], Path.of('/build/work/xyz'), Path.of('/build/work/xyz/config.json'), Duration.ofMinutes(1), [:], ContainerPlatform.of('amd64')) | ||
|
||
then: 'should set the tolerations for amd64' | ||
result.spec.template.spec.tolerations.get(0).key == 'arch' | ||
result.spec.template.spec.tolerations.get(0).value == 'amd64' | ||
result.spec.template.spec.tolerations.get(0).operator == 'Equal' | ||
result.spec.template.spec.tolerations.get(0).effect == 'NoSchedule' | ||
|
||
when: | ||
result = k8sService.buildJobSpec('foo', 'my-image:latest', ['this','that'], Path.of('/build/work/xyz'), Path.of('/build/work/xyz/config.json'), Duration.ofMinutes(1), [:], ContainerPlatform.of('arm64')) | ||
|
||
then: 'should not set the toleration for arm64' | ||
result.spec.template.spec.tolerations == null | ||
|
||
when: | ||
result = k8sService.buildJobSpec('foo', 'my-image:latest', ['this','that'], Path.of('/build/work/xyz'), Path.of('/build/work/xyz/config.json'), Duration.ofMinutes(1), [:], null) | ||
|
||
then: 'should not throw NPE' | ||
result.spec.template.spec.tolerations == null | ||
} | ||
} |