Skip to content

Commit

Permalink
Merge branch 'release/1.60.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
jelemux committed Dec 1, 2022
2 parents ae98e9c + d5e976c commit 4370066
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 38 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.60.1](https://github.com/cloudogu/ces-build-lib/releases/tag/1.60.1) - 2022-12-01
### Fixed
- Incorrect usage of parameters makes currently used feature of installing and performing a setup unusable.

## [1.60.0](https://github.com/cloudogu/ces-build-lib/releases/tag/1.60.0) - 2022-11-30
### Changed
- Split method to perform an update into a configuration and installation subpart, which can be called independently. #90

## [1.59.0](https://github.com/cloudogu/ces-build-lib/releases/tag/1.59.0) - 2022-11-28
### Added
- Function `collectAndArchiveLogs` to collect dogu and resource information to help debugging k3s Jenkins buils. #89
Expand Down
3 changes: 1 addition & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>com.cloudogu.ces</groupId>
<artifactId>ces-build-lib</artifactId>
<name>ces-build-lib</name>
<version>1.59.0</version>
<version>1.60.1</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -59,7 +59,6 @@

<build>
<sourceDirectory>src</sourceDirectory>
<!--<scriptSourceDirectory>vars</scriptSourceDirectory>-->
<testSourceDirectory>test</testSourceDirectory>
<resources>
<resource>
Expand Down
83 changes: 51 additions & 32 deletions src/com/cloudogu/ces/cesbuildlib/K3d.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -173,26 +173,24 @@ class K3d {
return script.sh(script: "sudo KUBECONFIG=${k3dDir}/.kube/config kubectl ${command}", returnStdout: returnStdout)
}

/**
* Installs the setup to the cluster. Creates an example setup.json with plantuml as dogu and executes the setup.
* After that the method will wait until the dogu-operator is ready.
* @param tag Tag of the setup e. g. "v0.6.0"
* @param timout Timeout in seconds for the setup process e. g. 300
* @param interval Interval in seconds for querying the actual state of the setup e. g. 2
*/
void setup(String tag, config = [:], Integer timout = 300, Integer interval = 5) {
void assignExternalIP() {
this.externalIP = this.sh.returnStdOut("curl -H \"Metadata-Flavor: Google\" http://169.254.169.254/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip")
}

void configureSetup(String tag, config = [:]) {
script.echo "configuring setup..."
// Config
script.echo "Installing setup..."
kubectl("apply -f https://raw.githubusercontent.com/cloudogu/k8s-ces-setup/${tag}/k8s/k8s-ces-setup-config.yaml")

// Merge default config with the one passed as parameter
config = defaultSetupConfig << config
writeSetupJson(config)

kubectl('create configmap k8s-ces-setup-json --from-file=setup.json')
}

void installAndTriggerSetup(String tag, Integer timout = 300, Integer interval = 5) {
script.echo "Installing setup..."
String setup = this.sh.returnStdOut("curl -s https://raw.githubusercontent.com/cloudogu/k8s-ces-setup/${tag}/k8s/k8s-ces-setup.yaml")
setup = setup.replace("{{ .Namespace }}", "default")
script.writeFile file: 'setup.yaml', text: setup
Expand All @@ -203,15 +201,29 @@ class K3d {
}

/**
* Installs a given dogu. Before applying the dogu.yaml to the cluster the method creates a custom dogu
* descriptor with an .local ip. This is required for the crane library in the dogu operator. The .local forces it
* to use http. Afterwards the .local will be patched out from the dogu resources so that kubelet has no problem to
* pull the image-
*
* @param dogu Name of the dogu e. g. "nginx-ingress"
* @param image Name of the image e. g. "k3d-citest-d9753c5632bc:1234/k8s/nginx-ingress"
* @param doguYaml Name of the custom resources
* Installs the setup to the cluster. Creates an example setup.json with plantuml as dogu and executes the setup.
* After that the method will wait until the dogu-operator is ready.
* @param tag Tag of the setup e. g. "v0.6.0"
* @param timout Timeout in seconds for the setup process e. g. 300
* @param interval Interval in seconds for querying the actual state of the setup e. g. 2
*/
void setup(String tag, config = [:], Integer timout = 300, Integer interval = 5) {
assignExternalIP()
configureSetup(tag, config)
installAndTriggerSetup(tag, timout, interval)
}


/**
* Installs a given dogu. Before applying the dogu.yaml to the cluster the method creates a custom dogu
* descriptor with an .local ip. This is required for the crane library in the dogu operator. The .local forces it
* to use http. Afterwards the .local will be patched out from the dogu resources so that kubelet has no problem to
* pull the image-
*
* @param dogu Name of the dogu e. g. "nginx-ingress"
* @param image Name of the image e. g. "k3d-citest-d9753c5632bc:1234/k8s/nginx-ingress"
* @param doguYaml Name of the custom resources
*/
void installDogu(String dogu, String image, String doguYaml) {
Docker docker = new Docker(script)
String[] IpPort = getRegistryIpAndPort(docker)
Expand Down Expand Up @@ -536,15 +548,19 @@ data:
*/
void collectDoguDescriptions() {
def allDoguNames = kubectl("get dogu --ignore-not-found -o name || true", true)
def doguNames = allDoguNames.split("\n")
for (def doguName : doguNames) {
def doguFileName = doguName.split("/")[1]
def doguDescribe = kubectl("describe ${doguName} || true", true)
script.dir("${K3D_LOG_FILENAME}") {
script.dir('dogus') {
script.writeFile(file: "${doguFileName}.txt".toString(), text: doguDescribe)
try {
def doguNames = allDoguNames.split("\n")
for (def doguName : doguNames) {
def doguFileName = doguName.split("/")[1]
def doguDescribe = kubectl("describe ${doguName} || true", true)
script.dir("${K3D_LOG_FILENAME}") {
script.dir('dogus') {
script.writeFile(file: "${doguFileName}.txt".toString(), text: doguDescribe)
}
}
}
} catch (Exception ignored) {
script.echo "Failed to collect dogu descriptions because of: \n${ignored.toString()}\nSkipping collection step."
}
}

Expand All @@ -553,16 +569,19 @@ data:
*/
void collectPodLogs() {
def allPodNames = kubectl("get pods -o name || true", true)
def podNames = allPodNames.split("\n")
for (def podName : podNames) {
def podFileName = podName.split("/")[1]
def podLogs = kubectl("logs ${podName} || true", true)
script.dir("${K3D_LOG_FILENAME}") {
script.dir('pods') {
script.writeFile(file: "${podFileName}.log".toString(), text: podLogs)
try {
def podNames = allPodNames.split("\n")
for (def podName : podNames) {
def podFileName = podName.split("/")[1]
def podLogs = kubectl("logs ${podName} || true", true)
script.dir("${K3D_LOG_FILENAME}") {
script.dir('pods') {
script.writeFile(file: "${podFileName}.log".toString(), text: podLogs)
}
}
}
} catch (Exception ignored) {
script.echo "Failed to collect pod logs because of: \n${ignored.toString()}\nSkipping collection step."
}
}
}

11 changes: 7 additions & 4 deletions test/com/cloudogu/ces/cesbuildlib/K3dTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,9 @@ class K3dTest extends GroovyTestCase {
sut.setup(tag, [:], 1, 1)

// then
assertThat(scriptMock.actualEcho.get(0)).isEqualTo("Installing setup...")
assertThat(scriptMock.actualEcho.get(1)).isEqualTo("Wait for dogu-operator to be ready...")
assertThat(scriptMock.actualEcho.get(0)).isEqualTo("configuring setup...")
assertThat(scriptMock.actualEcho.get(1)).isEqualTo("Installing setup...")
assertThat(scriptMock.actualEcho.get(2)).isEqualTo("Wait for dogu-operator to be ready...")

assertThat(scriptMock.allActualArgs[0].trim()).isEqualTo("curl -H \"Metadata-Flavor: Google\" http://169.254.169.254/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip")
assertThat(scriptMock.allActualArgs[1].trim()).isEqualTo("sudo KUBECONFIG=${workspaceEnvDir}/.k3d/.kube/config kubectl apply -f https://raw.githubusercontent.com/cloudogu/k8s-ces-setup/${tag}/k8s/k8s-ces-setup-config.yaml".trim())
Expand Down Expand Up @@ -198,7 +199,10 @@ class K3dTest extends GroovyTestCase {
}

// then
assertThat(scriptMock.actualEcho.get(0)).isEqualTo("Installing setup...")
assertThat(scriptMock.actualEcho.get(0)).isEqualTo("configuring setup...")
assertThat(scriptMock.actualEcho.get(1)).isEqualTo("Installing setup...")
assertThat(scriptMock.actualEcho.get(2)).isEqualTo("Wait for dogu-operator to be ready...")

assertThat(scriptMock.actualShMapArgs[0].trim()).isEqualTo("curl -H \"Metadata-Flavor: Google\" http://169.254.169.254/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip")
assertThat(scriptMock.actualShMapArgs[1].trim()).isEqualTo("sudo KUBECONFIG=${workspaceEnvDir}/.k3d/.kube/config kubectl apply -f https://raw.githubusercontent.com/cloudogu/k8s-ces-setup/${tag}/k8s/k8s-ces-setup-config.yaml".trim())
assertThat(scriptMock.writeFileParams.get(0)).isNotNull()
Expand All @@ -208,7 +212,6 @@ class K3dTest extends GroovyTestCase {
assertThat(setupYaml).isNotNull()
assertThat(setupYaml.contains("{{ .Namespace }}")).isFalse()
assertThat(scriptMock.actualShMapArgs[4].trim()).isEqualTo("sudo KUBECONFIG=${workspaceEnvDir}/.k3d/.kube/config kubectl apply -f setup.yaml".trim())
assertThat(scriptMock.actualEcho.get(1)).isEqualTo("Wait for dogu-operator to be ready...")
assertThat(scriptMock.actualShStringArgs[0].trim()).isEqualTo("sleep 1s")
assertThat(scriptMock.actualShMapArgs[5].trim()).isEqualTo("sudo KUBECONFIG=${workspaceEnvDir}/.k3d/.kube/config kubectl rollout status deployment/k8s-dogu-operator-controller-manager".trim())
}
Expand Down

0 comments on commit 4370066

Please sign in to comment.