From 93ae1b49876b734e725cdb2c01e8eae9237ed653 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 18 Oct 2023 06:02:52 +0000 Subject: [PATCH] feat(helm/bake): Add additional input fields where we can fill in details of the APIs versions (#1020) (#1031) * security(feature): Change codeql to scan daily instead of weekly * feat(helm/bake): Add additional input fields where we can fill in details of the APIs versions - These input fields will not be pre-populated with versions of the target cluster available in the environment. - They will become part of the bake result. - Added API_VERSIONS_ENABLED env variable flag * feat(helm/bake): Add additional input fields where we can fill in details of the APIs versions - These input fields will not be pre-populated with versions of the target cluster available in the environment. - They will become part of the bake result. - Added API_VERSIONS_ENABLED env variable flag * feat(helm/bake): Add additional input fields where we can fill in details of the APIs versions - These input fields will not be pre-populated with versions of the target cluster available in the environment. - They will become part of the bake result. - Added API_VERSIONS_ENABLED env variable flag --------- Co-authored-by: Jason McIntosh (cherry picked from commit 4a12958abb4898428e6840e8753b9ca9a3b1a674) Co-authored-by: Krystian <24556350+ciurescuraul@users.noreply.github.com> --- .../helm/HelmBakeManifestRequest.java | 4 ++ .../manifests/helm/HelmTemplateUtils.java | 13 +++++ .../manifests/helm/HelmTemplateUtilsTest.java | 50 +++++++++++++++++++ 3 files changed, 67 insertions(+) diff --git a/rosco-manifests/src/main/java/com/netflix/spinnaker/rosco/manifests/helm/HelmBakeManifestRequest.java b/rosco-manifests/src/main/java/com/netflix/spinnaker/rosco/manifests/helm/HelmBakeManifestRequest.java index 9ee6ab7dd..0e874f901 100644 --- a/rosco-manifests/src/main/java/com/netflix/spinnaker/rosco/manifests/helm/HelmBakeManifestRequest.java +++ b/rosco-manifests/src/main/java/com/netflix/spinnaker/rosco/manifests/helm/HelmBakeManifestRequest.java @@ -3,12 +3,16 @@ import com.netflix.spinnaker.kork.artifacts.model.Artifact; import com.netflix.spinnaker.rosco.manifests.BakeManifestRequest; import java.util.List; +import javax.annotation.Nullable; import lombok.Data; import lombok.EqualsAndHashCode; @Data @EqualsAndHashCode(callSuper = true) public class HelmBakeManifestRequest extends BakeManifestRequest { + @Nullable String apiVersions; + @Nullable String kubeVersion; + String namespace; /** diff --git a/rosco-manifests/src/main/java/com/netflix/spinnaker/rosco/manifests/helm/HelmTemplateUtils.java b/rosco-manifests/src/main/java/com/netflix/spinnaker/rosco/manifests/helm/HelmTemplateUtils.java index f0d74e943..c15e64dd4 100644 --- a/rosco-manifests/src/main/java/com/netflix/spinnaker/rosco/manifests/helm/HelmTemplateUtils.java +++ b/rosco-manifests/src/main/java/com/netflix/spinnaker/rosco/manifests/helm/HelmTemplateUtils.java @@ -15,6 +15,7 @@ import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; @Component @Slf4j @@ -88,6 +89,18 @@ public BakeRecipe buildCommand( command.add("--include-crds"); } + String apiVersions = request.getApiVersions(); + if (StringUtils.hasText(apiVersions)) { + command.add("--api-versions"); + command.add(apiVersions); + } + + String kubeVersion = request.getKubeVersion(); + if (StringUtils.hasText(kubeVersion)) { + command.add("--kube-version"); + command.add(kubeVersion); + } + Map overrides = request.getOverrides(); if (!overrides.isEmpty()) { List overrideList = new ArrayList<>(); diff --git a/rosco-manifests/src/test/java/com/netflix/spinnaker/rosco/manifests/helm/HelmTemplateUtilsTest.java b/rosco-manifests/src/test/java/com/netflix/spinnaker/rosco/manifests/helm/HelmTemplateUtilsTest.java index 1a6eb41e9..f164c9cf5 100644 --- a/rosco-manifests/src/test/java/com/netflix/spinnaker/rosco/manifests/helm/HelmTemplateUtilsTest.java +++ b/rosco-manifests/src/test/java/com/netflix/spinnaker/rosco/manifests/helm/HelmTemplateUtilsTest.java @@ -340,6 +340,56 @@ public void buildBakeRecipeWithGitRepoArtifactUsingHelmChartFilePath(@TempDir Pa } } + @Test + public void buildBakeRecipeIncludingHelmVersionsOptionsWithHelm3() throws IOException { + ArtifactDownloader artifactDownloader = mock(ArtifactDownloader.class); + RoscoHelmConfigurationProperties helmConfigurationProperties = + new RoscoHelmConfigurationProperties(); + HelmTemplateUtils helmTemplateUtils = + new HelmTemplateUtils(artifactDownloader, helmConfigurationProperties); + + HelmBakeManifestRequest request = new HelmBakeManifestRequest(); + Artifact artifact = Artifact.builder().build(); + request.setTemplateRenderer(BakeManifestRequest.TemplateRenderer.HELM3); + request.setApiVersions("customApiVersion"); + request.setKubeVersion("customKubernetesVersion"); + request.setInputArtifacts(Collections.singletonList(artifact)); + request.setOverrides(Collections.emptyMap()); + + try (BakeManifestEnvironment env = BakeManifestEnvironment.create()) { + BakeRecipe bakeRecipe = helmTemplateUtils.buildBakeRecipe(env, request); + assertTrue(bakeRecipe.getCommand().contains("--api-versions")); + assertTrue(bakeRecipe.getCommand().indexOf("--api-versions") > 3); + assertTrue(bakeRecipe.getCommand().contains("--kube-version")); + assertTrue(bakeRecipe.getCommand().indexOf("--kube-version") > 5); + } + } + + @Test + public void buildBakeRecipeIncludingHelmVersionsOptionsWithHelm2() throws IOException { + ArtifactDownloader artifactDownloader = mock(ArtifactDownloader.class); + RoscoHelmConfigurationProperties helmConfigurationProperties = + new RoscoHelmConfigurationProperties(); + HelmTemplateUtils helmTemplateUtils = + new HelmTemplateUtils(artifactDownloader, helmConfigurationProperties); + + HelmBakeManifestRequest request = new HelmBakeManifestRequest(); + Artifact artifact = Artifact.builder().build(); + request.setTemplateRenderer(BakeManifestRequest.TemplateRenderer.HELM2); + request.setApiVersions("customApiVersion"); + request.setKubeVersion("customKubernetesVersion"); + request.setInputArtifacts(Collections.singletonList(artifact)); + request.setOverrides(Collections.emptyMap()); + + try (BakeManifestEnvironment env = BakeManifestEnvironment.create()) { + BakeRecipe bakeRecipe = helmTemplateUtils.buildBakeRecipe(env, request); + assertTrue(bakeRecipe.getCommand().contains("--api-versions")); + assertTrue(bakeRecipe.getCommand().indexOf("--api-versions") > 3); + assertTrue(bakeRecipe.getCommand().contains("--kube-version")); + assertTrue(bakeRecipe.getCommand().indexOf("--kube-version") > 5); + } + } + @Test public void buildBakeRecipeIncludingCRDsWithHelm3() throws IOException { ArtifactDownloader artifactDownloader = mock(ArtifactDownloader.class);