Skip to content

Commit 11a8c16

Browse files
committed
decouple common feature config from the feature list
1 parent e5fee1f commit 11a8c16

File tree

6 files changed

+16
-14
lines changed

6 files changed

+16
-14
lines changed

src/main/groovy/com/cloudogu/gitops/Feature.groovy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,14 @@ abstract class Feature {
8585
protected void validate() { }
8686

8787
/**
88-
* Hook for preConfigValidation. Optional.
88+
* Hook for preConfigInit. Optional.
8989
* Feature should throw RuntimeException to stop immediately.
9090
*/
91-
void preConfigValidation(Config configToSet) { }
91+
void preConfigInit(Config configToSet) { }
9292

9393
/**
94-
* Hook for postConfigValidation. Optional.
94+
* Hook for postConfigInit. Optional.
9595
* Feature should throw RuntimeException to stop immediately.
9696
*/
97-
void postConfigValidation(Config configToSet) { }
97+
void postConfigInit(Config configToSet) { }
9898
}

src/main/groovy/com/cloudogu/gitops/cli/GitopsPlaygroundCli.groovy

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import picocli.CommandLine
2424

2525
import static com.cloudogu.gitops.config.ConfigConstants.APP_NAME
2626
import static com.cloudogu.gitops.utils.MapUtils.deepMerge
27+
28+
2729
/**
2830
* Provides the entrypoint to the application as well as all config parameters.
2931
* When changing parameters, make sure to update the Config for the config file as well
@@ -37,7 +39,7 @@ class GitopsPlaygroundCli {
3739
ApplicationConfigurator applicationConfigurator
3840

3941
GitopsPlaygroundCli(K8sClient k8sClient = new K8sClient(new CommandExecutor(), new FileSystemUtils(), null),
40-
ApplicationConfigurator applicationConfigurator = new ApplicationConfigurator(null)) {
42+
ApplicationConfigurator applicationConfigurator = new ApplicationConfigurator()) {
4143
this.k8sClient = k8sClient
4244
this.applicationConfigurator = applicationConfigurator
4345
}
@@ -65,6 +67,8 @@ class GitopsPlaygroundCli {
6567
Application app = context.getBean(Application)
6668

6769
def config = readConfigs(args)
70+
runHook(app, 'preConfigInit', config)
71+
6872
if (config.application.outputConfigFile) {
6973
println(config.toYaml(false))
7074
return ReturnCode.SUCCESS
@@ -74,8 +78,9 @@ class GitopsPlaygroundCli {
7478
// eg a simple docker run .. --help should not fail with connection refused
7579
config = applicationConfigurator.initConfig(config)
7680
log.debug("Actual config: ${config.toYaml(true)}")
81+
runHook(app, 'postConfigInit', config)
7782

78-
runHook(app, 'postConfigValidation', config)
83+
context = createApplicationContext()
7984
register(config, context)
8085

8186
if (config.application.destroy) {
@@ -91,6 +96,7 @@ class GitopsPlaygroundCli {
9196
if (!confirm("Applying gitops playground to kubernetes cluster '${k8sClient.currentContext}'.", config)) {
9297
return ReturnCode.NOT_CONFIRMED
9398
}
99+
app = context.getBean(Application)
94100
app.start()
95101

96102
printWelcomeScreen()
@@ -211,9 +217,6 @@ class GitopsPlaygroundCli {
211217
log.debug("Writing CLI params into config")
212218
Config mergedConfig = Config.fromMap(mergedConfigs)
213219
new CommandLine(mergedConfig).parseArgs(args)
214-
215-
def app = ApplicationContext.run().getBean(Application)
216-
runHook(app, 'preConfigValidation', mergedConfig)
217220

218221
return mergedConfig
219222
}

src/main/groovy/com/cloudogu/gitops/config/CommonFeatureConfig.groovy

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import groovy.util.logging.Slf4j
66
@Slf4j
77
class CommonFeatureConfig extends Feature {
88
@Override
9-
void preConfigValidation(Config configToSet) {
10-
log.debug("Common preConfigValidation")
9+
void preConfigInit(Config configToSet) {
1110
validateScmmAndJenkinsAreBothSet(configToSet)
1211
validateMirrorReposHelmChartFolderSet(configToSet)
1312
}

src/main/groovy/com/cloudogu/gitops/features/Content.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class Content extends Feature {
7979
}
8080

8181
@Override
82-
void preConfigValidation(Config configToSet) {
82+
void preConfigInit(Config configToSet) {
8383
config.content.repos.each { repo ->
8484

8585
if (!repo.url) {

src/main/groovy/com/cloudogu/gitops/features/argocd/ArgoCD.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class ArgoCD extends Feature {
7777
}
7878

7979
@Override
80-
void postConfigValidation(Config configToSet) {
80+
void postConfigInit(Config configToSet) {
8181
// Exit early if not in operator mode or if env list is empty
8282
if (!configToSet.features.argocd.operator || !configToSet.features.argocd.env) {
8383
log.debug("Skipping features.argocd.env validation: operator mode is disabled or env list is empty.")

src/test/groovy/com/cloudogu/gitops/cli/GitopsPlaygroundCliMainScriptedTest.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class GitopsPlaygroundCliMainScriptedTest {
7474
.enableAnnotationInfo()
7575
.scan().withCloseable { scanResult ->
7676
scanResult.getAllClasses().each { ClassInfo classInfo ->
77-
if (classInfo.name.endsWith("Test") || classInfo.isAbstract()) {
77+
if (classInfo.name.endsWith("Test") || classInfo.isAbstract() || !classInfo.hasAnnotation(jakarta.inject.Singleton)) {
7878
return
7979
}
8080

0 commit comments

Comments
 (0)