Skip to content

Commit

Permalink
added ttlSecondsAfterFinished
Browse files Browse the repository at this point in the history
Signed-off-by: munishchouhan <[email protected]>
  • Loading branch information
munishchouhan committed Dec 13, 2024
1 parent eddc9ee commit 9c8f51b
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ class BlobCacheConfig {
@Value('${wave.blobCache.transfer.executor-shutdown-timeout:20s}')
Duration transferExecutorShutdownTimeout

@Value('${wave.blob.k8s.job.retention.duration:30d}')
Duration jobRetentionDuration

Map<String,String> getEnvironment() {
final result = new HashMap<String,String>(10)
if( storageRegion ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ class BuildConfig {
@Value('${wave.build.max-container-file-size:10000}')
int maxContainerFileSize

@Value('${wave.build.k8s.job.retention.duration:30d}')
Duration jobRetentionDuration

@PostConstruct
private void init() {
log.info("Builder config: " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,7 @@ class MirrorConfig {
@Value('${wave.mirror.requestsMemory}')
String requestsMemory

@Value('${wave.mirror.k8s.job.retention.duration:30d}')
Duration jobRetentionDuration

}
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ class ScanConfig {
@Value('${wave.scan.vulnerability.limit:100}')
Integer vulnerabilityLimit

@Value('${wave.scan.k8s.job.retention.duration:30d}')
Duration jobRetentionDuration

String getScanImage() {
return scanImage
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ class K8sServiceImpl implements K8sService {

//spec section
def spec = builder.withNewSpec()
.withTtlSecondsAfterFinished(blobConfig.jobRetentionDuration.toSeconds() as Integer)
.withBackoffLimit(blobConfig.retryAttempts)
.withNewTemplate()
.editOrNewSpec()
Expand Down Expand Up @@ -534,6 +535,7 @@ class K8sServiceImpl implements K8sService {
//spec section
def spec = builder
.withNewSpec()
.withTtlSecondsAfterFinished(buildConfig.jobRetentionDuration.toSeconds() as Integer)
.withBackoffLimit(buildConfig.retryAttempts)
.withNewTemplate()
.withNewMetadata()
Expand Down Expand Up @@ -614,6 +616,7 @@ class K8sServiceImpl implements K8sService {
//spec section
def spec = builder
.withNewSpec()
.withTtlSecondsAfterFinished(scanConfig.jobRetentionDuration.toSeconds() as Integer)
.withBackoffLimit(scanConfig.retryAttempts)
.withNewTemplate()
.editOrNewSpec()
Expand Down Expand Up @@ -682,6 +685,7 @@ class K8sServiceImpl implements K8sService {
//spec section
def spec = builder
.withNewSpec()
.withTtlSecondsAfterFinished(config.jobRetentionDuration.toSeconds() as Integer)
.withBackoffLimit(config.retryAttempts)
.withNewTemplate()
.editOrNewSpec()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ class K8sServiceImplTest extends Specification {
def config = Mock(BlobCacheConfig) {
getEnvironment() >> [:]
getRetryAttempts() >> 5
getJobRetentionDuration() >> Duration.ofDays(1)
}

when:
Expand All @@ -455,6 +456,7 @@ class K8sServiceImplTest extends Specification {
result.metadata.name == 'foo'
result.metadata.namespace == 'my-ns'
and:
result.spec.ttlSecondsAfterFinished == Duration.ofDays(1).toSeconds() as Integer
result.spec.backoffLimit == 5
and:
verifyAll(result.spec.template.spec) {
Expand Down Expand Up @@ -484,6 +486,7 @@ class K8sServiceImplTest extends Specification {
getRequestsCpu() >> '2'
getRequestsMemory() >> '8Gi'
getRetryAttempts() >> 3
getJobRetentionDuration() >> Duration.ofDays(1)
}

when:
Expand All @@ -492,6 +495,7 @@ class K8sServiceImplTest extends Specification {
result.metadata.name == 'foo'
result.metadata.namespace == 'my-ns'
and:
result.spec.ttlSecondsAfterFinished == Duration.ofDays(1).toSeconds() as Integer
result.spec.backoffLimit == 3
and:
verifyAll(result.spec.template.spec) {
Expand Down Expand Up @@ -579,7 +583,8 @@ class K8sServiceImplTest extends Specification {
'wave.build.k8s.configPath': '/home/kube.config',
'wave.build.k8s.storage.claimName': 'build-claim',
'wave.build.k8s.storage.mountPath': '/build',
'wave.build.retry-attempts': 3
'wave.build.retry-attempts': 3,
'wave.build.k8s.job.retention.duration': Duration.ofDays(1)
]
and:
def ctx = ApplicationContext.run(PROPS)
Expand All @@ -596,6 +601,7 @@ class K8sServiceImplTest extends Specification {
def job = k8sService.buildJobSpec(name, containerImage, args, workDir, credsFile, timeout, nodeSelector)

then:
job.spec.ttlSecondsAfterFinished == Duration.ofDays(1).toSeconds() as Integer
job.spec.backoffLimit == 3
job.spec.template.spec.containers[0].image == containerImage
job.spec.template.spec.containers[0].command == args
Expand Down Expand Up @@ -695,6 +701,7 @@ class K8sServiceImplTest extends Specification {
getRequestsCpu() >> '2'
getRequestsMemory() >> '4Gi'
getEnvironmentAsTuples() >> [new Tuple2<String, String>('FOO', 'abc'), new Tuple2<String, String>('BAR', 'xyz')]
getJobRetentionDuration() >> Duration.ofDays(1)
}

when:
Expand Down Expand Up @@ -738,6 +745,7 @@ class K8sServiceImplTest extends Specification {
getCacheDirectory() >> Path.of('/build/cache/dir')
getRequestsCpu() >> '2'
getRequestsMemory() >> '4Gi'
getJobRetentionDuration() >> Duration.ofDays(1)
}

when:
Expand Down Expand Up @@ -781,6 +789,7 @@ class K8sServiceImplTest extends Specification {
getRequestsCpu() >> '2'
getRequestsMemory() >> '4Gi'
getRetryAttempts() >> 3
getJobRetentionDuration() >> Duration.ofDays(1)
}

when:
Expand Down Expand Up @@ -825,6 +834,7 @@ class K8sServiceImplTest extends Specification {
getRequestsCpu() >> null
getRequestsMemory() >> null
getRetryAttempts() >> 3
getJobRetentionDuration() >> Duration.ofDays(1)
}

when:
Expand All @@ -833,6 +843,7 @@ class K8sServiceImplTest extends Specification {
then:
job.metadata.name == name
job.metadata.namespace == 'foo'
job.spec.ttlSecondsAfterFinished == Duration.ofDays(1).toSeconds() as Integer
job.spec.backoffLimit == 3
job.spec.template.spec.containers[0].image == containerImage
job.spec.template.spec.containers[0].args == args
Expand Down Expand Up @@ -885,6 +896,7 @@ class K8sServiceImplTest extends Specification {
getRequestsCpu() >> null
getRequestsMemory() >> null
getRetryAttempts() >> 3
getJobRetentionDuration() >> Duration.ofDays(1)
}

when:
Expand All @@ -893,6 +905,7 @@ class K8sServiceImplTest extends Specification {
then:
job.metadata.name == name
job.metadata.namespace == 'foo'
job.spec.ttlSecondsAfterFinished == Duration.ofDays(1).toSeconds() as Integer
job.spec.backoffLimit == 3
job.spec.template.spec.containers[0].image == containerImage
job.spec.template.spec.containers[0].args == args
Expand Down

0 comments on commit 9c8f51b

Please sign in to comment.