Fix K8s participant Error when helm repo is not configured 15/126915/2
authorLathish <lathishbabu.ganesan@est.tech>
Tue, 1 Feb 2022 09:58:14 +0000 (15:28 +0530)
committerLathish <lathishbabu.ganesan@est.tech>
Tue, 1 Feb 2022 12:03:07 +0000 (17:33 +0530)
Issue-ID: POLICY-3874
Change-Id: Ib28e427b6f498c89b8ab5b1f5bf6c88e6c9fc919
Signed-off-by: Lathish <lathishbabu.ganesan@est.tech>
participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/helm/HelmClient.java
participant/participant-impl/participant-impl-kubernetes/src/main/resources/config/application.yaml

index 31fa62f..6133c7e 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ========================LICENSE_START=================================
- * Copyright (C) 2021 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2021-2022 Nordix Foundation. All rights reserved.
  * ======================================================================
  * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
  * ======================================================================
@@ -93,18 +93,19 @@ public class HelmClient {
      * @throws IOException in case of IO errors
      */
     public String findChartRepository(ChartInfo chart) throws ServiceException, IOException {
-        updateHelmRepo();
-        String repository = verifyConfiguredRepo(chart);
-        if (repository != null) {
-            logger.info("Helm chart located in the repository {} ", repository);
-            return repository;
+        if (updateHelmRepo()) {
+            String repository = verifyConfiguredRepo(chart);
+            if (repository != null) {
+                logger.info("Helm chart located in the repository {} ", repository);
+                return repository;
+            }
         }
         var localHelmChartDir = chartStore.getAppPath(chart.getChartId()).toString();
         logger.info("Chart not found in helm repositories, verifying local repo {} ", localHelmChartDir);
         if (verifyLocalHelmRepo(new File(localHelmChartDir + PATH_DELIMITER + chart.getChartId().getName()))) {
-            repository = localHelmChartDir;
+            return localHelmChartDir;
         }
-        return repository;
+        return null;
     }
 
     /**
@@ -254,10 +255,18 @@ public class HelmClient {
     }
 
 
-    private void updateHelmRepo() throws ServiceException {
-        logger.info("Updating local helm repositories before verifying the chart");
-        executeCommand(new ProcessBuilder().command("helm", "repo", "update"));
-        logger.debug("Helm repositories updated successfully");
+    private boolean updateHelmRepo() {
+        try {
+            logger.info("Updating local helm repositories before verifying the chart");
+            executeCommand(new ProcessBuilder().command("helm", "repo", "update"));
+            logger.debug("Helm repositories updated successfully");
+        } catch (ServiceException e) {
+            logger.error("Failed to update the helm repo: ", e);
+            return false;
+        }
+        return true;
+
+
     }
 
     private boolean verifyLocalHelmRepo(File localFile) {
index f77153a..8b9d7e4 100644 (file)
@@ -13,10 +13,10 @@ participant:
     reportingTimeIntervalMs: 120000
     description: Participant Description
     participantId:
-      name: org.onap.k8s.controlloop.K8SControlLoopParticipant
-      version: 2.3.4
+      name: K8sParticipant0
+      version: 1.0.0
     participantType:
-      name: org.onap.k8s.controlloop.K8SControlLoopParticipant
+      name: org.onap.k8s.controlloop.K8sControlLoopParticipant
       version: 2.3.4
     clampControlLoopTopics:
       topicSources: