Skip to content

Commit

Permalink
Merge branch 'release/1.60.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Sprey committed Nov 30, 2022
2 parents ae98e9c + 4b61347 commit 6714f6d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 25 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [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
Expand Down
2 changes: 1 addition & 1 deletion 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.0</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
47 changes: 29 additions & 18 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, config = [:], 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 @@ -565,4 +577,3 @@ data:
}
}
}

15 changes: 9 additions & 6 deletions test/com/cloudogu/ces/cesbuildlib/K3dTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,16 @@ 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())
assertThat(scriptMock.allActualArgs[2].trim()).isEqualTo("sudo KUBECONFIG=${workspaceEnvDir}/.k3d/.kube/config kubectl create configmap k8s-ces-setup-json --from-file=setup.json".trim())
assertThat(scriptMock.allActualArgs[3].trim()).isEqualTo("curl -s https://raw.githubusercontent.com/cloudogu/k8s-ces-setup/${tag}/k8s/k8s-ces-setup.yaml".trim())
assertThat(scriptMock.allActualArgs[4].trim()).isEqualTo("sudo KUBECONFIG=${workspaceEnvDir}/.k3d/.kube/config kubectl apply -f setup.yaml".trim())
assertThat(scriptMock.allActualArgs[5].trim()).isEqualTo("sleep 1s")
assertThat(scriptMock.allActualArgs[5].trim()).isEqualTo("sleep 5s")
assertThat(scriptMock.allActualArgs[6].trim()).isEqualTo("sudo KUBECONFIG=${workspaceEnvDir}/.k3d/.kube/config kubectl rollout status deployment/k8s-dogu-operator-controller-manager".trim())

assertThat(scriptMock.writeFileParams.get(0)).isNotNull()
Expand All @@ -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,8 +212,7 @@ 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.actualShStringArgs[0].trim()).isEqualTo("sleep 5s")
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 6714f6d

Please sign in to comment.