From fd6c4afd3c6fe4414426ddde4c677b20e1de1760 Mon Sep 17 00:00:00 2001 From: Srinath Chandrashekhar Date: Tue, 4 Jun 2019 15:57:14 +0530 Subject: [PATCH] Add an option to ignore job status in helm task handler --- api/pom.xml | 2 +- app/pom.xml | 2 +- common/pom.xml | 2 +- executor/pom.xml | 2 +- extensions/embedded-hsql-store/pom.xml | 4 ++-- extensions/helm-handler/pom.xml | 2 +- .../executor/handlers/HelmTaskHandler.java | 23 ++++++++++++------- extensions/jdbc-store/pom.xml | 2 +- extensions/kafka-message-handler/pom.xml | 2 +- extensions/kafka-queue/pom.xml | 2 +- extensions/mongo-store/pom.xml | 2 +- extensions/pom.xml | 2 +- extensions/shell-handler/pom.xml | 2 +- extensions/spark-handler/pom.xml | 2 +- pom.xml | 2 +- scheduler/pom.xml | 2 +- 16 files changed, 31 insertions(+), 24 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index 752357a..bac0a73 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -20,7 +20,7 @@ kronos com.cognitree - 2.2.3 + 2.2.4-RC1 4.0.0 diff --git a/app/pom.xml b/app/pom.xml index 5774c72..3e993a1 100644 --- a/app/pom.xml +++ b/app/pom.xml @@ -22,7 +22,7 @@ kronos com.cognitree - 2.2.3 + 2.2.4-RC1 4.0.0 diff --git a/common/pom.xml b/common/pom.xml index 21e0050..e1cfe1d 100755 --- a/common/pom.xml +++ b/common/pom.xml @@ -24,7 +24,7 @@ kronos com.cognitree - 2.2.3 + 2.2.4-RC1 com.cognitree.kronos diff --git a/executor/pom.xml b/executor/pom.xml index 78fd886..14f6c30 100755 --- a/executor/pom.xml +++ b/executor/pom.xml @@ -22,7 +22,7 @@ kronos com.cognitree - 2.2.3 + 2.2.4-RC1 4.0.0 diff --git a/extensions/embedded-hsql-store/pom.xml b/extensions/embedded-hsql-store/pom.xml index 76842c8..b048deb 100644 --- a/extensions/embedded-hsql-store/pom.xml +++ b/extensions/embedded-hsql-store/pom.xml @@ -22,12 +22,12 @@ extensions com.cognitree.kronos.extensions - 2.2.3 + 2.2.4-RC1 4.0.0 embedded-hsql-store - 2.2.3 + 2.2.4-RC1 2.4.1 diff --git a/extensions/helm-handler/pom.xml b/extensions/helm-handler/pom.xml index fd5b1fc..071ecfd 100644 --- a/extensions/helm-handler/pom.xml +++ b/extensions/helm-handler/pom.xml @@ -22,7 +22,7 @@ extensions com.cognitree.kronos.extensions - 2.2.3 + 2.2.4-RC1 4.0.0 diff --git a/extensions/helm-handler/src/main/java/com/cognitree/kronos/executor/handlers/HelmTaskHandler.java b/extensions/helm-handler/src/main/java/com/cognitree/kronos/executor/handlers/HelmTaskHandler.java index efc27e8..b4e183a 100755 --- a/extensions/helm-handler/src/main/java/com/cognitree/kronos/executor/handlers/HelmTaskHandler.java +++ b/extensions/helm-handler/src/main/java/com/cognitree/kronos/executor/handlers/HelmTaskHandler.java @@ -26,9 +26,7 @@ import hapi.chart.ChartOuterClass.Chart; import hapi.release.ReleaseOuterClass.Release; import hapi.release.StatusOuterClass.Status.Code; -import hapi.services.tiller.Tiller.GetReleaseStatusRequest; -import hapi.services.tiller.Tiller.GetReleaseStatusResponse; -import hapi.services.tiller.Tiller.InstallReleaseRequest; +import hapi.services.tiller.Tiller.*; import hapi.services.tiller.Tiller.InstallReleaseRequest.Builder; import io.fabric8.kubernetes.api.model.batch.Job; import io.fabric8.kubernetes.api.model.batch.JobList; @@ -81,11 +79,13 @@ public class HelmTaskHandler implements TaskHandler { private static final String PROP_VALUES_FILE = "valuesFile"; private static final String PROP_TIMEOUT = "timeout"; private static final String PROP_MAX_WAIT_TIMEOUT = "maxWaitTimeout"; + private static final String PROP_IGNORE_JOB_STATUS = "ignoreJobStatus"; private static final ChartType DEFAULT_CHART_TYPE = directory; private static final String DEFAULT_RELEASE_PREFIX = "release"; private static final long DEFAULT_WAIT_TIMEOUT = 600L; private static final long DEFAULT_HELM_TIMEOUT = 300L; + private static final boolean DEFAULT_IGNORE_JOB_STATUS = false; private static final int SLEEP_INTERVAL_IN_SECONDS = 5; private static final int MAX_RETRY_COUNT = 3; private static final int RETRY_SLEEP_INTERVAL = 5000; @@ -178,8 +178,9 @@ private TaskResult handle(Task task, String releaseName, int retryCount) { release = releaseManager.install(requestBuilder, chart).get().getRelease(); logger.info("Successfully installed release: {} in namespace: {}", releaseName, release.getNamespace()); } + boolean ignoreJobStatus = (boolean) taskProperties.getOrDefault(PROP_IGNORE_JOB_STATUS, DEFAULT_IGNORE_JOB_STATUS); waitForReleaseAndJobCompletion(releaseManager, kubernetesClient, releaseName, - release.getNamespace(), waitTimeout); + release.getNamespace(), waitTimeout, ignoreJobStatus); logger.info("Successfully completed release: {} in namespace {}", releaseName, release.getNamespace()); return new TaskResult(true, null, taskResult); @@ -203,7 +204,8 @@ private TaskResult handle(Task task, String releaseName, int retryCount) { } private void waitForReleaseAndJobCompletion(ReleaseManager releaseManager, KubernetesClient kubernetesClient, - String releaseName, String namespace, long waitTimeout) throws Exception { + String releaseName, String namespace, long waitTimeout, + boolean ignoreJobStatus) throws Exception { logger.info("Waiting for release {} in namespace {} to complete.", releaseName, namespace); boolean deployed = false; @@ -234,7 +236,12 @@ private void waitForReleaseAndJobCompletion(ReleaseManager releaseManager, Kuber " in namespace " + namespace + " current state is: " + statusCode); } } - waitForJobCompletion(kubernetesClient, releaseName, namespace, waitTimeout); + if (ignoreJobStatus) { + logger.info("Task is configured to not wait for the completion" + + " of release {} in namespace {}", releaseName, namespace); + } else { + waitForJobCompletion(kubernetesClient, releaseName, namespace, waitTimeout); + } } private Code getHelmReleaseStatus(ReleaseManager releaseManager, String releaseName) throws Exception { @@ -387,14 +394,14 @@ private Chart.Builder loadHelmChart(ChartType chartType, String chartPath) throw case zip: File zipFile = new File(chartPath); ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(zipFile)); - try (ZipInputStreamChartLoader zipInputStreamChartLoader = new ZipInputStreamChartLoader();) { + try (ZipInputStreamChartLoader zipInputStreamChartLoader = new ZipInputStreamChartLoader()) { helmChart = zipInputStreamChartLoader.load(zipInputStream); } break; case tape: File tarFile = new File(chartPath); TarInputStream tarInputStream = new TarInputStream(new FileInputStream(tarFile)); - try (TapeArchiveChartLoader tapeArchiveChartLoader = new TapeArchiveChartLoader();) { + try (TapeArchiveChartLoader tapeArchiveChartLoader = new TapeArchiveChartLoader()) { helmChart = tapeArchiveChartLoader.load(tarInputStream); } break; diff --git a/extensions/jdbc-store/pom.xml b/extensions/jdbc-store/pom.xml index 9982c62..6deb3ac 100755 --- a/extensions/jdbc-store/pom.xml +++ b/extensions/jdbc-store/pom.xml @@ -22,7 +22,7 @@ extensions com.cognitree.kronos.extensions - 2.2.3 + 2.2.4-RC1 4.0.0 diff --git a/extensions/kafka-message-handler/pom.xml b/extensions/kafka-message-handler/pom.xml index e5cddbd..1cdba47 100644 --- a/extensions/kafka-message-handler/pom.xml +++ b/extensions/kafka-message-handler/pom.xml @@ -5,7 +5,7 @@ extensions com.cognitree.kronos.extensions - 2.2.3 + 2.2.4-RC1 4.0.0 diff --git a/extensions/kafka-queue/pom.xml b/extensions/kafka-queue/pom.xml index db319b0..59c514e 100755 --- a/extensions/kafka-queue/pom.xml +++ b/extensions/kafka-queue/pom.xml @@ -22,7 +22,7 @@ extensions com.cognitree.kronos.extensions - 2.2.3 + 2.2.4-RC1 4.0.0 diff --git a/extensions/mongo-store/pom.xml b/extensions/mongo-store/pom.xml index ed7f4c0..69f8e8f 100644 --- a/extensions/mongo-store/pom.xml +++ b/extensions/mongo-store/pom.xml @@ -6,7 +6,7 @@ extensions com.cognitree.kronos.extensions - 2.2.3 + 2.2.4-RC1 4.0.0 diff --git a/extensions/pom.xml b/extensions/pom.xml index 80790b0..e06635b 100755 --- a/extensions/pom.xml +++ b/extensions/pom.xml @@ -24,7 +24,7 @@ com.cognitree kronos - 2.2.3 + 2.2.4-RC1 com.cognitree.kronos.extensions diff --git a/extensions/shell-handler/pom.xml b/extensions/shell-handler/pom.xml index 044fec3..855a7ef 100755 --- a/extensions/shell-handler/pom.xml +++ b/extensions/shell-handler/pom.xml @@ -22,7 +22,7 @@ extensions com.cognitree.kronos.extensions - 2.2.3 + 2.2.4-RC1 4.0.0 diff --git a/extensions/spark-handler/pom.xml b/extensions/spark-handler/pom.xml index 65eddb4..64d837e 100644 --- a/extensions/spark-handler/pom.xml +++ b/extensions/spark-handler/pom.xml @@ -22,7 +22,7 @@ extensions com.cognitree.kronos.extensions - 2.2.3 + 2.2.4-RC1 4.0.0 diff --git a/pom.xml b/pom.xml index 9b53dc0..b7ef11f 100755 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ kronos kronos pom - 2.2.3 + 2.2.4-RC1 1.8 diff --git a/scheduler/pom.xml b/scheduler/pom.xml index f9bab00..fe3d094 100755 --- a/scheduler/pom.xml +++ b/scheduler/pom.xml @@ -22,7 +22,7 @@ kronos com.cognitree - 2.2.3 + 2.2.4-RC1 4.0.0