diff options
-rw-r--r-- | Changelog.md | 15 | ||||
-rw-r--r-- | Dockerfile | 2 | ||||
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | README.md | 5 | ||||
-rw-r--r-- | pom.xml | 2 | ||||
-rw-r--r-- | src/main/java/org/onap/sdc/helmvalidator/helm/versions/ChartBasedVersionProvider.java | 18 | ||||
-rw-r--r-- | src/test/java/org/onap/sdc/helmvalidator/helm/versions/ApiVersionsReaderTest.java | 12 | ||||
-rw-r--r-- | src/test/java/org/onap/sdc/helmvalidator/helm/versions/ChartBasedVersionProviderTest.java | 16 | ||||
-rw-r--r-- | version.properties | 2 |
9 files changed, 40 insertions, 34 deletions
diff --git a/Changelog.md b/Changelog.md index 463a1e2..3c167f8 100644 --- a/Changelog.md +++ b/Changelog.md @@ -4,10 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). -## [0.0.1] - 23/03/2021 - -- Init Helm client validator project, which is dedicated to be used during Helm packages validation in time of VSP creation +## [1.1.0] - 12/04/2021 +- Remove mapping to helm v2 when version desired is not provided +- Remove Helm v2 clients from container +- Supported Helm Versions: + - Helm v3: 3.5.2, 3.4.1, 3.3.4 ## [1.0.0] - 24/03/2021 @@ -15,3 +17,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Supported Helm Versions: - Helm v3: 3.5.2, 3.4.1, 3.3.4, - Helm v2: 2.17.0, 2.14.3 + +## [0.0.1] - 23/03/2021 + +- Init Helm client validator project, which is dedicated to be used during Helm packages validation in time of VSP creation + + + @@ -7,7 +7,7 @@ RUN adduser -G onap -D validator RUN apk add --no-cache bash vim curl wget -ENV HELM_SUPPORTED_VERSIONS=3.5.2,3.4.1,3.3.4,2.17.0,2.14.3 +ENV HELM_SUPPORTED_VERSIONS=3.5.2,3.4.1,3.3.4 #Installing Helm COPY scripts/collect_helm_versions_from_web.sh ./opt/helmvalidator/tmp/collect_helm_versions_from_web.sh @@ -5,7 +5,7 @@ build-docker: mvn clean install -Pdocker build-docker-local: - export HELM_SUPPORTED_VERSIONS=3.5.2,3.4.1,3.3.4,2.17.0 && \ + export HELM_SUPPORTED_VERSIONS=3.5.2,3.4.1,3.3.4 && \ cd scripts && \ ./collect_helm_versions_from_web.sh local && \ cd ../ && \ @@ -49,12 +49,11 @@ This should be a POST with `multipart/form-data` encoding with the following fie It is possible to provide helm version in three ways: 1. Select exact version from supported versions e.g. "3.4.1" -2. Select major helm version e.g. "v2" for Helm 2 or "v3" for Helm 3. In this case app will use the latest supported version. +2. Select major helm version e.g. "v3" for Helm 3. In this case app will use the latest supported version. 3. In case when field version is not present in request then app gets helm version from "apiVersion" field located in the main chart (Chart.yaml). Mapping rules: -apiVersion: v1 -> the latest available helm 2 - +apiVersion: v1 -> the latest available helm 3 apiVersion: v2 -> the latest available helm 3 #### Response @@ -10,7 +10,7 @@ </parent> <groupId>org.onap.sdc</groupId> <artifactId>sdc-helm-validator</artifactId> - <version>1.0.0-SNAPSHOT</version> + <version>1.1.0-SNAPSHOT</version> <name>helmvalidator</name> <description>Spring-Boot application for validating helm charts</description> diff --git a/src/main/java/org/onap/sdc/helmvalidator/helm/versions/ChartBasedVersionProvider.java b/src/main/java/org/onap/sdc/helmvalidator/helm/versions/ChartBasedVersionProvider.java index b892a33..c3e423f 100644 --- a/src/main/java/org/onap/sdc/helmvalidator/helm/versions/ChartBasedVersionProvider.java +++ b/src/main/java/org/onap/sdc/helmvalidator/helm/versions/ChartBasedVersionProvider.java @@ -20,6 +20,7 @@ package org.onap.sdc.helmvalidator.helm.versions; +import java.util.List; import org.onap.sdc.helmvalidator.helm.versions.exception.NotSupportedApiVersionException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -27,6 +28,9 @@ import org.springframework.stereotype.Service; @Service public class ChartBasedVersionProvider { + private static final List<String> SUPPORTED_API_VERSIONS = List.of("v1", "v2"); + private static final String HELM_3 = "3"; + private final SupportedVersionsProvider supportedVersionsProvider; private final ApiVersionsReader apiVersionsReader; @@ -40,18 +44,14 @@ public class ChartBasedVersionProvider { public String getVersion(String chartPath) { String apiVersion = apiVersionsReader.readVersion(chartPath); - return mapToChartVersion(apiVersion); + return mapToHelmVersion(apiVersion); } - private String mapToChartVersion(String apiVersion) { - switch (apiVersion) { - case "v1": - return supportedVersionsProvider.getLatestVersion("2"); - case "v2": - return supportedVersionsProvider.getLatestVersion("3"); - default: - throw new NotSupportedApiVersionException("Cannot obtain Helm version from API version: " + apiVersion); + private String mapToHelmVersion(String apiVersion) { + if (!SUPPORTED_API_VERSIONS.contains(apiVersion)) { + throw new NotSupportedApiVersionException("Cannot obtain Helm version from API version: " + apiVersion); } + return supportedVersionsProvider.getLatestVersion(HELM_3); } } diff --git a/src/test/java/org/onap/sdc/helmvalidator/helm/versions/ApiVersionsReaderTest.java b/src/test/java/org/onap/sdc/helmvalidator/helm/versions/ApiVersionsReaderTest.java index 79ea56a..2dbb6c1 100644 --- a/src/test/java/org/onap/sdc/helmvalidator/helm/versions/ApiVersionsReaderTest.java +++ b/src/test/java/org/onap/sdc/helmvalidator/helm/versions/ApiVersionsReaderTest.java @@ -36,13 +36,12 @@ import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; import org.onap.sdc.helmvalidator.helm.versions.exception.ApiVersionNotFoundException; import org.onap.sdc.helmvalidator.helm.versions.exception.ReadFileException; class ApiVersionsReaderTest { + private static final String API_VERSION_V2= "v2"; private static final String TEST_RESOURCES_TMP = "src/test/resources/tmp"; private static final Path TEST_CHART_PATH = Path.of(TEST_RESOURCES_TMP).resolve(Path.of("Chart.yaml")); @@ -55,14 +54,13 @@ class ApiVersionsReaderTest { apiVersionsReader = new ApiVersionsReader(); } - @ParameterizedTest - @ValueSource(strings = {"v1", "v2"}) - void shouldCorrectlyReadApiVersionFromTar(String apiVersion) throws IOException { - prepareTestTar(apiVersion); + @Test + void shouldCorrectlyReadApiVersionFromTar() throws IOException { + prepareTestTar(API_VERSION_V2); String helmVersion = apiVersionsReader.readVersion(TEST_TAR_PATH.toString()); - assertThat(helmVersion).isEqualTo(apiVersion); + assertThat(helmVersion).isEqualTo(API_VERSION_V2); } @Test diff --git a/src/test/java/org/onap/sdc/helmvalidator/helm/versions/ChartBasedVersionProviderTest.java b/src/test/java/org/onap/sdc/helmvalidator/helm/versions/ChartBasedVersionProviderTest.java index 64daf2d..7819aa5 100644 --- a/src/test/java/org/onap/sdc/helmvalidator/helm/versions/ChartBasedVersionProviderTest.java +++ b/src/test/java/org/onap/sdc/helmvalidator/helm/versions/ChartBasedVersionProviderTest.java @@ -27,8 +27,6 @@ import static org.mockito.Mockito.when; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.CsvSource; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; @@ -37,6 +35,9 @@ import org.onap.sdc.helmvalidator.helm.versions.exception.NotSupportedApiVersion @ExtendWith(MockitoExtension.class) class ChartBasedVersionProviderTest { + private static final String EXPECTED_HELM_VERSION = "3.4.3"; + private static final String API_VERSION = "v2"; + private final String testChartPath = "test/path"; @Mock private SupportedVersionsProvider versionsProvider; @@ -49,15 +50,14 @@ class ChartBasedVersionProviderTest { chartBasedVersionProvider = new ChartBasedVersionProvider(versionsProvider, apiVersionsReader); } - @ParameterizedTest - @CsvSource({"v1,2.18", "v2,3.11"}) - void shouldGetLatestHelmVersionBasedOnApiVersion(String apiVersion, String expectedHelmVersion) { - when(apiVersionsReader.readVersion(testChartPath)).thenReturn(apiVersion); - when(versionsProvider.getLatestVersion(Mockito.anyString())).thenReturn(expectedHelmVersion); + @Test + void shouldGetLatestHelmVersionBasedOnApiVersion() { + when(apiVersionsReader.readVersion(testChartPath)).thenReturn(API_VERSION); + when(versionsProvider.getLatestVersion(Mockito.anyString())).thenReturn(EXPECTED_HELM_VERSION); String helmVersion = chartBasedVersionProvider.getVersion(testChartPath); - assertThat(helmVersion).isEqualTo(expectedHelmVersion); + assertThat(helmVersion).isEqualTo(EXPECTED_HELM_VERSION); } @Test diff --git a/version.properties b/version.properties index 2ddebb3..7b8b963 100644 --- a/version.properties +++ b/version.properties @@ -1,5 +1,5 @@ major=1 -minor=0 +minor=1 patch=0 base_version=${major}.${minor}.${patch} release_version=${base_version} |