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 dd1d59d96..bd728e750 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 @@ -30,6 +30,8 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import com.netflix.spinnaker.kork.artifacts.artifactstore.ArtifactStore; +import com.netflix.spinnaker.kork.artifacts.artifactstore.ArtifactStoreConfigurationProperties; import com.netflix.spinnaker.kork.artifacts.model.Artifact; import com.netflix.spinnaker.kork.exceptions.SpinnakerException; import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerHttpException; @@ -47,6 +49,9 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.Stream; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; @@ -70,6 +75,12 @@ final class HelmTemplateUtilsTest { private HelmBakeManifestRequest bakeManifestRequest; + /** + * Configuration for the default values in the event artifact store had been + * turned off. + */ + private ArtifactStoreConfigurationProperties artifactStoreConfig; + @BeforeEach private void init(TestInfo testInfo) { System.out.println("--------------- Test " + testInfo.getDisplayName()); @@ -77,7 +88,14 @@ private void init(TestInfo testInfo) { artifactDownloader = mock(ArtifactDownloader.class); RoscoHelmConfigurationProperties helmConfigurationProperties = new RoscoHelmConfigurationProperties(); - helmTemplateUtils = new HelmTemplateUtils(artifactDownloader, helmConfigurationProperties); + artifactStoreConfig = new ArtifactStoreConfigurationProperties(); + ArtifactStoreConfigurationProperties.HelmConfig helmConfig = + new ArtifactStoreConfigurationProperties.HelmConfig(); + artifactStoreConfig.setHelm(helmConfig); + helmConfig.setExpandOverrides(false); + helmTemplateUtils = + new HelmTemplateUtils( + artifactDownloader, Optional.empty(), artifactStoreConfig, helmConfigurationProperties); Artifact chartArtifact = Artifact.builder().name("test-artifact").version("3").build(); bakeManifestRequest = new HelmBakeManifestRequest(); @@ -154,7 +172,8 @@ public void removeTestsDirectoryTemplatesWithTests() throws IOException { RoscoHelmConfigurationProperties helmConfigurationProperties = new RoscoHelmConfigurationProperties(); HelmTemplateUtils helmTemplateUtils = - new HelmTemplateUtils(artifactDownloader, helmConfigurationProperties); + new HelmTemplateUtils( + artifactDownloader, Optional.empty(), artifactStoreConfig, helmConfigurationProperties); String output = helmTemplateUtils.removeTestsDirectoryTemplates(inputManifests); @@ -208,7 +227,8 @@ public void removeTestsDirectoryTemplatesWithoutTests() throws IOException { RoscoHelmConfigurationProperties helmConfigurationProperties = new RoscoHelmConfigurationProperties(); HelmTemplateUtils helmTemplateUtils = - new HelmTemplateUtils(artifactDownloader, helmConfigurationProperties); + new HelmTemplateUtils( + artifactDownloader, Optional.empty(), artifactStoreConfig, helmConfigurationProperties); String output = helmTemplateUtils.removeTestsDirectoryTemplates(inputManifests); @@ -223,7 +243,8 @@ public void buildBakeRecipeSelectsHelmExecutableByVersion( RoscoHelmConfigurationProperties helmConfigurationProperties = new RoscoHelmConfigurationProperties(); HelmTemplateUtils helmTemplateUtils = - new HelmTemplateUtils(artifactDownloader, helmConfigurationProperties); + new HelmTemplateUtils( + artifactDownloader, Optional.empty(), artifactStoreConfig, helmConfigurationProperties); HelmBakeManifestRequest request = new HelmBakeManifestRequest(); Artifact artifact = Artifact.builder().build(); @@ -256,7 +277,8 @@ public void buildBakeRecipeWithGitRepoArtifact(@TempDir Path tempDir) throws IOE RoscoHelmConfigurationProperties helmConfigurationProperties = new RoscoHelmConfigurationProperties(); HelmTemplateUtils helmTemplateUtils = - new HelmTemplateUtils(artifactDownloader, helmConfigurationProperties); + new HelmTemplateUtils( + artifactDownloader, Optional.empty(), artifactStoreConfig, helmConfigurationProperties); HelmBakeManifestRequest request = new HelmBakeManifestRequest(); @@ -296,7 +318,8 @@ public void buildBakeRecipeWithGitRepoArtifactUsingHelmChartFilePath(@TempDir Pa RoscoHelmConfigurationProperties helmConfigurationProperties = new RoscoHelmConfigurationProperties(); HelmTemplateUtils helmTemplateUtils = - new HelmTemplateUtils(artifactDownloader, helmConfigurationProperties); + new HelmTemplateUtils( + artifactDownloader, Optional.empty(), artifactStoreConfig, helmConfigurationProperties); HelmBakeManifestRequest request = new HelmBakeManifestRequest(); @@ -356,7 +379,8 @@ public void buildBakeRecipeIncludingHelmVersionsOptionsWithHelm3() throws IOExce RoscoHelmConfigurationProperties helmConfigurationProperties = new RoscoHelmConfigurationProperties(); HelmTemplateUtils helmTemplateUtils = - new HelmTemplateUtils(artifactDownloader, helmConfigurationProperties); + new HelmTemplateUtils( + artifactDownloader, Optional.empty(), artifactStoreConfig, helmConfigurationProperties); HelmBakeManifestRequest request = new HelmBakeManifestRequest(); Artifact artifact = Artifact.builder().build(); @@ -381,7 +405,8 @@ public void buildBakeRecipeIncludingHelmVersionsOptionsWithHelm2() throws IOExce RoscoHelmConfigurationProperties helmConfigurationProperties = new RoscoHelmConfigurationProperties(); HelmTemplateUtils helmTemplateUtils = - new HelmTemplateUtils(artifactDownloader, helmConfigurationProperties); + new HelmTemplateUtils( + artifactDownloader, Optional.empty(), artifactStoreConfig, helmConfigurationProperties); HelmBakeManifestRequest request = new HelmBakeManifestRequest(); Artifact artifact = Artifact.builder().build(); @@ -406,7 +431,8 @@ public void buildBakeRecipeIncludingCRDsWithHelm3() throws IOException { RoscoHelmConfigurationProperties helmConfigurationProperties = new RoscoHelmConfigurationProperties(); HelmTemplateUtils helmTemplateUtils = - new HelmTemplateUtils(artifactDownloader, helmConfigurationProperties); + new HelmTemplateUtils( + artifactDownloader, Optional.empty(), artifactStoreConfig, helmConfigurationProperties); HelmBakeManifestRequest request = new HelmBakeManifestRequest(); Artifact artifact = Artifact.builder().build(); @@ -423,6 +449,54 @@ public void buildBakeRecipeIncludingCRDsWithHelm3() throws IOException { } } + @ParameterizedTest + @MethodSource("ensureOverrides") + public void ensureOverridesGetEvaluated( + String reference, + Map overrides, + String expected, + Boolean artifactStoreNull, + Boolean expandOverrides) { + ArtifactStore artifactStore = null; + if (!artifactStoreNull) { + artifactStore = mock(ArtifactStore.class); + when(artifactStore.get(any())).thenReturn(Artifact.builder().reference(reference).build()); + } + RoscoHelmConfigurationProperties helmConfigurationProperties = + new RoscoHelmConfigurationProperties(); + + // do not use the artifactStoreConfig field as we are trying to test various + // values of expandOverrides + ArtifactStoreConfigurationProperties artifactStoreConfiguration = + new ArtifactStoreConfigurationProperties(); + ArtifactStoreConfigurationProperties.HelmConfig helmConfig = + new ArtifactStoreConfigurationProperties.HelmConfig(); + helmConfig.setExpandOverrides(expandOverrides); + artifactStoreConfiguration.setHelm(helmConfig); + + HelmTemplateUtils helmTemplateUtils = + new HelmTemplateUtils( + artifactDownloader, + Optional.ofNullable(artifactStore), + artifactStoreConfiguration, + helmConfigurationProperties); + HelmBakeManifestRequest request = new HelmBakeManifestRequest(); + request.setOutputName("output_name"); + request.setTemplateRenderer(BakeManifestRequest.TemplateRenderer.HELM3); + request.setOverrides(overrides); + BakeRecipe recipe = + helmTemplateUtils.buildCommand(request, List.of(), Path.of("template_path")); + + assertThat(recipe.getCommand().contains(expected)).isTrue(); + } + + private static Stream ensureOverrides() { + return Stream.of( + Arguments.of("test", Map.of("foo", "ref://bar/baz"), "foo=test", false, true), + Arguments.of("test", Map.of("foo", "ref://bar/baz"), "foo=ref://bar/baz", false, false), + Arguments.of("test", Map.of("foo", "ref://bar/baz"), "foo=ref://bar/baz", true, false)); + } + @ParameterizedTest @MethodSource("helmRendererArgsCRDs") public void buildBakeRecipeNotIncludingCRDs( @@ -432,7 +506,8 @@ public void buildBakeRecipeNotIncludingCRDs( RoscoHelmConfigurationProperties helmConfigurationProperties = new RoscoHelmConfigurationProperties(); HelmTemplateUtils helmTemplateUtils = - new HelmTemplateUtils(artifactDownloader, helmConfigurationProperties); + new HelmTemplateUtils( + artifactDownloader, Optional.empty(), artifactStoreConfig, helmConfigurationProperties); HelmBakeManifestRequest request = new HelmBakeManifestRequest(); Artifact artifact = Artifact.builder().build(); diff --git a/rosco-manifests/src/test/java/com/netflix/spinnaker/rosco/manifests/helmfile/HelmfileTemplateUtilsTest.java b/rosco-manifests/src/test/java/com/netflix/spinnaker/rosco/manifests/helmfile/HelmfileTemplateUtilsTest.java index 91d76ebf8..5d52d4cf8 100644 --- a/rosco-manifests/src/test/java/com/netflix/spinnaker/rosco/manifests/helmfile/HelmfileTemplateUtilsTest.java +++ b/rosco-manifests/src/test/java/com/netflix/spinnaker/rosco/manifests/helmfile/HelmfileTemplateUtilsTest.java @@ -30,6 +30,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import com.netflix.spinnaker.kork.artifacts.artifactstore.ArtifactStoreConfigurationProperties; import com.netflix.spinnaker.kork.artifacts.model.Artifact; import com.netflix.spinnaker.kork.exceptions.SpinnakerException; import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerHttpException; @@ -49,6 +50,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.Stream; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; @@ -72,6 +74,8 @@ final class HelmfileTemplateUtilsTest { private HelmfileBakeManifestRequest bakeManifestRequest; + private ArtifactStoreConfigurationProperties artifactStoreConfig; + @BeforeEach private void init(TestInfo testInfo) { System.out.println("--------------- Test " + testInfo.getDisplayName()); @@ -79,8 +83,17 @@ private void init(TestInfo testInfo) { artifactDownloader = mock(ArtifactDownloader.class); RoscoHelmfileConfigurationProperties helmfileConfigurationProperties = new RoscoHelmfileConfigurationProperties(); + artifactStoreConfig = new ArtifactStoreConfigurationProperties(); + ArtifactStoreConfigurationProperties.HelmConfig helmConfig = + new ArtifactStoreConfigurationProperties.HelmConfig(); + artifactStoreConfig.setHelm(helmConfig); + helmConfig.setExpandOverrides(false); helmfileTemplateUtils = - new HelmfileTemplateUtils(artifactDownloader, helmfileConfigurationProperties); + new HelmfileTemplateUtils( + artifactDownloader, + Optional.empty(), + artifactStoreConfig, + helmfileConfigurationProperties); Artifact chartArtifact = Artifact.builder().name("test-artifact").version("3").build(); bakeManifestRequest = new HelmfileBakeManifestRequest(); @@ -177,7 +190,11 @@ public void removeTestsDirectoryTemplatesWithTests() throws IOException { RoscoHelmfileConfigurationProperties helmfileConfigurationProperties = new RoscoHelmfileConfigurationProperties(); HelmfileTemplateUtils helmfileTemplateUtils = - new HelmfileTemplateUtils(artifactDownloader, helmfileConfigurationProperties); + new HelmfileTemplateUtils( + artifactDownloader, + Optional.empty(), + artifactStoreConfig, + helmfileConfigurationProperties); String output = helmfileTemplateUtils.removeTestsDirectoryTemplates(inputManifests); @@ -231,7 +248,11 @@ public void removeTestsDirectoryTemplatesWithoutTests() throws IOException { RoscoHelmfileConfigurationProperties helmfileConfigurationProperties = new RoscoHelmfileConfigurationProperties(); HelmfileTemplateUtils helmfileTemplateUtils = - new HelmfileTemplateUtils(artifactDownloader, helmfileConfigurationProperties); + new HelmfileTemplateUtils( + artifactDownloader, + Optional.empty(), + artifactStoreConfig, + helmfileConfigurationProperties); String output = helmfileTemplateUtils.removeTestsDirectoryTemplates(inputManifests); @@ -246,7 +267,11 @@ public void buildBakeRecipeSelectsHelm3ExecutableWhenNoneSet( RoscoHelmfileConfigurationProperties helmfileConfigurationProperties = new RoscoHelmfileConfigurationProperties(); HelmfileTemplateUtils helmfileTemplateUtils = - new HelmfileTemplateUtils(artifactDownloader, helmfileConfigurationProperties); + new HelmfileTemplateUtils( + artifactDownloader, + Optional.empty(), + artifactStoreConfig, + helmfileConfigurationProperties); RoscoHelmConfigurationProperties helmConfigurationProperties = new RoscoHelmConfigurationProperties(); @@ -280,7 +305,11 @@ public void buildBakeRecipeWithGitRepoArtifact(@TempDir Path tempDir) throws IOE RoscoHelmfileConfigurationProperties helmfileConfigurationProperties = new RoscoHelmfileConfigurationProperties(); HelmfileTemplateUtils helmfileTemplateUtils = - new HelmfileTemplateUtils(artifactDownloader, helmfileConfigurationProperties); + new HelmfileTemplateUtils( + artifactDownloader, + Optional.empty(), + artifactStoreConfig, + helmfileConfigurationProperties); HelmfileBakeManifestRequest request = new HelmfileBakeManifestRequest(); @@ -320,7 +349,11 @@ public void buildBakeRecipeWithGitRepoArtifactUsingHelmfileFilePath(@TempDir Pat RoscoHelmfileConfigurationProperties helmfileConfigurationProperties = new RoscoHelmfileConfigurationProperties(); HelmfileTemplateUtils helmfileTemplateUtils = - new HelmfileTemplateUtils(artifactDownloader, helmfileConfigurationProperties); + new HelmfileTemplateUtils( + artifactDownloader, + Optional.empty(), + artifactStoreConfig, + helmfileConfigurationProperties); HelmfileBakeManifestRequest request = new HelmfileBakeManifestRequest(); @@ -459,7 +492,11 @@ public void buildBakeRecipeIncludesEnvironmentWhenSet() throws IOException { RoscoHelmfileConfigurationProperties helmfileConfigurationProperties = new RoscoHelmfileConfigurationProperties(); HelmfileTemplateUtils helmfileTemplateUtils = - new HelmfileTemplateUtils(artifactDownloader, helmfileConfigurationProperties); + new HelmfileTemplateUtils( + artifactDownloader, + Optional.empty(), + artifactStoreConfig, + helmfileConfigurationProperties); HelmfileBakeManifestRequest request = new HelmfileBakeManifestRequest(); Artifact artifact = Artifact.builder().build(); @@ -483,7 +520,11 @@ public void buildBakeRecipeDoesNotIncludeEnvironmentWhenNotSet() throws IOExcept RoscoHelmfileConfigurationProperties helmfileConfigurationProperties = new RoscoHelmfileConfigurationProperties(); HelmfileTemplateUtils helmfileTemplateUtils = - new HelmfileTemplateUtils(artifactDownloader, helmfileConfigurationProperties); + new HelmfileTemplateUtils( + artifactDownloader, + Optional.empty(), + artifactStoreConfig, + helmfileConfigurationProperties); HelmfileBakeManifestRequest request = new HelmfileBakeManifestRequest(); Artifact artifact = Artifact.builder().build(); @@ -502,7 +543,11 @@ public void buildBakeRecipeIncludesNamespaceWhenSet() throws IOException { RoscoHelmfileConfigurationProperties helmfileConfigurationProperties = new RoscoHelmfileConfigurationProperties(); HelmfileTemplateUtils helmfileTemplateUtils = - new HelmfileTemplateUtils(artifactDownloader, helmfileConfigurationProperties); + new HelmfileTemplateUtils( + artifactDownloader, + Optional.empty(), + artifactStoreConfig, + helmfileConfigurationProperties); HelmfileBakeManifestRequest request = new HelmfileBakeManifestRequest(); Artifact artifact = Artifact.builder().build(); @@ -526,7 +571,11 @@ public void buildBakeRecipeDoesNotIncludeNamespaceWhenNotSet() throws IOExceptio RoscoHelmfileConfigurationProperties helmfileConfigurationProperties = new RoscoHelmfileConfigurationProperties(); HelmfileTemplateUtils helmfileTemplateUtils = - new HelmfileTemplateUtils(artifactDownloader, helmfileConfigurationProperties); + new HelmfileTemplateUtils( + artifactDownloader, + Optional.empty(), + artifactStoreConfig, + helmfileConfigurationProperties); HelmfileBakeManifestRequest request = new HelmfileBakeManifestRequest(); Artifact artifact = Artifact.builder().build(); @@ -545,7 +594,11 @@ public void buildBakeRecipeIncludingCRDsWithHelm3() throws IOException { RoscoHelmfileConfigurationProperties helmfileConfigurationProperties = new RoscoHelmfileConfigurationProperties(); HelmfileTemplateUtils helmfileTemplateUtils = - new HelmfileTemplateUtils(artifactDownloader, helmfileConfigurationProperties); + new HelmfileTemplateUtils( + artifactDownloader, + Optional.empty(), + artifactStoreConfig, + helmfileConfigurationProperties); HelmfileBakeManifestRequest request = new HelmfileBakeManifestRequest(); Artifact artifact = Artifact.builder().build(); @@ -567,7 +620,11 @@ public void buildBakeRecipeNotIncludingCRDsWithHelm3() throws IOException { RoscoHelmfileConfigurationProperties helmfileConfigurationProperties = new RoscoHelmfileConfigurationProperties(); HelmfileTemplateUtils helmfileTemplateUtils = - new HelmfileTemplateUtils(artifactDownloader, helmfileConfigurationProperties); + new HelmfileTemplateUtils( + artifactDownloader, + Optional.empty(), + artifactStoreConfig, + helmfileConfigurationProperties); HelmfileBakeManifestRequest request = new HelmfileBakeManifestRequest(); Artifact artifact = Artifact.builder().build(); @@ -586,7 +643,11 @@ public void buildBakeRecipeIncludesOverridesWhenSet() throws IOException { RoscoHelmfileConfigurationProperties helmfileConfigurationProperties = new RoscoHelmfileConfigurationProperties(); HelmfileTemplateUtils helmfileTemplateUtils = - new HelmfileTemplateUtils(artifactDownloader, helmfileConfigurationProperties); + new HelmfileTemplateUtils( + artifactDownloader, + Optional.empty(), + artifactStoreConfig, + helmfileConfigurationProperties); HelmfileBakeManifestRequest request = new HelmfileBakeManifestRequest(); Artifact artifact = Artifact.builder().build(); @@ -610,7 +671,11 @@ public void buildBakeRecipeDoesNotIncludeOverridesWhenNotSet() throws IOExceptio RoscoHelmfileConfigurationProperties helmfileConfigurationProperties = new RoscoHelmfileConfigurationProperties(); HelmfileTemplateUtils helmfileTemplateUtils = - new HelmfileTemplateUtils(artifactDownloader, helmfileConfigurationProperties); + new HelmfileTemplateUtils( + artifactDownloader, + Optional.empty(), + artifactStoreConfig, + helmfileConfigurationProperties); HelmfileBakeManifestRequest request = new HelmfileBakeManifestRequest(); Artifact artifact = Artifact.builder().build(); @@ -629,7 +694,11 @@ public void buildBakeRecipeIncludesValuesWhenSet() throws IOException { RoscoHelmfileConfigurationProperties helmfileConfigurationProperties = new RoscoHelmfileConfigurationProperties(); HelmfileTemplateUtils helmfileTemplateUtils = - new HelmfileTemplateUtils(artifactDownloader, helmfileConfigurationProperties); + new HelmfileTemplateUtils( + artifactDownloader, + Optional.empty(), + artifactStoreConfig, + helmfileConfigurationProperties); HelmfileBakeManifestRequest request = new HelmfileBakeManifestRequest(); @@ -656,7 +725,11 @@ public void buildBakeRecipeDoesNotIncludeValuesWhenNotSet() throws IOException { RoscoHelmfileConfigurationProperties helmfileConfigurationProperties = new RoscoHelmfileConfigurationProperties(); HelmfileTemplateUtils helmfileTemplateUtils = - new HelmfileTemplateUtils(artifactDownloader, helmfileConfigurationProperties); + new HelmfileTemplateUtils( + artifactDownloader, + Optional.empty(), + artifactStoreConfig, + helmfileConfigurationProperties); HelmfileBakeManifestRequest request = new HelmfileBakeManifestRequest(); Artifact artifact = Artifact.builder().build();