Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated k8s client to 21.0.0 #553

Merged
merged 30 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4ace0b5
updated k8s client
munishchouhan Jul 5, 2024
f27630c
Merge branch 'master' into update-k8s-client-21.0.0
munishchouhan Jul 8, 2024
a99cc3e
Merge branch 'master' into update-k8s-client-21.0.0
munishchouhan Jul 8, 2024
6b3a974
update more dependencies
munishchouhan Jul 8, 2024
fe5fd53
Merge branch 'master' into update-k8s-client-21.0.0
munishchouhan Jul 9, 2024
1c7ed96
Merge branch 'master' into update-k8s-client-21.0.0
munishchouhan Jul 12, 2024
62b9bfd
added withOverhead(null)
munishchouhan Jul 19, 2024
fec2425
Merge branch 'master' into update-k8s-client-21.0.0
munishchouhan Jul 22, 2024
0e36332
Merge branch 'master' into update-k8s-client-21.0.0
munishchouhan Jul 22, 2024
b8eb0cb
fixed tests
munishchouhan Jul 22, 2024
27866eb
Merge branch 'master' into update-k8s-client-21.0.0
munishchouhan Aug 2, 2024
ea20c91
Merge branch 'master' into update-k8s-client-21.0.0
munishchouhan Aug 28, 2024
41110e9
fixed errors
munishchouhan Aug 28, 2024
888a891
Merge branch 'master' into update-k8s-client-21.0.0
munishchouhan Aug 29, 2024
6a01864
Merge branch 'master' into update-k8s-client-21.0.0
munishchouhan Oct 28, 2024
9ea01c2
Bump logback-classic:1.4.14
pditommaso Nov 2, 2024
e4314a3
Merge branch 'master' into update-k8s-client-21.0.0
pditommaso Nov 2, 2024
ff419d5
Merge branch 'master' into update-k8s-client-21.0.0
munishchouhan Nov 18, 2024
8553fbc
fixed error
munishchouhan Nov 18, 2024
cd8af8e
added job label selector
munishchouhan Nov 18, 2024
362903f
fixed tests
munishchouhan Nov 18, 2024
51a1a55
Merge branch 'master' into update-k8s-client-21.0.0
munishchouhan Nov 18, 2024
6b0c3e0
[release] bump 1.15.1-A1
munishchouhan Nov 18, 2024
8260c4b
revert VERSION [ci skip]
munishchouhan Nov 19, 2024
62b97b3
minor change [ci skip]
munishchouhan Nov 19, 2024
9fdadd8
Merge branch 'master' into update-k8s-client-21.0.0
pditommaso Nov 22, 2024
206e013
Added Foreground propagationPolicy
munishchouhan Nov 24, 2024
002aa73
Merge branch 'master' into update-k8s-client-21.0.0
munishchouhan Nov 24, 2024
8d46fb7
Remove K8s withOverhead [ci skip]
pditommaso Nov 25, 2024
fe2c76b
Bump K8s client 21.0.1
pditommaso Nov 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ dependencies {
implementation 'io.micronaut.reactor:micronaut-reactor-http-client'
implementation 'org.apache.commons:commons-compress:1.27.1'
implementation 'org.apache.commons:commons-lang3:3.17.0'
implementation 'io.kubernetes:client-java:19.0.0'
implementation 'io.kubernetes:client-java-api-fluent:18.0.1'
implementation 'io.kubernetes:client-java:21.0.1'
implementation 'io.kubernetes:client-java-api-fluent:21.0.1'
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310'
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml'
Expand Down
32 changes: 20 additions & 12 deletions src/main/groovy/io/seqera/wave/service/k8s/K8sServiceImpl.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
import io.kubernetes.client.custom.Quantity
import io.kubernetes.client.openapi.models.V1ContainerBuilder
import io.kubernetes.client.openapi.models.V1DeleteOptions
import io.kubernetes.client.openapi.models.V1EnvVar
import io.kubernetes.client.openapi.models.V1HostPathVolumeSource
import io.kubernetes.client.openapi.models.V1Job
Expand Down Expand Up @@ -144,7 +143,8 @@ class K8sServiceImpl implements K8sService {
JobStatus getJobStatus(String name) {
final job = k8sClient
.batchV1Api()
.readNamespacedJob(name, namespace, null)
.readNamespacedJob(name, namespace)
.execute()
if( !job ) {
log.warn "K8s job=$name - unknown"
return null
Expand Down Expand Up @@ -178,7 +178,8 @@ class K8sServiceImpl implements K8sService {
V1Pod getPod(String name) {
return k8sClient
.coreV1Api()
.readNamespacedPod(name, namespace, null)
.readNamespacedPod(name, namespace)
.execute()
}

/**
Expand Down Expand Up @@ -293,7 +294,6 @@ class K8sServiceImpl implements K8sService {
.withRestartPolicy("Never")
.addAllToVolumes(volumes)


final requests = new V1ResourceRequirements()
if( requestsCpu )
requests.putRequestsItem('cpu', new Quantity(requestsCpu))
Expand Down Expand Up @@ -356,7 +356,8 @@ class K8sServiceImpl implements K8sService {
void deletePod(String name) {
k8sClient
.coreV1Api()
.deleteNamespacedPod(name, namespace, (String)null, (String)null, (Integer)null, (Boolean)null, (String)null, (V1DeleteOptions)null)
.deleteNamespacedPod(name, namespace)
.execute()
}

@Deprecated
Expand Down Expand Up @@ -391,7 +392,6 @@ class K8sServiceImpl implements K8sService {
.withRestartPolicy("Never")
.addAllToVolumes(volumes)


final requests = new V1ResourceRequirements()
if( scanConfig.requestsCpu )
requests.putRequestsItem('cpu', new Quantity(scanConfig.requestsCpu))
Expand Down Expand Up @@ -431,7 +431,8 @@ class K8sServiceImpl implements K8sService {

return k8sClient
.batchV1Api()
.createNamespacedJob(namespace, spec, null, null, null,null)
.createNamespacedJob(namespace, spec)
.execute()
}

V1Job createTransferJobSpec(String name, String containerImage, List<String> args, BlobCacheConfig blobConfig) {
Expand Down Expand Up @@ -494,7 +495,8 @@ class K8sServiceImpl implements K8sService {
final spec = buildJobSpec(name, containerImage, args, workDir, creds, timeout, nodeSelector)
return k8sClient
.batchV1Api()
.createNamespacedJob(namespace, spec, null, null, null,null)
.createNamespacedJob(namespace, spec)
.execute()
}

V1Job buildJobSpec(String name, String containerImage, List<String> args, Path workDir, Path credsFile, Duration timeout, Map<String,String> nodeSelector) {
Expand Down Expand Up @@ -583,7 +585,8 @@ class K8sServiceImpl implements K8sService {
final spec = scanJobSpec(name, containerImage, args, workDir, creds, scanConfig)
return k8sClient
.batchV1Api()
.createNamespacedJob(namespace, spec, null, null, null,null)
.createNamespacedJob(namespace, spec)
.execute()
}

V1Job scanJobSpec(String name, String containerImage, List<String> args, Path workDir, Path credsFile, ScanConfig scanConfig) {
Expand Down Expand Up @@ -650,7 +653,8 @@ class K8sServiceImpl implements K8sService {
final spec = mirrorJobSpec(name, containerImage, args, workDir, creds, config)
return k8sClient
.batchV1Api()
.createNamespacedJob(namespace, spec, null, null, null,null)
.createNamespacedJob(namespace, spec)
.execute()
}

V1Job mirrorJobSpec(String name, String containerImage, List<String> args, Path workDir, Path credsFile, MirrorConfig config) {
Expand Down Expand Up @@ -722,15 +726,19 @@ class K8sServiceImpl implements K8sService {
void deleteJob(String name) {
k8sClient
.batchV1Api()
.deleteNamespacedJob(name, namespace, null, null, null, null,"Foreground", null)
.deleteNamespacedJob(name, namespace)
.propagationPolicy("Foreground")
.execute()
}

@Override
V1Pod getLatestPodForJob(String jobName) {
// list all pods for the given job
final allPods = k8sClient
.coreV1Api()
.listNamespacedPod(namespace, null, null, null, null, "job-name=${jobName}", null, null, null, null, null, null)
.listNamespacedPod(namespace)
.labelSelector("job-name=${jobName}")
.execute()

if( !allPods || !allPods.items )
return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,11 +513,16 @@ class K8sServiceImplTest extends Specification {
def "getLatestPodForJob should return the latest pod when multiple pods are present"() {
given:
def jobName = "test-job"
def namespace = "test-ns"
def pod1 = new V1Pod().metadata(new V1ObjectMeta().creationTimestamp(OffsetDateTime.now().minusDays(1)))
def pod2 = new V1Pod().metadata(new V1ObjectMeta().creationTimestamp(OffsetDateTime.now()))
def allPods = new V1PodList().items(Arrays.asList(pod1, pod2))
def api = Mock(CoreV1Api)
api.listNamespacedPod(_, _, _, _, _, "job-name=${jobName}", _, _, _, _, _, _) >> allPods
def podRequest2 = Mock(CoreV1Api. APIlistNamespacedPodRequest)
podRequest2.execute() >> allPods
def podRequest1 = Mock(CoreV1Api. APIlistNamespacedPodRequest)
podRequest1.labelSelector("job-name=${jobName}") >> podRequest2
api.listNamespacedPod(namespace) >> podRequest1
def k8sClient = new K8sClient() {
@Override
ApiClient apiClient() {
Expand All @@ -528,7 +533,7 @@ class K8sServiceImplTest extends Specification {
}
}
and:
def k8sService = new K8sServiceImpl(k8sClient: k8sClient)
def k8sService = new K8sServiceImpl(k8sClient: k8sClient, namespace: namespace)

when:
def latestPod = k8sService.getLatestPodForJob(jobName)
Expand All @@ -540,8 +545,13 @@ class K8sServiceImplTest extends Specification {
def "getLatestPodForJob should return null when no pod is present"() {
given:
def jobName = "test-job"
def namespace = "test-ns"
def api = Mock(CoreV1Api)
api.listNamespacedPod(_, _, _, _, _, "job-name=${jobName}", _, _, _, _, _, _) >> null
def podRequest2 = Mock(CoreV1Api. APIlistNamespacedPodRequest)
podRequest2.execute() >> null
def podRequest1 = Mock(CoreV1Api. APIlistNamespacedPodRequest)
podRequest1.labelSelector("job-name=${jobName}") >> podRequest2
api.listNamespacedPod(namespace) >> podRequest1
def k8sClient = new K8sClient() {
@Override
ApiClient apiClient() {
Expand All @@ -552,7 +562,7 @@ class K8sServiceImplTest extends Specification {
}
}
and:
def k8sService = new K8sServiceImpl(k8sClient: k8sClient)
def k8sService = new K8sServiceImpl(k8sClient: k8sClient, namespace: namespace)

when:
def latestPod = k8sService.getLatestPodForJob(jobName)
Expand Down Expand Up @@ -826,7 +836,7 @@ class K8sServiceImplTest extends Specification {
job.spec.backoffLimit == 3
job.spec.template.spec.containers[0].image == containerImage
job.spec.template.spec.containers[0].args == args
job.spec.template.spec.containers[0].resources.requests == null
job.spec.template.spec.containers[0].resources.requests == [:]
job.spec.template.spec.containers[0].env == [new V1EnvVar().name('REGISTRY_AUTH_FILE').value('/tmp/config.json')]
and:
job.spec.template.spec.containers[0].volumeMounts.size() == 2
Expand Down Expand Up @@ -886,7 +896,7 @@ class K8sServiceImplTest extends Specification {
job.spec.backoffLimit == 3
job.spec.template.spec.containers[0].image == containerImage
job.spec.template.spec.containers[0].args == args
job.spec.template.spec.containers[0].resources.requests == null
job.spec.template.spec.containers[0].resources.requests == [:]
job.spec.template.spec.volumes.size() == 1
job.spec.template.spec.volumes[0].persistentVolumeClaim.claimName == 'bar'
job.spec.template.spec.restartPolicy == 'Never'
Expand Down Expand Up @@ -973,11 +983,14 @@ class K8sServiceImplTest extends Specification {
def api = Mock(BatchV1Api)
def client = Mock(K8sClient) { batchV1Api()>>api }
def service = Spy(new K8sServiceImpl(namespace:NS, k8sClient: client))
def jobRequest = Mock(BatchV1Api. APIreadNamespacedJobRequest)

when:
def status = service.getJobStatus(NAME)

then:
1 * api.readNamespacedJob(NAME, NS, null) >> JOB
jobRequest.execute() >> JOB
1 * api.readNamespacedJob(NAME, NS) >> jobRequest
and:
status == EXPECTED

Expand Down