Check the application.yaml for errors
This commit is contained in:
parent
c754fa74d1
commit
d7ad34bb83
9 changed files with 156 additions and 2 deletions
|
@ -2,4 +2,6 @@ package org.domaindrivenarchitecture.provs.server.domain.k3s
|
||||||
|
|
||||||
interface ApplicationFileRepository {
|
interface ApplicationFileRepository {
|
||||||
fun assertExists(applicationFileName: ApplicationFileName?)
|
fun assertExists(applicationFileName: ApplicationFileName?)
|
||||||
|
fun assertC4kSpecError(applicationFileName: ApplicationFileName?)
|
||||||
|
fun assertC4kJavaException(applicationFileName: ApplicationFileName?)
|
||||||
}
|
}
|
|
@ -15,6 +15,8 @@ fun Prov.provisionK3sCommand(cli: K3sCliCommand) = task {
|
||||||
if (cli.onlyModules == null ) {
|
if (cli.onlyModules == null ) {
|
||||||
val k3sConfig: K3sConfig = getK3sConfig(cli.configFileName)
|
val k3sConfig: K3sConfig = getK3sConfig(cli.configFileName)
|
||||||
DefaultApplicationFileRepository().assertExists(cli.applicationFileName)
|
DefaultApplicationFileRepository().assertExists(cli.applicationFileName)
|
||||||
|
DefaultApplicationFileRepository().assertC4kSpecError(cli.applicationFileName)
|
||||||
|
DefaultApplicationFileRepository().assertC4kJavaException(cli.applicationFileName)
|
||||||
DefaultConfigFileRepository().assertExists(cli.configFileName)
|
DefaultConfigFileRepository().assertExists(cli.configFileName)
|
||||||
|
|
||||||
val k3sConfigReprovision = k3sConfig.copy(reprovision = cli.reprovision || k3sConfig.reprovision)
|
val k3sConfigReprovision = k3sConfig.copy(reprovision = cli.reprovision || k3sConfig.reprovision)
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.domaindrivenarchitecture.provs.server.infrastructure
|
||||||
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.checkLocalFile
|
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.checkLocalFile
|
||||||
import org.domaindrivenarchitecture.provs.server.domain.k3s.ApplicationFileName
|
import org.domaindrivenarchitecture.provs.server.domain.k3s.ApplicationFileName
|
||||||
import org.domaindrivenarchitecture.provs.server.domain.k3s.ApplicationFileRepository
|
import org.domaindrivenarchitecture.provs.server.domain.k3s.ApplicationFileRepository
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
class DefaultApplicationFileRepository : ApplicationFileRepository {
|
class DefaultApplicationFileRepository : ApplicationFileRepository {
|
||||||
|
|
||||||
|
@ -11,4 +12,30 @@ class DefaultApplicationFileRepository : ApplicationFileRepository {
|
||||||
throw RuntimeException("Application file ${applicationFileName.fileName} not found. Please check if path is correct.")
|
throw RuntimeException("Application file ${applicationFileName.fileName} not found. Please check if path is correct.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun assertC4kSpecError(applicationFileName: ApplicationFileName?) {
|
||||||
|
if (applicationFileName != null) {
|
||||||
|
val fileContent = File(applicationFileName.fullqualified()).readText()
|
||||||
|
|
||||||
|
|
||||||
|
if (fileContent.contains("Spec.failed".toRegex()) && fileContent.contains("Detected.*[0-9].*error+".toRegex())) {
|
||||||
|
throw RuntimeException("Application file ${applicationFileName.fileName} contains spec errors. Please check your configuration file.")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun assertC4kJavaException(applicationFileName: ApplicationFileName?) {
|
||||||
|
if (applicationFileName != null) {
|
||||||
|
val fileContent = File(applicationFileName.fullqualified()).readText()
|
||||||
|
|
||||||
|
|
||||||
|
if (fileContent.contains("Exception.in.thread".toRegex())) {
|
||||||
|
throw RuntimeException("Application file ${applicationFileName.fileName} contains java exception. Please check the c4k code for errors.")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ internal class DefaultConfigFileRepositoryKtTest {
|
||||||
@Test
|
@Test
|
||||||
fun assertExistsPasses() {
|
fun assertExistsPasses() {
|
||||||
// given
|
// given
|
||||||
val validFileName = "src/test/resources/existing_file"
|
val validFileName = "src/test/resources/existing-file"
|
||||||
|
|
||||||
// when
|
// when
|
||||||
val validFile = ApplicationFileName(File(validFileName).path)
|
val validFile = ApplicationFileName(File(validFileName).path)
|
||||||
|
|
|
@ -2,6 +2,7 @@ package org.domaindrivenarchitecture.provs.server.infrastructure
|
||||||
|
|
||||||
import org.domaindrivenarchitecture.provs.configuration.domain.ConfigFileName
|
import org.domaindrivenarchitecture.provs.configuration.domain.ConfigFileName
|
||||||
import org.domaindrivenarchitecture.provs.configuration.infrastructure.DefaultConfigFileRepository
|
import org.domaindrivenarchitecture.provs.configuration.infrastructure.DefaultConfigFileRepository
|
||||||
|
import org.domaindrivenarchitecture.provs.server.domain.k3s.ApplicationFileName
|
||||||
import org.junit.jupiter.api.Assertions.assertEquals
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.jupiter.api.assertThrows
|
import org.junit.jupiter.api.assertThrows
|
||||||
|
@ -28,7 +29,7 @@ internal class DefaultApplicationFileRepositoryKtTest {
|
||||||
@Test
|
@Test
|
||||||
fun assertExistsPasses() {
|
fun assertExistsPasses() {
|
||||||
// given
|
// given
|
||||||
val validFileName = "src/test/resources/existing_file"
|
val validFileName = "src/test/resources/existing-file"
|
||||||
|
|
||||||
// when
|
// when
|
||||||
val validFile = ConfigFileName(File(validFileName).path)
|
val validFile = ConfigFileName(File(validFileName).path)
|
||||||
|
@ -38,4 +39,70 @@ internal class DefaultApplicationFileRepositoryKtTest {
|
||||||
// then
|
// then
|
||||||
// no exception is thrown
|
// no exception is thrown
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun assertC4kSpecErrorThrows() {
|
||||||
|
// given
|
||||||
|
val applicationFileName = "src/test/resources/failed-spec.yaml"
|
||||||
|
|
||||||
|
// when
|
||||||
|
val failedFile = ApplicationFileName(File(applicationFileName).path)
|
||||||
|
val repo = DefaultApplicationFileRepository()
|
||||||
|
|
||||||
|
// then
|
||||||
|
val exception = assertThrows<RuntimeException>(
|
||||||
|
"Should throw because of bad spec."
|
||||||
|
) { repo.assertC4kSpecError(failedFile) }
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
"Application file src/test/resources/failed-spec.yaml contains spec errors. Please check your configuration file.",
|
||||||
|
exception.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun assertC4kSpecErrorPasses() {
|
||||||
|
// given
|
||||||
|
val validFileName = "src/test/resources/valid.yaml"
|
||||||
|
|
||||||
|
// when
|
||||||
|
val validFile = ApplicationFileName(File(validFileName).path)
|
||||||
|
val repo = DefaultApplicationFileRepository()
|
||||||
|
repo.assertC4kSpecError(validFile)
|
||||||
|
|
||||||
|
// then
|
||||||
|
// no exception is thrown
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun assertC4kJavaExceptionThrows() {
|
||||||
|
// given
|
||||||
|
val applicationFileName = "src/test/resources/java-exception.yaml"
|
||||||
|
|
||||||
|
// when
|
||||||
|
val failedFile = ApplicationFileName(File(applicationFileName).path)
|
||||||
|
val repo = DefaultApplicationFileRepository()
|
||||||
|
|
||||||
|
// then
|
||||||
|
val exception = assertThrows<RuntimeException>(
|
||||||
|
"Should throw because of java exception."
|
||||||
|
) { repo.assertC4kJavaException(failedFile) }
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
"Application file src/test/resources/java-exception.yaml contains java exception. Please check the c4k code for errors.",
|
||||||
|
exception.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun assertC4kJavaExceptionPasses() {
|
||||||
|
// given
|
||||||
|
val validFileName = "src/test/resources/valid.yaml"
|
||||||
|
|
||||||
|
// when
|
||||||
|
val validFile = ApplicationFileName(File(validFileName).path)
|
||||||
|
val repo = DefaultApplicationFileRepository()
|
||||||
|
repo.assertC4kJavaException(validFile)
|
||||||
|
|
||||||
|
// then
|
||||||
|
// no exception is thrown
|
||||||
|
}
|
||||||
}
|
}
|
13
src/test/resources/failed-spec.yaml
Normal file
13
src/test/resources/failed-spec.yaml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
-- Spec failed --------------------
|
||||||
|
|
||||||
|
{:jvb-auth-password 1234,
|
||||||
|
^^^^
|
||||||
|
:jicofo-auth-password ...,
|
||||||
|
:jicofo-component-secret ...}
|
||||||
|
|
||||||
|
should satisfy
|
||||||
|
|
||||||
|
bash-env-string?
|
||||||
|
|
||||||
|
-------------------------
|
||||||
|
Detected 1 error
|
34
src/test/resources/java-exception.yaml
Normal file
34
src/test/resources/java-exception.yaml
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
Exception in thread "main" java.lang.IllegalArgumentException: Cannot open <nil> as a Reader.
|
||||||
|
at clojure.java.io$fn__11641.invokeStatic(io.clj:288)
|
||||||
|
at clojure.java.io$fn__11641.invoke(io.clj:288)
|
||||||
|
at clojure.java.io$fn__11530$G__11519__11537.invoke(io.clj:69)
|
||||||
|
at clojure.java.io$reader.invokeStatic(io.clj:102)
|
||||||
|
at clojure.java.io$reader.doInvoke(io.clj:86)
|
||||||
|
at clojure.lang.RestFn.invoke(RestFn.java:410)
|
||||||
|
at clojure.lang.AFn.applyToHelper(AFn.java:154)
|
||||||
|
at clojure.lang.RestFn.applyTo(RestFn.java:132)
|
||||||
|
at clojure.core$apply.invokeStatic(core.clj:669)
|
||||||
|
at clojure.core$slurp.invokeStatic(core.clj:7009)
|
||||||
|
at clojure.core$slurp.doInvoke(core.clj:7009)
|
||||||
|
at clojure.lang.RestFn.invoke(RestFn.java:410)
|
||||||
|
at dda.c4k_common.yaml$fn__577.invokeStatic(yaml.clj:39)
|
||||||
|
at dda.c4k_common.yaml$fn__577.invoke(yaml.clj:38)
|
||||||
|
at clojure.lang.MultiFn.invoke(MultiFn.java:229)
|
||||||
|
at dda.c4k_common.yaml$load_as_edn.invokeStatic(yaml.clj:42)
|
||||||
|
at dda.c4k_common.yaml$load_as_edn.invoke(yaml.clj:41)
|
||||||
|
at dda.c4k_website.website$replace_common_data.invokeStatic(website.cljc:122)
|
||||||
|
at dda.c4k_website.website$replace_common_data.invoke(website.cljc:117)
|
||||||
|
at dda.c4k_website.website$generate_hashfile_volume.invokeStatic(website.cljc:198)
|
||||||
|
at dda.c4k_website.website$generate_hashfile_volume.invoke(website.cljc:196)
|
||||||
|
at dda.c4k_website.core$generate_configs.invokeStatic(core.cljc:60)
|
||||||
|
at dda.c4k_website.core$generate_configs.invoke(core.cljc:45)
|
||||||
|
at dda.c4k_website.core$k8s_objects.invokeStatic(core.cljc:74)
|
||||||
|
at dda.c4k_website.core$k8s_objects.invoke(core.cljc:66)
|
||||||
|
at dda.c4k_common.common$generate_common.invokeStatic(common.cljc:68)
|
||||||
|
at dda.c4k_common.common$generate_common.invoke(common.cljc:60)
|
||||||
|
at dda.c4k_common.uberjar$main_common.invokeStatic(uberjar.clj:50)
|
||||||
|
at dda.c4k_common.uberjar$main_common.invoke(uberjar.clj:31)
|
||||||
|
at dda.c4k_website.uberjar$_main.invokeStatic(uberjar.clj:9)
|
||||||
|
at dda.c4k_website.uberjar$_main.doInvoke(uberjar.clj:8)
|
||||||
|
at clojure.lang.RestFn.applyTo(RestFn.java:137)
|
||||||
|
at dda.c4k_website.uberjar.main(Unknown Source)
|
9
src/test/resources/valid.yaml
Normal file
9
src/test/resources/valid.yaml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: config
|
||||||
|
type: Opaque
|
||||||
|
data:
|
||||||
|
JVB_AUTH_PASSWORD: BLA
|
||||||
|
JICOFO_AUTH_PASSWORD: BLA
|
||||||
|
JICOFO_COMPONENT_SECRET: BLA
|
Loading…
Reference in a new issue