From 1414aafb229e98835211529caa024eab71b8828a Mon Sep 17 00:00:00 2001 From: Matteo Saloni Date: Thu, 11 Jul 2024 14:06:41 +0200 Subject: [PATCH] fix: fix k8s init config map and cleanup --- .../infrastructure/k8s/K8sBaseFramework.java | 103 ++++++++++++++++++ .../k8s/K8sCronJobFramework.java | 11 ++ .../k8s/K8sDeploymentFramework.java | 86 ++------------- .../infrastructure/k8s/K8sJobFramework.java | 86 ++------------- .../infrastructure/k8s/K8sServeFramework.java | 86 ++------------- .../k8s/runnables/K8sCronJobRunnable.java | 9 -- .../k8s/runnables/K8sDeploymentRunnable.java | 10 -- .../k8s/runnables/K8sJobRunnable.java | 9 -- .../framework/k8s/runnables/K8sRunnable.java | 8 ++ .../k8s/runnables/K8sServeRunnable.java | 9 -- 10 files changed, 143 insertions(+), 274 deletions(-) diff --git a/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sBaseFramework.java b/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sBaseFramework.java index ba81f000c..c4f5cbcf2 100644 --- a/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sBaseFramework.java +++ b/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sBaseFramework.java @@ -9,9 +9,11 @@ import io.kubernetes.client.openapi.ApiClient; import io.kubernetes.client.openapi.ApiException; import io.kubernetes.client.openapi.apis.CoreV1Api; +import io.kubernetes.client.openapi.models.V1ConfigMap; import io.kubernetes.client.openapi.models.V1EnvFromSource; import io.kubernetes.client.openapi.models.V1EnvVar; import io.kubernetes.client.openapi.models.V1LocalObjectReference; +import io.kubernetes.client.openapi.models.V1ObjectMeta; import io.kubernetes.client.openapi.models.V1Pod; import io.kubernetes.client.openapi.models.V1PodList; import io.kubernetes.client.openapi.models.V1ResourceRequirements; @@ -23,18 +25,23 @@ import it.smartcommunitylabdhub.commons.infrastructure.Framework; import it.smartcommunitylabdhub.commons.jackson.JacksonMapper; import it.smartcommunitylabdhub.commons.models.enums.State; +import it.smartcommunitylabdhub.commons.utils.MapUtils; import it.smartcommunitylabdhub.framework.k8s.exceptions.K8sFrameworkException; import it.smartcommunitylabdhub.framework.k8s.jackson.IntOrStringMixin; import it.smartcommunitylabdhub.framework.k8s.kubernetes.K8sBuilderHelper; import it.smartcommunitylabdhub.framework.k8s.kubernetes.K8sSecretHelper; +import it.smartcommunitylabdhub.framework.k8s.model.ContextRef; +import it.smartcommunitylabdhub.framework.k8s.model.ContextSource; import it.smartcommunitylabdhub.framework.k8s.objects.CoreLabel; import it.smartcommunitylabdhub.framework.k8s.objects.CoreLog; import it.smartcommunitylabdhub.framework.k8s.objects.CoreMetric; import it.smartcommunitylabdhub.framework.k8s.objects.CoreNodeSelector; import it.smartcommunitylabdhub.framework.k8s.objects.CoreResource; import it.smartcommunitylabdhub.framework.k8s.runnables.K8sRunnable; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; +import java.util.Base64; import java.util.Collections; import java.util.HashMap; import java.util.LinkedList; @@ -49,6 +56,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.lang.Nullable; import org.springframework.util.Assert; +import org.springframework.util.StringUtils; @Slf4j public abstract class K8sBaseFramework @@ -560,4 +568,99 @@ protected void cleanRunSecret(T runnable) { log.warn("Failed to delete secret {}", secretName, e); } } + + public V1ConfigMap buildInitConfigMap(T runnable) throws K8sFrameworkException { + //check context refs and build config + if ( + (runnable.getContextSources() == null || runnable.getContextSources().isEmpty()) && + (runnable.getContextRefs() == null || runnable.getContextRefs().isEmpty()) + ) { + //nothing to do + return null; + } + + //build and create configMap + log.debug("build initConfigMap for {}", runnable.getId()); + if (log.isTraceEnabled()) { + log.trace("contextSources {}", runnable.getContextSources()); + log.trace("contextRefs {}", runnable.getContextRefs()); + } + + try { + // Generate Config map + Optional> contextRefsOpt = Optional.ofNullable(runnable.getContextRefs()); + Optional> contextSourcesOpt = Optional.ofNullable(runnable.getContextSources()); + + V1ConfigMap configMap = new V1ConfigMap() + .metadata(new V1ObjectMeta().name("init-config-map-" + runnable.getId()).labels(buildLabels(runnable))) + .data( + MapUtils.mergeMultipleMaps( + // Generate context-refs.txt if exist + contextRefsOpt + .map(contextRefsList -> + Map.of( + "context-refs.txt", + contextRefsList + .stream() + .map(v -> + v.getProtocol() + "," + v.getDestination() + "," + v.getSource() + "\n" + ) + .collect(Collectors.joining("")) + ) + ) + .orElseGet(Map::of), + // Generate context-sources.txt if exist + contextSourcesOpt + .map(contextSources -> + contextSources + .stream() + .filter(e -> StringUtils.hasText(e.getBase64())) + .collect( + Collectors.toMap( + c -> + Base64 + .getUrlEncoder() + .withoutPadding() + .encodeToString(c.getName().getBytes()), + c -> + new String( + Base64.getDecoder().decode(c.getBase64()), + StandardCharsets.UTF_8 + ) + ) + ) + ) + .orElseGet(Map::of), + contextSourcesOpt + .map(contextSources -> + Map.of( + "context-sources-map.txt", + contextSources + .stream() + .filter(e -> StringUtils.hasText(e.getBase64())) + .map(c -> + Base64 + .getUrlEncoder() + .withoutPadding() + .encodeToString(c.getName().getBytes()) + + "," + + c.getName() + + "\n" + ) + .collect(Collectors.joining("")) + ) + ) + .orElseGet(Map::of) + ) + ); + + if (log.isTraceEnabled()) { + log.trace("configMap for {}: {}", runnable.getId(), configMap); + } + + return configMap; + } catch (NullPointerException e) { + throw new K8sFrameworkException(e.getMessage()); + } + } } diff --git a/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sCronJobFramework.java b/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sCronJobFramework.java index d0c83aa37..d259edbf0 100644 --- a/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sCronJobFramework.java +++ b/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sCronJobFramework.java @@ -4,6 +4,7 @@ import io.kubernetes.client.openapi.ApiClient; import io.kubernetes.client.openapi.ApiException; import io.kubernetes.client.openapi.apis.BatchV1Api; +import io.kubernetes.client.openapi.models.V1ConfigMap; import io.kubernetes.client.openapi.models.V1CronJob; import io.kubernetes.client.openapi.models.V1CronJobSpec; import io.kubernetes.client.openapi.models.V1Job; @@ -59,6 +60,16 @@ public K8sCronJobRunnable run(K8sCronJobRunnable runnable) throws K8sFrameworkEx storeRunSecret(secret); } + try { + V1ConfigMap initConfigMap = buildInitConfigMap(runnable); + if (initConfigMap != null) { + log.info("create initConfigMap for {}", String.valueOf(initConfigMap.getMetadata().getName())); + coreV1Api.createNamespacedConfigMap(namespace, initConfigMap, null, null, null, null); + } + } catch (ApiException | NullPointerException e) { + throw new K8sFrameworkException(e.getMessage()); + } + log.info("create job for {}", String.valueOf(job.getMetadata().getName())); job = create(job); diff --git a/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sDeploymentFramework.java b/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sDeploymentFramework.java index 72a946532..2008428a8 100644 --- a/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sDeploymentFramework.java +++ b/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sDeploymentFramework.java @@ -20,16 +20,11 @@ import io.kubernetes.client.openapi.models.V1VolumeMount; import it.smartcommunitylabdhub.commons.annotations.infrastructure.FrameworkComponent; import it.smartcommunitylabdhub.commons.models.enums.State; -import it.smartcommunitylabdhub.commons.utils.MapUtils; import it.smartcommunitylabdhub.framework.k8s.exceptions.K8sFrameworkException; -import it.smartcommunitylabdhub.framework.k8s.model.ContextRef; -import it.smartcommunitylabdhub.framework.k8s.model.ContextSource; import it.smartcommunitylabdhub.framework.k8s.objects.CoreVolume; import it.smartcommunitylabdhub.framework.k8s.runnables.K8sDeploymentRunnable; import jakarta.validation.constraints.NotNull; import java.io.Serializable; -import java.nio.charset.StandardCharsets; -import java.util.Base64; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -75,81 +70,14 @@ public K8sDeploymentRunnable run(K8sDeploymentRunnable runnable) throws K8sFrame storeRunSecret(secret); } - //check context refs and build config - if (runnable.getContextRefs() != null || runnable.getContextSources() != null) { - //build and create configMap - //TODO move to shared method - try { - // Generate Config map - Optional> contextRefsOpt = Optional.ofNullable(runnable.getContextRefs()); - Optional> contextSourcesOpt = Optional.ofNullable(runnable.getContextSources()); - V1ConfigMap configMap = new V1ConfigMap() - .metadata( - new V1ObjectMeta().name("init-config-map-" + runnable.getId()).labels(buildLabels(runnable)) - ) - .data( - MapUtils.mergeMultipleMaps( - // Generate context-refs.txt if exist - contextRefsOpt - .map(contextRefsList -> - Map.of( - "context-refs.txt", - contextRefsList - .stream() - .map(v -> - v.getProtocol() + "," + v.getDestination() + "," + v.getSource() + "\n" - ) - .collect(Collectors.joining("")) - ) - ) - .orElseGet(Map::of), - // Generate context-sources.txt if exist - contextSourcesOpt - .map(contextSources -> - contextSources - .stream() - .collect( - Collectors.toMap( - c -> - Base64 - .getUrlEncoder() - .withoutPadding() - .encodeToString(c.getName().getBytes()), - c -> - new String( - Base64.getDecoder().decode(c.getBase64()), - StandardCharsets.UTF_8 - ) - ) - ) - ) - .orElseGet(Map::of), - contextSourcesOpt - .map(contextSources -> - Map.of( - "context-sources-map.txt", - contextSources - .stream() - .map(c -> - Base64 - .getUrlEncoder() - .withoutPadding() - .encodeToString(c.getName().getBytes()) + - "," + - c.getName() + - "\n" - ) - .collect(Collectors.joining("")) - ) - ) - .orElseGet(Map::of) - ) - ); - - coreV1Api.createNamespacedConfigMap(namespace, configMap, null, null, null, null); - } catch (ApiException | NullPointerException e) { - throw new K8sFrameworkException(e.getMessage()); + try { + V1ConfigMap initConfigMap = buildInitConfigMap(runnable); + if (initConfigMap != null) { + log.info("create initConfigMap for {}", String.valueOf(initConfigMap.getMetadata().getName())); + coreV1Api.createNamespacedConfigMap(namespace, initConfigMap, null, null, null, null); } + } catch (ApiException | NullPointerException e) { + throw new K8sFrameworkException(e.getMessage()); } log.info("create deployment for {}", String.valueOf(deployment.getMetadata().getName())); diff --git a/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sJobFramework.java b/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sJobFramework.java index 9129147af..ad5aa7f52 100644 --- a/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sJobFramework.java +++ b/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sJobFramework.java @@ -19,16 +19,11 @@ import io.kubernetes.client.openapi.models.V1VolumeMount; import it.smartcommunitylabdhub.commons.annotations.infrastructure.FrameworkComponent; import it.smartcommunitylabdhub.commons.models.enums.State; -import it.smartcommunitylabdhub.commons.utils.MapUtils; import it.smartcommunitylabdhub.framework.k8s.exceptions.K8sFrameworkException; -import it.smartcommunitylabdhub.framework.k8s.model.ContextRef; -import it.smartcommunitylabdhub.framework.k8s.model.ContextSource; import it.smartcommunitylabdhub.framework.k8s.objects.CoreVolume; import it.smartcommunitylabdhub.framework.k8s.runnables.K8sJobRunnable; import jakarta.validation.constraints.NotNull; import java.io.Serializable; -import java.nio.charset.StandardCharsets; -import java.util.Base64; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -88,81 +83,14 @@ public K8sJobRunnable run(K8sJobRunnable runnable) throws K8sFrameworkException storeRunSecret(secret); } - //check context refs and build config - if (runnable.getContextRefs() != null || runnable.getContextSources() != null) { - //build and create configMap - //TODO move to shared method - try { - // Generate Config map - Optional> contextRefsOpt = Optional.ofNullable(runnable.getContextRefs()); - Optional> contextSourcesOpt = Optional.ofNullable(runnable.getContextSources()); - V1ConfigMap configMap = new V1ConfigMap() - .metadata( - new V1ObjectMeta().name("init-config-map-" + runnable.getId()).labels(buildLabels(runnable)) - ) - .data( - MapUtils.mergeMultipleMaps( - // Generate context-refs.txt if exist - contextRefsOpt - .map(contextRefsList -> - Map.of( - "context-refs.txt", - contextRefsList - .stream() - .map(v -> - v.getProtocol() + "," + v.getDestination() + "," + v.getSource() + "\n" - ) - .collect(Collectors.joining("")) - ) - ) - .orElseGet(Map::of), - // Generate context-sources.txt if exist - contextSourcesOpt - .map(contextSources -> - contextSources - .stream() - .collect( - Collectors.toMap( - c -> - Base64 - .getUrlEncoder() - .withoutPadding() - .encodeToString(c.getName().getBytes()), - c -> - new String( - Base64.getDecoder().decode(c.getBase64()), - StandardCharsets.UTF_8 - ) - ) - ) - ) - .orElseGet(Map::of), - contextSourcesOpt - .map(contextSources -> - Map.of( - "context-sources-map.txt", - contextSources - .stream() - .map(c -> - Base64 - .getUrlEncoder() - .withoutPadding() - .encodeToString(c.getName().getBytes()) + - "," + - c.getName() + - "\n" - ) - .collect(Collectors.joining("")) - ) - ) - .orElseGet(Map::of) - ) - ); - - coreV1Api.createNamespacedConfigMap(namespace, configMap, null, null, null, null); - } catch (ApiException | NullPointerException e) { - throw new K8sFrameworkException(e.getMessage()); + try { + V1ConfigMap initConfigMap = buildInitConfigMap(runnable); + if (initConfigMap != null) { + log.info("create initConfigMap for {}", String.valueOf(initConfigMap.getMetadata().getName())); + coreV1Api.createNamespacedConfigMap(namespace, initConfigMap, null, null, null, null); } + } catch (ApiException | NullPointerException e) { + throw new K8sFrameworkException(e.getMessage()); } log.info("create job for {}", String.valueOf(job.getMetadata().getName())); diff --git a/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sServeFramework.java b/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sServeFramework.java index 273c2af1f..ef8fae41f 100644 --- a/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sServeFramework.java +++ b/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sServeFramework.java @@ -12,16 +12,11 @@ import io.kubernetes.client.openapi.models.V1ServiceSpec; import it.smartcommunitylabdhub.commons.annotations.infrastructure.FrameworkComponent; import it.smartcommunitylabdhub.commons.models.enums.State; -import it.smartcommunitylabdhub.commons.utils.MapUtils; import it.smartcommunitylabdhub.framework.k8s.exceptions.K8sFrameworkException; -import it.smartcommunitylabdhub.framework.k8s.model.ContextRef; -import it.smartcommunitylabdhub.framework.k8s.model.ContextSource; import it.smartcommunitylabdhub.framework.k8s.runnables.K8sDeploymentRunnable; import it.smartcommunitylabdhub.framework.k8s.runnables.K8sServeRunnable; import jakarta.validation.constraints.NotNull; import java.io.Serializable; -import java.nio.charset.StandardCharsets; -import java.util.Base64; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -61,81 +56,14 @@ public K8sServeRunnable run(K8sServeRunnable runnable) throws K8sFrameworkExcept // Create a deployment from a Deployment+Service V1Deployment deployment = buildDeployment(runnable); - //check context refs and build config - if (runnable.getContextRefs() != null || runnable.getContextSources() != null) { - //build and create configMap - //TODO move to shared method - try { - // Generate Config map - Optional> contextRefsOpt = Optional.ofNullable(runnable.getContextRefs()); - Optional> contextSourcesOpt = Optional.ofNullable(runnable.getContextSources()); - V1ConfigMap configMap = new V1ConfigMap() - .metadata( - new V1ObjectMeta().name("init-config-map-" + runnable.getId()).labels(buildLabels(runnable)) - ) - .data( - MapUtils.mergeMultipleMaps( - // Generate context-refs.txt if exist - contextRefsOpt - .map(contextRefsList -> - Map.of( - "context-refs.txt", - contextRefsList - .stream() - .map(v -> - v.getProtocol() + "," + v.getDestination() + "," + v.getSource() + "\n" - ) - .collect(Collectors.joining("")) - ) - ) - .orElseGet(Map::of), - // Generate context-sources.txt if exist - contextSourcesOpt - .map(contextSources -> - contextSources - .stream() - .collect( - Collectors.toMap( - c -> - Base64 - .getUrlEncoder() - .withoutPadding() - .encodeToString(c.getName().getBytes()), - c -> - new String( - Base64.getDecoder().decode(c.getBase64()), - StandardCharsets.UTF_8 - ) - ) - ) - ) - .orElseGet(Map::of), - contextSourcesOpt - .map(contextSources -> - Map.of( - "context-sources-map.txt", - contextSources - .stream() - .map(c -> - Base64 - .getUrlEncoder() - .withoutPadding() - .encodeToString(c.getName().getBytes()) + - "," + - c.getName() + - "\n" - ) - .collect(Collectors.joining("")) - ) - ) - .orElseGet(Map::of) - ) - ); - - coreV1Api.createNamespacedConfigMap(namespace, configMap, null, null, null, null); - } catch (ApiException | NullPointerException e) { - throw new K8sFrameworkException(e.getMessage()); + try { + V1ConfigMap initConfigMap = buildInitConfigMap(runnable); + if (initConfigMap != null) { + log.info("create initConfigMap for {}", String.valueOf(initConfigMap.getMetadata().getName())); + coreV1Api.createNamespacedConfigMap(namespace, initConfigMap, null, null, null, null); } + } catch (ApiException | NullPointerException e) { + throw new K8sFrameworkException(e.getMessage()); } log.info("create deployment for {}", String.valueOf(deployment.getMetadata().getName())); diff --git a/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/runnables/K8sCronJobRunnable.java b/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/runnables/K8sCronJobRunnable.java index 7c3466275..0ad73450a 100644 --- a/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/runnables/K8sCronJobRunnable.java +++ b/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/runnables/K8sCronJobRunnable.java @@ -3,9 +3,6 @@ import com.fasterxml.jackson.annotation.JsonProperty; import it.smartcommunitylabdhub.commons.annotations.infrastructure.RunnableComponent; import it.smartcommunitylabdhub.framework.k8s.infrastructure.k8s.K8sCronJobFramework; -import it.smartcommunitylabdhub.framework.k8s.model.ContextRef; -import it.smartcommunitylabdhub.framework.k8s.model.ContextSource; -import java.util.List; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; @@ -25,12 +22,6 @@ public class K8sCronJobRunnable extends K8sRunnable { @JsonProperty("backoff_limit") private Integer backoffLimit; - @JsonProperty("context_refs") - private List contextRefs; - - @JsonProperty("context_sources") - private List contextSources; - @Override public String getFramework() { return K8sCronJobFramework.FRAMEWORK; diff --git a/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/runnables/K8sDeploymentRunnable.java b/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/runnables/K8sDeploymentRunnable.java index 65816ceb9..c62ba2232 100644 --- a/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/runnables/K8sDeploymentRunnable.java +++ b/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/runnables/K8sDeploymentRunnable.java @@ -1,11 +1,7 @@ package it.smartcommunitylabdhub.framework.k8s.runnables; -import com.fasterxml.jackson.annotation.JsonProperty; import it.smartcommunitylabdhub.commons.annotations.infrastructure.RunnableComponent; import it.smartcommunitylabdhub.framework.k8s.infrastructure.k8s.K8sDeploymentFramework; -import it.smartcommunitylabdhub.framework.k8s.model.ContextRef; -import it.smartcommunitylabdhub.framework.k8s.model.ContextSource; -import java.util.List; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; @@ -20,12 +16,6 @@ @AllArgsConstructor public class K8sDeploymentRunnable extends K8sRunnable { - @JsonProperty("context_refs") - private List contextRefs; - - @JsonProperty("context_sources") - private List contextSources; - private Integer replicas; @Override diff --git a/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/runnables/K8sJobRunnable.java b/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/runnables/K8sJobRunnable.java index 78c896893..e2264eeee 100644 --- a/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/runnables/K8sJobRunnable.java +++ b/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/runnables/K8sJobRunnable.java @@ -3,9 +3,6 @@ import com.fasterxml.jackson.annotation.JsonProperty; import it.smartcommunitylabdhub.commons.annotations.infrastructure.RunnableComponent; import it.smartcommunitylabdhub.framework.k8s.infrastructure.k8s.K8sJobFramework; -import it.smartcommunitylabdhub.framework.k8s.model.ContextRef; -import it.smartcommunitylabdhub.framework.k8s.model.ContextSource; -import java.util.List; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; @@ -20,12 +17,6 @@ @AllArgsConstructor public class K8sJobRunnable extends K8sRunnable { - @JsonProperty("context_refs") - private List contextRefs; - - @JsonProperty("context_sources") - private List contextSources; - @JsonProperty("backoff_limit") private Integer backoffLimit; diff --git a/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/runnables/K8sRunnable.java b/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/runnables/K8sRunnable.java index 17a274efd..b0c8a461d 100644 --- a/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/runnables/K8sRunnable.java +++ b/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/runnables/K8sRunnable.java @@ -4,6 +4,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import it.smartcommunitylabdhub.commons.infrastructure.RunRunnable; import it.smartcommunitylabdhub.commons.infrastructure.SecuredRunnable; +import it.smartcommunitylabdhub.framework.k8s.model.ContextRef; +import it.smartcommunitylabdhub.framework.k8s.model.ContextSource; import it.smartcommunitylabdhub.framework.k8s.objects.CoreAffinity; import it.smartcommunitylabdhub.framework.k8s.objects.CoreEnv; import it.smartcommunitylabdhub.framework.k8s.objects.CoreLabel; @@ -80,6 +82,12 @@ public class K8sRunnable implements RunRunnable, SecuredRunnable, CredentialsCon private AbstractAuthenticationToken credentials; + @JsonProperty("context_refs") + private List contextRefs; + + @JsonProperty("context_sources") + private List contextSources; + @Override public String getFramework() { return "k8s"; diff --git a/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/runnables/K8sServeRunnable.java b/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/runnables/K8sServeRunnable.java index 36a61a8e7..b486b43e5 100644 --- a/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/runnables/K8sServeRunnable.java +++ b/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/runnables/K8sServeRunnable.java @@ -1,10 +1,7 @@ package it.smartcommunitylabdhub.framework.k8s.runnables; -import com.fasterxml.jackson.annotation.JsonProperty; import it.smartcommunitylabdhub.commons.annotations.infrastructure.RunnableComponent; import it.smartcommunitylabdhub.framework.k8s.infrastructure.k8s.K8sServeFramework; -import it.smartcommunitylabdhub.framework.k8s.model.ContextRef; -import it.smartcommunitylabdhub.framework.k8s.model.ContextSource; import it.smartcommunitylabdhub.framework.k8s.objects.CorePort; import it.smartcommunitylabdhub.framework.k8s.objects.CoreServiceType; import java.util.List; @@ -22,12 +19,6 @@ @NoArgsConstructor public class K8sServeRunnable extends K8sRunnable { - @JsonProperty("context_refs") - private List contextRefs; - - @JsonProperty("context_sources") - private List contextSources; - private List servicePorts; private CoreServiceType serviceType;