Skip to content

Commit

Permalink
Improve K8s unit tests (#4196) [ci fast]
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Sherman <[email protected]>
Signed-off-by: Paolo Di Tommaso <[email protected]>
Co-authored-by: Paolo Di Tommaso <[email protected]>
  • Loading branch information
bentsherman and pditommaso authored Sep 17, 2023
1 parent 144e0a8 commit 5a43a32
Show file tree
Hide file tree
Showing 3 changed files with 256 additions and 812 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ class K8sDriverLauncherTest extends Specification {
def pod = Mock(PodOptions)
pod.getVolumeClaims() >> [ new PodVolumeClaim('pvc-1', '/mnt/path/data') ]
pod.getMountConfigMaps() >> [ new PodMountConfig('cfg-2', '/mnt/path/cfg') ]
pod.getAutomountServiceAccountToken() >> true

def k8s = Mock(K8sConfig)
k8s.getNextflowImageName() >> 'the-image'
Expand All @@ -163,6 +162,7 @@ class K8sDriverLauncherTest extends Specification {
kind: 'Pod',
metadata: [name:'foo-boo', namespace:'foo', labels:[app:'nextflow', runName:'foo-boo']],
spec: [
automountServiceAccountToken: false,
restartPolicy: 'Never',
containers: [
[
Expand Down Expand Up @@ -197,7 +197,6 @@ class K8sDriverLauncherTest extends Specification {
def pod = Mock(PodOptions)
pod.getVolumeClaims() >> [ new PodVolumeClaim('pvc-1', '/mnt/path/data') ]
pod.getMountConfigMaps() >> [ new PodMountConfig('cfg-2', '/mnt/path/cfg') ]
pod.getAutomountServiceAccountToken() >> true

def k8s = Mock(K8sConfig)
k8s.getNextflowImageName() >> 'the-image'
Expand Down Expand Up @@ -230,6 +229,7 @@ class K8sDriverLauncherTest extends Specification {
template: [
metadata: metadata,
spec: [
automountServiceAccountToken: false,
restartPolicy: 'Never',
containers: [
[
Expand Down Expand Up @@ -265,7 +265,6 @@ class K8sDriverLauncherTest extends Specification {
def pod = Mock(PodOptions)
pod.getVolumeClaims() >> [ new PodVolumeClaim('pvc-1', '/mnt/path/data') ]
pod.getMountConfigMaps() >> [ new PodMountConfig('cfg-2', '/mnt/path/cfg') ]
pod.getAutomountServiceAccountToken() >> true

def k8s = Mock(K8sConfig)
k8s.getLaunchDir() >> '/the/user/dir'
Expand All @@ -281,40 +280,11 @@ class K8sDriverLauncherTest extends Specification {
driver.@headImage = 'foo/bar'

when:
def spec = driver.makeLauncherSpec()
def result = driver.makeLauncherSpec()
then:
driver.getLaunchCli() >> 'nextflow run foo'

spec == [
apiVersion: 'v1',
kind: 'Pod',
metadata: [name:'foo-boo', namespace:'foo', labels:[app:'nextflow', runName:'foo-boo']],
spec: [
restartPolicy: 'Never',
containers: [
[
name: 'foo-boo',
image: 'foo/bar',
command: ['/bin/bash', '-c', "source /etc/nextflow/init.sh; nextflow run foo"],
env: [
[name:'NXF_WORK', value:'/the/work/dir'],
[name:'NXF_ASSETS', value:'/the/project/dir'],
[name:'NXF_EXECUTOR', value:'k8s'],
[name:'NXF_ANSI_LOG', value: 'false']
],
volumeMounts: [
[name:'vol-1', mountPath:'/mnt/path/data'],
[name:'vol-2', mountPath:'/mnt/path/cfg']
]
]
],
serviceAccountName: 'bar',
volumes: [
[name:'vol-1', persistentVolumeClaim:[claimName:'pvc-1']],
[name:'vol-2', configMap:[name:'cfg-2'] ]
]
]
]
and:
result.spec.containers[0].image == 'foo/bar'

}

Expand All @@ -324,9 +294,9 @@ class K8sDriverLauncherTest extends Specification {
def pod = Mock(PodOptions)
pod.getVolumeClaims() >> [ new PodVolumeClaim('pvc-1', '/mnt/path/data') ]
pod.getMountConfigMaps() >> [ new PodMountConfig('cfg-2', '/mnt/path/cfg') ]
pod.getAutomountServiceAccountToken() >> true

def k8s = Mock(K8sConfig)
k8s.getNextflowImageName() >> 'the-image'
k8s.getLaunchDir() >> '/the/user/dir'
k8s.getWorkDir() >> '/the/work/dir'
k8s.getProjectDir() >> '/the/project/dir'
Expand All @@ -337,48 +307,17 @@ class K8sDriverLauncherTest extends Specification {
driver.@runName = 'foo-boo'
driver.@k8sClient = new K8sClient(new ClientConfig(namespace: 'foo', serviceAccount: 'bar'))
driver.@k8sConfig = k8s
driver.@headImage = 'foo/bar'
driver.@headCpus = 2
driver.@headMemory = '200Mi'

when:
def spec = driver.makeLauncherSpec()
def result = driver.makeLauncherSpec()
then:
driver.getLaunchCli() >> 'nextflow run foo'

spec == [
apiVersion: 'v1',
kind: 'Pod',
metadata: [name:'foo-boo', namespace:'foo', labels:[app:'nextflow', runName:'foo-boo']],
spec: [
restartPolicy: 'Never',
containers: [
[
name: 'foo-boo',
image: 'foo/bar',
command: ['/bin/bash', '-c', "source /etc/nextflow/init.sh; nextflow run foo"],
env: [
[name:'NXF_WORK', value:'/the/work/dir'],
[name:'NXF_ASSETS', value:'/the/project/dir'],
[name:'NXF_EXECUTOR', value:'k8s'],
[name:'NXF_ANSI_LOG', value: 'false']
],
resources: [
requests: [cpu: 2, memory: '200Mi'],
limits: [memory: '200Mi']
],
volumeMounts: [
[name:'vol-1', mountPath:'/mnt/path/data'],
[name:'vol-2', mountPath:'/mnt/path/cfg']
]
]
],
serviceAccountName: 'bar',
volumes: [
[name:'vol-1', persistentVolumeClaim:[claimName:'pvc-1']],
[name:'vol-2', configMap:[name:'cfg-2'] ]
]
]
and:
result.spec.containers[0].resources == [
requests: [cpu: 2, memory: '200Mi'],
limits: [memory: '200Mi']
]

}
Expand Down
Loading

0 comments on commit 5a43a32

Please sign in to comment.