diff --git a/foundation/foundation-upgrade/src/main/java/com/boozallen/aissemble/upgrade/migration/v1_9_0/ArgocdTemplateSyncPolicyMigration.java b/foundation/foundation-upgrade/src/main/java/com/boozallen/aissemble/upgrade/migration/v1_9_0/ArgocdTemplateSyncPolicyMigration.java new file mode 100644 index 000000000..73d2b696b --- /dev/null +++ b/foundation/foundation-upgrade/src/main/java/com/boozallen/aissemble/upgrade/migration/v1_9_0/ArgocdTemplateSyncPolicyMigration.java @@ -0,0 +1,125 @@ +package com.boozallen.aissemble.upgrade.migration.v1_9_0; + +/*- + * #%L + * aiSSEMBLE::Foundation::Upgrade + * %% + * Copyright (C) 2021 Booz Allen + * %% + * This software package is licensed under the Booz Allen Public License. All Rights Reserved. + * #L% + */ + +import com.boozallen.aissemble.upgrade.migration.AbstractAissembleMigration; +import com.boozallen.aissemble.upgrade.util.YamlUtils; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import static com.boozallen.aissemble.upgrade.util.YamlUtils.indent; +import static org.technologybrewery.baton.util.FileUtils.readAllFileLines; +import static org.technologybrewery.baton.util.FileUtils.writeFile; + +/** + * This migration is responsible for updating the ArgoCD values file to include the syncPolicy in order to enable + * ArgoCD automatically sync an application ability. Ultimately, this enables the ArgoCD sync wave feature to function properly. + */ +public class ArgocdTemplateSyncPolicyMigration extends AbstractAissembleMigration { + + protected static final Logger logger = LoggerFactory.getLogger(ArgocdTemplateSyncPolicyMigration.class); + private static final String SYNC_POLICY = "syncPolicy:"; + private static final String SPEC = "spec:"; + + @Override + protected boolean shouldExecuteOnFile(File file) { + boolean shouldExecute = true; + if (file != null && file.exists()) { + try { + List content = readAllFileLines(file); + if (isApplication(content)) { + for (String line: content) { + if (line.trim().equals(SYNC_POLICY)) { + shouldExecute = false; + break; + } + } + } else { + shouldExecute = false; + } + } catch (IOException e) { + logger.error("Failed to check content of file: {}", file.getPath(), e); + } + } + return shouldExecute; + } + + @Override + protected boolean performMigration(File file) { + try { + List content = readAllFileLines(file); + List updatedContent = new ArrayList<>(); + boolean startSpecConfig = false; + int counter = 0; + int size = content.size(); + int indentSpaces = 0; + String specIndent = null; + for (String line: content) { + counter++; + boolean lastItem = counter == size; + + line = line.stripTrailing(); + if (line.equals(SPEC)) { + startSpecConfig = true; + updatedContent.add(line); + + // get the indentSpaces spaces + indentSpaces = YamlUtils.getIndentSpaces(content, counter); + specIndent = indent(1, indentSpaces); + continue; + } + + if (startSpecConfig && !StringUtils.isBlank(line) && !line.startsWith(specIndent)) { + updatedContent.addAll(getSyncPolicyHelmFunc(indentSpaces)); + startSpecConfig = false; + } + updatedContent.add(line); + + if (startSpecConfig && lastItem) { + updatedContent.addAll(getSyncPolicyHelmFunc(indentSpaces)); + } + } + + writeFile(file, updatedContent); + } catch (Exception e) { + logger.error("Failed to migrate ArgoCD syncPolicy to the template file: {}", file.getPath(), e); + } + return false; + } + + private List getSyncPolicyHelmFunc(int indentSpaces) { + ArrayList syncPolicy = new ArrayList(); + syncPolicy.add(indent(1, indentSpaces) + "{{- with .Values.spec.syncPolicy }}"); + syncPolicy.add(indent(1, indentSpaces) + "syncPolicy:"); + syncPolicy.add(indent(2, indentSpaces) + String.format("{{- toYaml . | nindent %d }}", 2 * indentSpaces)); + syncPolicy.add(indent(1, indentSpaces) + "{{- end }}"); + return syncPolicy; + } + + private boolean isApplication(List content) { + final String kindApplication = "kind:application"; + String line = ""; + for (int i=0; i 0; + } catch (IOException e) { + logger.error("Failed to check content of file: {}", file.getPath(), e); + } + return false; + } + + @Override + protected boolean performMigration(File file) { + try { + List content = FileUtils.readAllFileLines(file); + List updatedContent = new ArrayList<>(); + + String syncPolicy = null; + String syncPolicyIndent = null; + String specIndent = null; + String line; + boolean inSpecConfig = false; + boolean inSyncPolicyConfig = false; + boolean skip; + boolean lastItem; + int size = content.size(); + int indentSpaces = 0; + + for (int i=0; i getMigratedSyncPolicyContent(File file, int indentSpace) throws IOException { + + YamlUtils.YamlObject yaml = YamlUtils.loadYaml(file); + if (!yaml.isEmpty() && yaml.containsKey("spec")) { + YamlUtils.YamlObject spec = yaml.getObject("spec"); + if (spec.containsKey("syncPolicy")) { + YamlUtils.YamlObject syncPolicy = spec.getObject("syncPolicy"); + if (syncPolicy.containsKey("syncOptions")) { + List syncOptions = syncPolicy.getListOfStrings("syncOptions"); + + if (containsExpectedSyncOptions(syncOptions) && syncPolicy.containsKey(AUTOMATED)) { + return new ArrayList<>(); + } + + return generateSyncPolicyContent(syncOptions, syncPolicy, indentSpace); + } + } + return generateSyncPolicyContent(new ArrayList<>(), new YamlUtils.YamlObject(new HashMap<>()), indentSpace); + } + List syncPolicyContent = generateSyncPolicyContent(new ArrayList<>(), new YamlUtils.YamlObject(new HashMap<>()), indentSpace); + syncPolicyContent.add(0, SPEC); + return syncPolicyContent; + } + + private boolean containsExpectedSyncOptions(List options) { + return options.stream().filter(line -> (line.contains(CREATE_NAMESPACE_OPTION) || line.contains(APPLY_OUT_OF_SYNC_OPTION))).count() >=2; + } + + private List generateSyncPolicyContent(List options, YamlUtils.YamlObject syncPolicy, int indentSpaces) { + List content = new ArrayList<>(); + content.add(indent(1, indentSpaces) + "syncPolicy:"); + content.add(indent(2, indentSpaces) + "syncOptions:"); + content.add(indent(3, indentSpaces) + "- CreateNamespace=true"); + content.add(indent(3, indentSpaces) + "- ApplyOutOfSyncOnly=true"); + for (String option: options) { + if (!option.contains(CREATE_NAMESPACE_OPTION) && !option.contains(APPLY_OUT_OF_SYNC_OPTION)) { + content.add(String.format("%s- %s", indent(3, indentSpaces), option)); + } + } + content.addAll(generateAutomatedSyncPolicy(syncPolicy, indentSpaces)); + return content; + } + + private List generateAutomatedSyncPolicy(YamlUtils.YamlObject syncPolicy, int indentSpaces) { + List automated = new ArrayList<>(); + if (syncPolicy.containsKey(AUTOMATED)) { + YamlUtils.YamlObject automatedYaml = syncPolicy.getObject(AUTOMATED); + Set keys = automatedYaml.keySet(); + if (keys != null && keys.size() > 0) { + automated.add(indent(2, indentSpaces) + "automated:"); + for (String key : keys) { + automated.add(String.format("%s%s: %s", indent(3, indentSpaces), key, automatedYaml.get(key))); + } + return automated; + } + } + + automated.add(indent(2, indentSpaces) + "automated: {}"); + return automated; + } + +} diff --git a/foundation/foundation-upgrade/src/main/java/com/boozallen/aissemble/upgrade/util/YamlUtils.java b/foundation/foundation-upgrade/src/main/java/com/boozallen/aissemble/upgrade/util/YamlUtils.java index 109f2044f..04823cfaf 100644 --- a/foundation/foundation-upgrade/src/main/java/com/boozallen/aissemble/upgrade/util/YamlUtils.java +++ b/foundation/foundation-upgrade/src/main/java/com/boozallen/aissemble/upgrade/util/YamlUtils.java @@ -11,6 +11,7 @@ import com.google.common.base.CaseFormat; import com.google.common.io.Files; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import com.boozallen.aissemble.upgrade.pojo.AbstractYamlObject; @@ -34,6 +35,9 @@ import org.yaml.snakeyaml.representer.Representer; public class YamlUtils { + private static final String SPACE = " "; + private static final int TAB = 2; + private static final String VALUE_FOR_KEY_IS_NOT = "Value for [%s] is not %s: %s"; public static YamlObject loadYaml(File file) throws IOException { Yaml yaml = new Yaml(); try (InputStream fileStream = Files.asByteSource(file).openStream()) { @@ -61,7 +65,7 @@ public boolean hasString(String key) { public String getString(String key) { Object value = get(key); if (!(value instanceof String)) { - throw new IllegalArgumentException("Value for [" + key + "] is not a string: " + value); + throw new IllegalArgumentException(String.format(VALUE_FOR_KEY_IS_NOT, key, "a string", value)); } return (String) value; } @@ -73,7 +77,7 @@ public boolean hasInt(String key) { public int getInt(String key) { Object value = get(key); if (!(value instanceof Integer)) { - throw new IllegalArgumentException("Value for [" + key + "] is not an integer: " + value); + throw new IllegalArgumentException(String.format(VALUE_FOR_KEY_IS_NOT, key, "an integer", value)); } return (int) value; } @@ -85,7 +89,7 @@ public boolean hasDouble(String key) { public double getDouble(String key) { Object value = get(key); if (!(value instanceof Double)) { - throw new IllegalArgumentException("Value for [" + key + "] is not a double: " + value); + throw new IllegalArgumentException(String.format(VALUE_FOR_KEY_IS_NOT, key, "a double", value)); } return (double) value; } @@ -97,7 +101,7 @@ public boolean hasBoolean(String key) { public boolean getBoolean(String key) { Object value = get(key); if (!(value instanceof Boolean)) { - throw new IllegalArgumentException("Value for [" + key + "] is not a boolean: " + value); + throw new IllegalArgumentException(String.format(VALUE_FOR_KEY_IS_NOT, key, "a boolean", value)); } return (boolean) value; } @@ -109,7 +113,7 @@ public boolean hasObject(String key) { public YamlObject getObject(String key) { Object value = get(key); if (!(value instanceof Map)) { - throw new IllegalArgumentException("Value for [" + key + "] is not a map: " + value); + throw new IllegalArgumentException(String.format(VALUE_FOR_KEY_IS_NOT, key, "a map", value)); } return new YamlObject((Map) value); } @@ -121,7 +125,7 @@ public boolean hasList(String key) { public List getList(String key) { Object value = get(key); if (!(value instanceof List)) { - throw new IllegalArgumentException("Value for [" + key + "] is not a list: " + value); + throw new IllegalArgumentException(String.format(VALUE_FOR_KEY_IS_NOT, key, "a list", value)); } return (List) value; } @@ -219,4 +223,42 @@ public Property getProperty(Class type, String name) { } return helmYamlObject; } + + /** + * Provide indent with given indent spaces and level of indention + * @param level the level of indent + * @return the indent + */ + public static String indent(int level, int tab) { + return StringUtils.repeat(SPACE, level*tab); + } + + /** + * Provide indent with default indent spaces (2) and level of indention + * @param level the level of indent + * @return the indent + */ + public static String indent(int level) { + return StringUtils.repeat(SPACE, level*TAB); + } + + + /** + * get the number of indent spaces with given file yaml file content in List format and a start index to search the indent + * @param yamlFileContent yaml file content in list format + * @param startIndex start index to search the indent + * @return number of indent spaces + */ + public static int getIndentSpaces(List yamlFileContent, int startIndex) { + int indentSpaces = 0; + int index = startIndex; + while (indentSpaces == 0) { + String line = yamlFileContent.get(index).stripTrailing(); + if (!StringUtils.isBlank(line)) { + indentSpaces = line.indexOf(line.trim()); + } + index++; + } + return indentSpaces; + } } diff --git a/foundation/foundation-upgrade/src/main/resources/migrations.json b/foundation/foundation-upgrade/src/main/resources/migrations.json index 4af171dcf..e4d85d440 100644 --- a/foundation/foundation-upgrade/src/main/resources/migrations.json +++ b/foundation/foundation-upgrade/src/main/resources/migrations.json @@ -22,6 +22,29 @@ "excludes": ["*-docker/*/target/Dockerfile"] } ] + }, + { + "name": "argocd-template-sync-policy-configuration-migration", + "implementation": "com.boozallen.aissemble.upgrade.migration.v1_9_0.ArgocdTemplateSyncPolicyMigration", + "fileSets": [ + { + "includes": [ + "*-deploy/src/main/resources/templates/*.yaml" + ], + "excludes": ["*-deploy/src/main/resources/templates/sealed-secret.yaml"] + } + ] + }, + { + "name": "argocd-value-file-sync-policy-configuration-migration", + "implementation": "com.boozallen.aissemble.upgrade.migration.v1_9_0.ArgocdValueFileSyncPolicyMigration", + "fileSets": [ + { + "includes": [ + "*-deploy/src/main/resources/values.yaml" + ] + } + ] } ] }, diff --git a/foundation/foundation-upgrade/src/test/java/com/boozallen/aissemble/upgrade/migration/v1_9_0/ArgocdTemplateSyncPolicyMigrationStep.java b/foundation/foundation-upgrade/src/test/java/com/boozallen/aissemble/upgrade/migration/v1_9_0/ArgocdTemplateSyncPolicyMigrationStep.java new file mode 100644 index 000000000..1960c2e4b --- /dev/null +++ b/foundation/foundation-upgrade/src/test/java/com/boozallen/aissemble/upgrade/migration/v1_9_0/ArgocdTemplateSyncPolicyMigrationStep.java @@ -0,0 +1,75 @@ +package com.boozallen.aissemble.upgrade.migration.v1_9_0; + +/*- + * #%L + * aiSSEMBLE::Foundation::Upgrade + * %% + * Copyright (C) 2021 Booz Allen + * %% + * This software package is licensed under the Booz Allen Public License. All Rights Reserved. + * #L% + */ + +import com.boozallen.aissemble.upgrade.migration.AbstractAissembleMigration; +import com.boozallen.aissemble.upgrade.migration.AbstractMigrationTest; +import com.boozallen.aissemble.upgrade.util.YamlUtils; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; +import org.technologybrewery.baton.util.FileUtils; + +import java.io.File; +import java.io.IOException; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class ArgocdTemplateSyncPolicyMigrationStep extends AbstractMigrationTest { + private File validatedFile; + + @Given("an ArgoCD template doesn't have syncPolicy configuration defined") + public void anArgoCDTemplateDoesNotHaveSyncPolicyConfigurationDefined() { + testFile = getTestFile("v1_9_0/ArgocdTemplateSyncPolicyMigration/migration/applicable-template.yaml"); + } + + @Given("an ArgoCD template has the syncPolicy configuration defined") + public void anArgoCDTemplateHasSyncPolicyConfigurationDefined() { + testFile = getTestFile("v1_9_0/ArgocdTemplateSyncPolicyMigration/migration/inapplicable-template.yaml"); + } + + @Given("a template that is not an ArgoCD application") + public void aTemplateThatIsNotArgoCDApplication() { + testFile = getTestFile("v1_9_0/ArgocdTemplateSyncPolicyMigration/migration/not-application-template.yaml"); + } + + @Given("an ArgoCD template file has indent with 4 spaces") + public void anArgoCDTemplateFileHasIndentWith4Spaces() { + testFile = getTestFile("v1_9_0/ArgocdTemplateSyncPolicyMigration/migration/indent-with-4-spaces-template.yaml"); + } + + @When("the 1.9.0 ArgoCD template syncPolicy migration executes") + public void theArgoCDTemplateSyncPolicyMigrationExecutes() { + AbstractAissembleMigration migration = new ArgocdTemplateSyncPolicyMigration(); + performMigration(migration); + } + + @Then("the syncPolicy template function is included in the template") + public void theSyncPolicyTemplateFunctionIsIncludedInTheTemplate() { + validatedFile = getTestFile("/v1_9_0/ArgocdTemplateSyncPolicyMigration/validation/" + testFile.getName()); + assertTrue("The syncPolicy helm function is included in the template.", validateMigration(testFile, validatedFile)); + } + + @Then("the template is unchanged") + public void theTemplateIsUnchanged() { + validatedFile = getTestFile("/v1_9_0/ArgocdTemplateSyncPolicyMigration/validation/" + testFile.getName()); + assertTrue("The ArgoCD template is not impacted by migration!", validateMigration(testFile, validatedFile)); + } + + @Then("the application template still has indent with 4 spaces") + public void theApplicationTemplateStillHasIndentWith4Spaces() throws IOException { + List content = FileUtils.readAllFileLines(testFile); + assertEquals("the file still has indent with 4 spaces", 4, YamlUtils.getIndentSpaces(content, 0)); + } + +} diff --git a/foundation/foundation-upgrade/src/test/java/com/boozallen/aissemble/upgrade/migration/v1_9_0/ArgocdValueFileSyncPolicyMigrationStep.java b/foundation/foundation-upgrade/src/test/java/com/boozallen/aissemble/upgrade/migration/v1_9_0/ArgocdValueFileSyncPolicyMigrationStep.java new file mode 100644 index 000000000..1e4e2d02d --- /dev/null +++ b/foundation/foundation-upgrade/src/test/java/com/boozallen/aissemble/upgrade/migration/v1_9_0/ArgocdValueFileSyncPolicyMigrationStep.java @@ -0,0 +1,62 @@ +package com.boozallen.aissemble.upgrade.migration.v1_9_0; + +/*- + * #%L + * aiSSEMBLE::Foundation::Upgrade + * %% + * Copyright (C) 2021 Booz Allen + * %% + * This software package is licensed under the Booz Allen Public License. All Rights Reserved. + * #L% + */ + +import com.boozallen.aissemble.upgrade.migration.AbstractAissembleMigration; +import com.boozallen.aissemble.upgrade.migration.AbstractMigrationTest; +import com.boozallen.aissemble.upgrade.util.YamlUtils; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; +import org.apache.commons.lang3.StringUtils; +import org.technologybrewery.baton.util.FileUtils; + +import java.io.File; +import java.io.IOException; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class ArgocdValueFileSyncPolicyMigrationStep extends AbstractMigrationTest { + private String configuration; + + @Given("an ArgoCD value file has {string} configuration defined") + public void anArgoCDValueFileHasConfiguredSyncPolicyConfigurationDefined(String configuration) { + this.configuration = configuration; + testFile = getTestFile(String.format("v1_9_0/ArgocdValueFileSyncPolicyMigration/migration/%s-values.yaml", configuration)); + } + + @When("the 1.9.0 ArgoCD value file syncPolicy migration executes") + public void theArgoCDTemplateSyncPolicyMigrationExecutes() { + AbstractAissembleMigration migration = new ArgocdValueFileSyncPolicyMigration(); + performMigration(migration); + } + + @Then("the value file is updated with expected syncPolicy value function") + public void theSyncPolicyTemplateFunctionIsIncludedInTheTemplate() { + File validatedFile = getTestFile(String.format("v1_9_0/ArgocdValueFileSyncPolicyMigration/validation/%s-values.yaml", configuration)); + assertTrue("the value file is updated with expected syncPolicy value function.", validateMigration(testFile, validatedFile)); + } + + @Given("an ArgoCD value file has indent with 4 spaces") + public void anArgoCDValueFileHasIndentWith4Spaces() { + this.configuration = "indent-with-4-spaces"; + testFile = getTestFile("v1_9_0/ArgocdValueFileSyncPolicyMigration/migration/indent-with-4-spaces-values.yaml"); + } + + @Then("the file still has indent with 4 spaces") + public void theFileStillHasIndentWith4Spaces() throws IOException { + List content = FileUtils.readAllFileLines(testFile); + assertEquals("the file still has indent with 4 spaces", 4, YamlUtils.getIndentSpaces(content, 0)); + } + +} diff --git a/foundation/foundation-upgrade/src/test/resources/specifications/v1_9_0/argocd-template-syncpolicy-migration.feature b/foundation/foundation-upgrade/src/test/resources/specifications/v1_9_0/argocd-template-syncpolicy-migration.feature new file mode 100644 index 000000000..9112954df --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/specifications/v1_9_0/argocd-template-syncpolicy-migration.feature @@ -0,0 +1,22 @@ +Feature: Migration ArgoCD application template syncPolicy + + Scenario: Migrate an ArgoCD template without syncPolicy configuration + Given an ArgoCD template doesn't have syncPolicy configuration defined + When the 1.9.0 ArgoCD template syncPolicy migration executes + Then the syncPolicy template function is included in the template + + Scenario: An ArgoCD template with syncPolicy configured is not impacted by this migration + Given an ArgoCD template has the syncPolicy configuration defined + When the 1.9.0 ArgoCD template syncPolicy migration executes + Then the template is unchanged + + Scenario: A not ArgoCD application template is not impacted by this migration + Given a template that is not an ArgoCD application + When the 1.9.0 ArgoCD template syncPolicy migration executes + Then the template is unchanged + + Scenario: Migrate ArgoCD template file indent with 4 spaces + Given an ArgoCD template file has indent with 4 spaces + When the 1.9.0 ArgoCD template syncPolicy migration executes + Then the syncPolicy template function is included in the template + And the application template still has indent with 4 spaces \ No newline at end of file diff --git a/foundation/foundation-upgrade/src/test/resources/specifications/v1_9_0/argocd-value-file-syncpolicy-migration.feature b/foundation/foundation-upgrade/src/test/resources/specifications/v1_9_0/argocd-value-file-syncpolicy-migration.feature new file mode 100644 index 000000000..1b2bba1f7 --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/specifications/v1_9_0/argocd-value-file-syncpolicy-migration.feature @@ -0,0 +1,22 @@ +Feature: Migration ArgoCD value files syncPolicy + + Scenario Outline: An ArgoCD value file is migrated with different syncPolicy configuration + Given an ArgoCD value file has "" configuration defined + When the 1.9.0 ArgoCD value file syncPolicy migration executes + Then the value file is updated with expected syncPolicy value function + + Examples: + | configured syncPolicy | + | no-automated | + | no-sync-policy | + | no-sync-options | + | partial-sync-options | + | with-automated-prune | + | with-sync-options-replace | + | with-sync-policy | + + Scenario: Migrate ArgoCD value file indent with 4 spaces + Given an ArgoCD value file has indent with 4 spaces + When the 1.9.0 ArgoCD value file syncPolicy migration executes + Then the value file is updated with expected syncPolicy value function + And the file still has indent with 4 spaces diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdTemplateSyncPolicyMigration/migration/applicable-template.yaml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdTemplateSyncPolicyMigration/migration/applicable-template.yaml new file mode 100644 index 000000000..b3dc58802 --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdTemplateSyncPolicyMigration/migration/applicable-template.yaml @@ -0,0 +1,23 @@ +piVersion: argoproj.io/v1alpha1 +kind: Application +metadata: + name: test + namespace: argocd + finalizers: + - resources-finalizer.argocd.argoproj.io +spec: + destination: + namespace: argocd + server: {{ .Values.spec.destination.server }} + project: default + source: + path: abc-deploy/src/main/resources/apps/test + repoURL: {{ .Values.spec.repo }} + targetRevision: {{ .Values.spec.targetRevision }} + {{ if .Values.spec.helm.valueFiles }} + helm: + valueFiles: + {{- range .Values.spec.helm.valueFiles }} + - {{ . }} + {{- end }} + {{ end }} \ No newline at end of file diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdTemplateSyncPolicyMigration/migration/inapplicable-template.yaml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdTemplateSyncPolicyMigration/migration/inapplicable-template.yaml new file mode 100644 index 000000000..dcda7a7cb --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdTemplateSyncPolicyMigration/migration/inapplicable-template.yaml @@ -0,0 +1,26 @@ +apiVersion: argoproj.io/v1alpha1 +kind: Application +metadata: + name: test + namespace: argocd + finalizers: + - resources-finalizer.argocd.argoproj.io +spec: + destination: + namespace: argocd + server: {{ .Values.spec.destination.server }} + project: default + source: + path: abc-deploy/src/main/resources/apps/test + repoURL: {{ .Values.spec.repo }} + targetRevision: {{ .Values.spec.targetRevision }} + {{ if .Values.spec.helm.valueFiles }} + helm: + valueFiles: + {{- range .Values.spec.helm.valueFiles }} + - {{ . }} + {{- end }} + {{ end }} + syncPolicy: + syncOptions: + - CreateNamespace=true \ No newline at end of file diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdTemplateSyncPolicyMigration/migration/indent-with-4-spaces-template.yaml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdTemplateSyncPolicyMigration/migration/indent-with-4-spaces-template.yaml new file mode 100644 index 000000000..e3610f7e4 --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdTemplateSyncPolicyMigration/migration/indent-with-4-spaces-template.yaml @@ -0,0 +1,23 @@ +apiVersion: argoproj.io/v1alpha1 +kind: Application +metadata: + name: test + namespace: argocd + finalizers: + - resources-finalizer.argocd.argoproj.io +spec: + destination: + namespace: argocd + server: {{ .Values.spec.destination.server }} + project: default + source: + path: abc-deploy/src/main/resources/apps/test + repoURL: {{ .Values.spec.repo }} + targetRevision: {{ .Values.spec.targetRevision }} + {{ if .Values.spec.helm.valueFiles }} + helm: + valueFiles: + {{- range .Values.spec.helm.valueFiles }} + - {{ . }} + {{- end }} + {{ end }} \ No newline at end of file diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdTemplateSyncPolicyMigration/migration/not-application-template.yaml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdTemplateSyncPolicyMigration/migration/not-application-template.yaml new file mode 100644 index 000000000..9f61142c3 --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdTemplateSyncPolicyMigration/migration/not-application-template.yaml @@ -0,0 +1,2 @@ +apiVersion: argoproj.io/v1alpha1 +kind: NotApplication \ No newline at end of file diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdTemplateSyncPolicyMigration/validation/applicable-template.yaml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdTemplateSyncPolicyMigration/validation/applicable-template.yaml new file mode 100644 index 000000000..5028b2776 --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdTemplateSyncPolicyMigration/validation/applicable-template.yaml @@ -0,0 +1,27 @@ +piVersion: argoproj.io/v1alpha1 +kind: Application +metadata: + name: test + namespace: argocd + finalizers: + - resources-finalizer.argocd.argoproj.io +spec: + destination: + namespace: argocd + server: {{ .Values.spec.destination.server }} + project: default + source: + path: abc-deploy/src/main/resources/apps/test + repoURL: {{ .Values.spec.repo }} + targetRevision: {{ .Values.spec.targetRevision }} + {{ if .Values.spec.helm.valueFiles }} + helm: + valueFiles: + {{- range .Values.spec.helm.valueFiles }} + - {{ . }} + {{- end }} + {{ end }} + {{- with .Values.spec.syncPolicy }} + syncPolicy: + {{- toYaml . | nindent 4 }} + {{- end }} diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdTemplateSyncPolicyMigration/validation/inapplicable-template.yaml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdTemplateSyncPolicyMigration/validation/inapplicable-template.yaml new file mode 100644 index 000000000..dcda7a7cb --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdTemplateSyncPolicyMigration/validation/inapplicable-template.yaml @@ -0,0 +1,26 @@ +apiVersion: argoproj.io/v1alpha1 +kind: Application +metadata: + name: test + namespace: argocd + finalizers: + - resources-finalizer.argocd.argoproj.io +spec: + destination: + namespace: argocd + server: {{ .Values.spec.destination.server }} + project: default + source: + path: abc-deploy/src/main/resources/apps/test + repoURL: {{ .Values.spec.repo }} + targetRevision: {{ .Values.spec.targetRevision }} + {{ if .Values.spec.helm.valueFiles }} + helm: + valueFiles: + {{- range .Values.spec.helm.valueFiles }} + - {{ . }} + {{- end }} + {{ end }} + syncPolicy: + syncOptions: + - CreateNamespace=true \ No newline at end of file diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdTemplateSyncPolicyMigration/validation/indent-with-4-spaces-template.yaml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdTemplateSyncPolicyMigration/validation/indent-with-4-spaces-template.yaml new file mode 100644 index 000000000..76df7a4a2 --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdTemplateSyncPolicyMigration/validation/indent-with-4-spaces-template.yaml @@ -0,0 +1,27 @@ +apiVersion: argoproj.io/v1alpha1 +kind: Application +metadata: + name: test + namespace: argocd + finalizers: + - resources-finalizer.argocd.argoproj.io +spec: + destination: + namespace: argocd + server: {{ .Values.spec.destination.server }} + project: default + source: + path: abc-deploy/src/main/resources/apps/test + repoURL: {{ .Values.spec.repo }} + targetRevision: {{ .Values.spec.targetRevision }} + {{ if .Values.spec.helm.valueFiles }} + helm: + valueFiles: + {{- range .Values.spec.helm.valueFiles }} + - {{ . }} + {{- end }} + {{ end }} + {{- with .Values.spec.syncPolicy }} + syncPolicy: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdTemplateSyncPolicyMigration/validation/not-application-template.yaml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdTemplateSyncPolicyMigration/validation/not-application-template.yaml new file mode 100644 index 000000000..9f61142c3 --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdTemplateSyncPolicyMigration/validation/not-application-template.yaml @@ -0,0 +1,2 @@ +apiVersion: argoproj.io/v1alpha1 +kind: NotApplication \ No newline at end of file diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/migration/indent-with-4-spaces-values.yaml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/migration/indent-with-4-spaces-values.yaml new file mode 100644 index 000000000..297566a81 --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/migration/indent-with-4-spaces-values.yaml @@ -0,0 +1,12 @@ +spec: + destination: + server: https://kubernetes.default.svc + targetRevision: dev + repo: test.url + helm: + valueFiles: + - values.yaml + +global: + imagePullPolicy: Always + dockerRepo: ghcr.io/ \ No newline at end of file diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/migration/no-automated-values.yaml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/migration/no-automated-values.yaml new file mode 100644 index 000000000..79e25b5a9 --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/migration/no-automated-values.yaml @@ -0,0 +1,15 @@ +spec: + destination: + server: https://kubernetes.default.svc + targetRevision: dev + repo: test.url + helm: + valueFiles: + - values.yaml + syncPolicy: + syncOptions: + - CreateNamespace=true + - ApplyOutOfSyncOnly=true +global: + imagePullPolicy: Always + dockerRepo: ghcr.io/ \ No newline at end of file diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/migration/no-sync-options-values.yaml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/migration/no-sync-options-values.yaml new file mode 100644 index 000000000..b312c8381 --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/migration/no-sync-options-values.yaml @@ -0,0 +1,13 @@ +spec: + destination: + server: https://kubernetes.default.svc + targetRevision: dev + repo: test.url + helm: + valueFiles: + - values.yaml + syncPolicy: + automated: {} +global: + imagePullPolicy: Always + dockerRepo: ghcr.io/ \ No newline at end of file diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/migration/no-sync-policy-values.yaml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/migration/no-sync-policy-values.yaml new file mode 100644 index 000000000..d7d6f6604 --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/migration/no-sync-policy-values.yaml @@ -0,0 +1,12 @@ +spec: + destination: + server: https://kubernetes.default.svc + targetRevision: dev + repo: test.url + helm: + valueFiles: + - values.yaml + +global: + imagePullPolicy: Always + dockerRepo: ghcr.io/ \ No newline at end of file diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/migration/partial-sync-options-values.yaml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/migration/partial-sync-options-values.yaml new file mode 100644 index 000000000..33cd762e4 --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/migration/partial-sync-options-values.yaml @@ -0,0 +1,15 @@ +spec: + destination: + server: https://kubernetes.default.svc + targetRevision: dev + repo: test.url + helm: + valueFiles: + - values.yaml + syncPolicy: + syncOptions: + - CreateNamespace=true + automated: {} +global: + imagePullPolicy: Always + dockerRepo: ghcr.io/ \ No newline at end of file diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/migration/with-automated-prune-values.yaml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/migration/with-automated-prune-values.yaml new file mode 100644 index 000000000..fe266e52a --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/migration/with-automated-prune-values.yaml @@ -0,0 +1,17 @@ +spec: + destination: + server: https://kubernetes.default.svc + targetRevision: dev + repo: test.url + helm: + valueFiles: + - values.yaml + syncPolicy: + syncOptions: + - CreateNamespace=true + - ApplyOutOfSyncOnly=true + automated: + prune: true +global: + imagePullPolicy: Always + dockerRepo: ghcr.io/ \ No newline at end of file diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/migration/with-sync-options-replace-values.yaml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/migration/with-sync-options-replace-values.yaml new file mode 100644 index 000000000..0f6d6232c --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/migration/with-sync-options-replace-values.yaml @@ -0,0 +1,17 @@ +spec: + destination: + server: https://kubernetes.default.svc + targetRevision: dev + repo: test.url + helm: + valueFiles: + - values.yaml + syncPolicy: + syncOptions: + - CreateNamespace=true + - ApplyOutOfSyncOnly=true + - Replace=true + automated: {} +global: + imagePullPolicy: Always + dockerRepo: ghcr.io/ \ No newline at end of file diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/migration/with-sync-policy-values.yaml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/migration/with-sync-policy-values.yaml new file mode 100644 index 000000000..f4a7840a6 --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/migration/with-sync-policy-values.yaml @@ -0,0 +1,16 @@ +spec: + destination: + server: https://kubernetes.default.svc + targetRevision: dev + repo: test.url + helm: + valueFiles: + - values.yaml + syncPolicy: + syncOptions: + - CreateNamespace=true + - ApplyOutOfSyncOnly=true + automated: {} +global: + imagePullPolicy: Always + dockerRepo: ghcr.io/ \ No newline at end of file diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/validation/indent-with-4-spaces-values.yaml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/validation/indent-with-4-spaces-values.yaml new file mode 100644 index 000000000..1b15e9398 --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/validation/indent-with-4-spaces-values.yaml @@ -0,0 +1,17 @@ +spec: + destination: + server: https://kubernetes.default.svc + targetRevision: dev + repo: test.url + helm: + valueFiles: + - values.yaml + + syncPolicy: + syncOptions: + - CreateNamespace=true + - ApplyOutOfSyncOnly=true + automated: {} +global: + imagePullPolicy: Always + dockerRepo: ghcr.io/ diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/validation/no-automated-values.yaml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/validation/no-automated-values.yaml new file mode 100644 index 000000000..63c52a3bd --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/validation/no-automated-values.yaml @@ -0,0 +1,16 @@ +spec: + destination: + server: https://kubernetes.default.svc + targetRevision: dev + repo: test.url + helm: + valueFiles: + - values.yaml + syncPolicy: + syncOptions: + - CreateNamespace=true + - ApplyOutOfSyncOnly=true + automated: {} +global: + imagePullPolicy: Always + dockerRepo: ghcr.io/ diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/validation/no-sync-options-values.yaml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/validation/no-sync-options-values.yaml new file mode 100644 index 000000000..63c52a3bd --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/validation/no-sync-options-values.yaml @@ -0,0 +1,16 @@ +spec: + destination: + server: https://kubernetes.default.svc + targetRevision: dev + repo: test.url + helm: + valueFiles: + - values.yaml + syncPolicy: + syncOptions: + - CreateNamespace=true + - ApplyOutOfSyncOnly=true + automated: {} +global: + imagePullPolicy: Always + dockerRepo: ghcr.io/ diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/validation/no-sync-policy-values.yaml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/validation/no-sync-policy-values.yaml new file mode 100644 index 000000000..707420960 --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/validation/no-sync-policy-values.yaml @@ -0,0 +1,17 @@ +spec: + destination: + server: https://kubernetes.default.svc + targetRevision: dev + repo: test.url + helm: + valueFiles: + - values.yaml + + syncPolicy: + syncOptions: + - CreateNamespace=true + - ApplyOutOfSyncOnly=true + automated: {} +global: + imagePullPolicy: Always + dockerRepo: ghcr.io/ diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/validation/partial-sync-options-values.yaml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/validation/partial-sync-options-values.yaml new file mode 100644 index 000000000..63c52a3bd --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/validation/partial-sync-options-values.yaml @@ -0,0 +1,16 @@ +spec: + destination: + server: https://kubernetes.default.svc + targetRevision: dev + repo: test.url + helm: + valueFiles: + - values.yaml + syncPolicy: + syncOptions: + - CreateNamespace=true + - ApplyOutOfSyncOnly=true + automated: {} +global: + imagePullPolicy: Always + dockerRepo: ghcr.io/ diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/validation/with-automated-prune-values.yaml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/validation/with-automated-prune-values.yaml new file mode 100644 index 000000000..fe266e52a --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/validation/with-automated-prune-values.yaml @@ -0,0 +1,17 @@ +spec: + destination: + server: https://kubernetes.default.svc + targetRevision: dev + repo: test.url + helm: + valueFiles: + - values.yaml + syncPolicy: + syncOptions: + - CreateNamespace=true + - ApplyOutOfSyncOnly=true + automated: + prune: true +global: + imagePullPolicy: Always + dockerRepo: ghcr.io/ \ No newline at end of file diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/validation/with-sync-options-replace-values.yaml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/validation/with-sync-options-replace-values.yaml new file mode 100644 index 000000000..0f6d6232c --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/validation/with-sync-options-replace-values.yaml @@ -0,0 +1,17 @@ +spec: + destination: + server: https://kubernetes.default.svc + targetRevision: dev + repo: test.url + helm: + valueFiles: + - values.yaml + syncPolicy: + syncOptions: + - CreateNamespace=true + - ApplyOutOfSyncOnly=true + - Replace=true + automated: {} +global: + imagePullPolicy: Always + dockerRepo: ghcr.io/ \ No newline at end of file diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/validation/with-sync-policy-values.yaml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/validation/with-sync-policy-values.yaml new file mode 100644 index 000000000..f4a7840a6 --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_9_0/ArgocdValueFileSyncPolicyMigration/validation/with-sync-policy-values.yaml @@ -0,0 +1,16 @@ +spec: + destination: + server: https://kubernetes.default.svc + targetRevision: dev + repo: test.url + helm: + valueFiles: + - values.yaml + syncPolicy: + syncOptions: + - CreateNamespace=true + - ApplyOutOfSyncOnly=true + automated: {} +global: + imagePullPolicy: Always + dockerRepo: ghcr.io/ \ No newline at end of file