-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from boozallen/52-migrate-downstream-helm-repo…
…sitory-url #52 Create Baton migration for Helm Chart repository URLs and old mo…
- Loading branch information
Showing
15 changed files
with
478 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...de/src/main/java/com/boozallen/aissemble/upgrade/migration/AbstractHelmNameMigration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.boozallen.aissemble.upgrade.migration; | ||
|
||
/*- | ||
* #%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.util.FileUtils; | ||
import org.apache.commons.collections4.CollectionUtils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.technologybrewery.baton.BatonException; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import static com.boozallen.aissemble.upgrade.util.FileUtils.getRegExCaptureGroups; | ||
|
||
/** | ||
* Baton migration used to migrate the Helm Chart names and/or Helm module names in the Chart.yaml and values.yaml files within a project's deploy folder | ||
*/ | ||
public abstract class AbstractHelmNameMigration extends AbstractAissembleMigration{ | ||
private static final Logger logger = LoggerFactory.getLogger(AbstractHelmNameMigration.class); | ||
|
||
@Override | ||
protected boolean shouldExecuteOnFile(File file) { | ||
boolean shouldExecute = false; | ||
try { | ||
List<String> namesToUpdate = getRegExCaptureGroups(getReplacementRegex(file), file); | ||
shouldExecute = CollectionUtils.isNotEmpty(namesToUpdate); | ||
} catch (IOException e){ | ||
throw new BatonException("Unable to determine if Helm chart migration must be executed", e); | ||
} | ||
return shouldExecute; | ||
} | ||
|
||
@Override | ||
protected boolean performMigration(File file) { | ||
boolean performedSuccessfully = false; | ||
try { | ||
performedSuccessfully = FileUtils.replaceInFile( | ||
file, | ||
getReplacementRegex(file), | ||
getReplacementText(file) | ||
); | ||
} catch (Exception e) { | ||
logger.error("Unable to perform Helm chart migration due to exception", e); | ||
} | ||
return performedSuccessfully; | ||
} | ||
|
||
public abstract String getReplacementRegex(File file); | ||
public abstract String getReplacementText(File file); | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
.../main/java/com/boozallen/aissemble/upgrade/migration/AbstractHelmRepositoryMigration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.boozallen.aissemble.upgrade.migration; | ||
|
||
/*- | ||
* #%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.util.FileUtils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import java.io.File; | ||
|
||
/** | ||
* Baton migration used to migrate the Helm Chart repository URL in the Chart.yaml within a project's deploy folder. | ||
* Migration is triggered by setting the oldHelmRepositoryUrl system property. | ||
*/ | ||
public abstract class AbstractHelmRepositoryMigration extends AbstractAissembleMigration{ | ||
public static final Logger logger = LoggerFactory.getLogger(AbstractHelmRepositoryMigration.class); | ||
private static final String OLD_HELM_REPO_PROPERTY = "oldHelmRepositoryUrl"; | ||
|
||
protected String getOldHelmRepositoryUrl(){ | ||
String oldHelmRepositoryUrl = System.getProperty(OLD_HELM_REPO_PROPERTY); | ||
if (oldHelmRepositoryUrl!= null){ | ||
return oldHelmRepositoryUrl; | ||
} else { | ||
logger.info("oldHelmRepositoryUrl system property not set. Skipping helm chart repository URL migration."); | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* Function that checks if user has provided system property containing old Helm repository URL | ||
* If yes, then Helm Charts repository URL migration will be run. | ||
* Otherwise, migration is skipped. | ||
*/ | ||
@Override | ||
protected boolean shouldExecuteOnFile(File file) { | ||
boolean shouldExecute = false; | ||
if (getOldHelmRepositoryUrl() != null){ | ||
shouldExecute = true; | ||
} | ||
return shouldExecute; | ||
} | ||
|
||
@Override | ||
protected boolean performMigration(File file) { | ||
boolean performedSuccessfully = false; | ||
try { | ||
performedSuccessfully = FileUtils.replaceInFile( | ||
file, | ||
getReplacementRegex(), | ||
getReplacementText() | ||
); | ||
} catch (Exception e) { | ||
logger.error("Unable to perform helm chart repository URL migration due to exception", e); | ||
} | ||
return performedSuccessfully; | ||
} | ||
|
||
public abstract String getReplacementRegex(); | ||
public abstract String getReplacementText(); | ||
} |
36 changes: 36 additions & 0 deletions
36
...main/java/com/boozallen/aissemble/upgrade/migration/v1_7_0/HelmChartsModuleMigration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.boozallen.aissemble.upgrade.migration.v1_7_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.AbstractHelmNameMigration; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* Baton migration used to migrate the Chart.yaml and values*.yaml files within a project's deploy folder | ||
* to use new Helm module names | ||
* Example: extensions-helm-kafka to aissemble-kafka-chart | ||
*/ | ||
public class HelmChartsModuleMigration extends AbstractHelmNameMigration { | ||
private static final String moduleNameReplaceRegex = "extensions-helm-([^\\/\\n:]+)"; | ||
private static final String AISSEMBLE_PREFIX = "aissemble-"; | ||
private static final String CHART_POSTFIX = "-chart"; | ||
|
||
@Override | ||
public String getReplacementRegex(File file) { | ||
return moduleNameReplaceRegex; | ||
} | ||
|
||
@Override | ||
public String getReplacementText(File file) { | ||
return AISSEMBLE_PREFIX.concat(FIRST_REGEX_GROUPING + CHART_POSTFIX); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.