Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from F8 to Dekorate #92

Merged
merged 1 commit into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
timeout 300s bash -c 'while [[ $(oc get pod -o json | jq ".items[] | select(.metadata.name | contains(\"build\")) | .status " | jq -rs "sort_by(.startTme) | last | .phase") == "Running" ]]; do sleep 20; done; echo ""'

# launch the tests without deploying the application
./mvnw -s .circleci/settings.xml verify -Dfabric8.skip=true -Popenshift,openshift-it
./mvnw -s .circleci/settings.xml verify -Popenshift,openshift-it -Dunmanaged-test=true

- run:
name: Cleanup s2i build
Expand All @@ -82,10 +82,10 @@ jobs:
echo "Cleaned up s2i build"

- run:
name: run tests against fmp build
name: run tests against Dekorate build
command: |
oc new-project fmp
.circleci/run_tests_with_fmp.sh -s .circleci/settings.xml
oc new-project dekorate
.circleci/run_tests_with_dekorate.sh -s .circleci/settings.xml
no_output_timeout: 3600

workflows:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ PROJECT_ABSOLUTE_DIR=$(dirname ${SCRIPT_ABSOLUTE_DIR})

pushd ${PROJECT_ABSOLUTE_DIR} > /dev/null

oc create -f .openshiftio/resource.configmap.yaml

./mvnw clean verify -Popenshift,openshift-it "$@"

popd > /dev/null
Expand Down
132 changes: 21 additions & 111 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,9 @@
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<arquillian.version>1.4.0.Final</arquillian.version>
<arquillian-cube.version>1.18.2</arquillian-cube.version>
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
<maven-failsafe-plugin.version>2.19.1</maven-failsafe-plugin.version>
<junit.version>4.13.2</junit.version>
<ubi.version>1.3</ubi.version>
<openshift-client.version>3.1.8</openshift-client.version>
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
<maven-failsafe-plugin.version>2.22.2</maven-failsafe-plugin.version>
<spring-boot.version>2.4.9</spring-boot.version>
<fabric8.generator.from>
registry.access.redhat.com/ubi8/openjdk-8:${ubi.version}
</fabric8.generator.from>
</properties>
<licenses>
<license>
Expand Down Expand Up @@ -73,62 +65,34 @@
<url>https://maven.repository.redhat.com/earlyaccess/all/</url>
</pluginRepository>
</pluginRepositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>${arquillian.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.arquillian.cube</groupId>
<artifactId>arquillian-cube-bom</artifactId>
<version>${arquillian-cube.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>openshift-client</artifactId>
<version>${openshift-client.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-kubernetes-fabric8-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-standalone</artifactId>
<scope>test</scope>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.arquillian.cube</groupId>
<artifactId>arquillian-cube-openshift</artifactId>
<scope>test</scope>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-kubernetes-fabric8-config</artifactId>
<!-- We need to exclude Kubernetes Client because it's in conflict with Dekorate dependency -->
<exclusions>
<exclusion>
<groupId>io.undertow</groupId>
<artifactId>undertow-core</artifactId>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>openshift-client</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.dekorate</groupId>
<artifactId>openshift-junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -146,12 +110,6 @@
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<resources>
Expand Down Expand Up @@ -193,60 +151,12 @@
<profiles>
<profile>
<id>openshift</id>
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>fabric8-maven-plugin</artifactId>
<version>4.4.0</version>
<executions>
<execution>
<id>fmp</id>
<goals>
<goal>resource</goal>
<goal>build</goal>
</goals>
</execution>
</executions>
<configuration>
<resources>
<labels>
<all>
<property>
<name>app.kubernetes.io/part-of</name>
<value>configmap-example</value>
</property>
<property>
<name>app.kubernetes.io/name</name>
<value>configmap-service</value>
</property>
<property>
<name>app.kubernetes.io/component</name>
<value>frontend</value>
</property>
<property>
<name>app.openshift.io/runtime</name>
<value>rh-spring-boot</value>
</property>
<property>
<name>app.openshift.io/runtime-version</name>
<value>${spring-boot.version}</value>
</property>
</all>
</labels>
<annotations>
<all>
<property>
<name>app.kubernetes.io/vcs-uri</name>
<value>git@github.com:snowdrop/configmap-example.git</value>
</property>
</all>
</annotations>
</resources>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>io.dekorate</groupId>
<artifactId>openshift-spring-starter</artifactId>
</dependency>
</dependencies>
</profile>
<profile>
<id>openshift-it</id>
Expand Down
17 changes: 0 additions & 17 deletions src/main/fabric8/route.yml

This file was deleted.

3 changes: 3 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Dekorate
dekorate.openshift.expose=true
dekorate.s2i.builder-image=registry.access.redhat.com/ubi8/openjdk-8:1.3
116 changes: 116 additions & 0 deletions src/test/java/dev/snowdrop/example/AbstractOpenShiftIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* Copyright 2021 Red Hat, Inc, and individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dev.snowdrop.example;

import static io.restassured.RestAssured.given;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.core.Is.is;

import java.util.concurrent.TimeUnit;

import org.junit.jupiter.api.Test;

import io.fabric8.kubernetes.api.model.ConfigMapBuilder;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.openshift.client.OpenShiftClient;

public abstract class AbstractOpenShiftIT {

private static final String CONFIG_MAP_NAME = "app-config";
private static final String GREETING_NAME = System.getProperty("app.name");
private static final String GREETING_PATH = "api/greeting";

@Test
public void testConfigMapLifecycle() {
// Endpoint should say Hello at the beginning as ConfigMap must have been loaded before running the test
verifyEndpoint("Hello");

// Verify the name parameter is properly replaced in the greetings sentence.
given().param("name", "John")
.when()
.get(baseURL() + GREETING_PATH)
.then()
.statusCode(200)
.body("content", is("Hello John from a ConfigMap!"));

// Verify the app is updated when the config map changes
updateConfigMap();
rolloutChanges();
waitForApp();
verifyEndpoint("Bonjour");

// Verify the app is updated when the config map is deleted
deleteConfigMap();
rolloutChanges();
await().atMost(5, TimeUnit.MINUTES)
.catchUncaughtExceptions()
.untilAsserted(() -> given().get(baseURL() + GREETING_PATH)
.then().statusCode(500));
}

protected abstract String baseURL();
protected abstract KubernetesClient kubernetesClient();

private void verifyEndpoint(final String greeting) {
given().get(baseURL() + GREETING_PATH)
.then()
.statusCode(200)
.body("content", is(String.format("%s World from a ConfigMap!", greeting)));
}

private void updateConfigMap() {
kubernetesClient().configMaps()
.withName(CONFIG_MAP_NAME)
.edit(c -> new ConfigMapBuilder(c)
.addToData("application.yml", "greeting.message: Bonjour %s from a ConfigMap!")
.build());
}

private void deleteConfigMap() {
kubernetesClient().configMaps()
.withName(CONFIG_MAP_NAME)
.delete();
}

private void rolloutChanges() {
scale(0);
scale(1);
}

private void scale(final int replicas) {
OpenShiftClient ocClient = kubernetesClient().adapt(OpenShiftClient.class);
ocClient.deploymentConfigs().withName(GREETING_NAME).scale(replicas);

await().atMost(5, TimeUnit.MINUTES)
.until(() ->
ocClient.deploymentConfigs().withName(GREETING_NAME)
.get()
.getStatus()
.getAvailableReplicas() == replicas);
}

private void waitForApp() {
await().atMost(5, TimeUnit.MINUTES)
.ignoreExceptions()
.untilAsserted(
() -> given()
.get(baseURL() + GREETING_PATH)
.then().statusCode(200)
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,21 @@
import static org.hamcrest.core.Is.is;

import dev.snowdrop.example.service.GreetingProperties;
import org.junit.Test;
import org.junit.runner.RunWith;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.test.context.junit.jupiter.SpringExtension;

@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class ExampleApplicationTest {
public class LocalTest {

private static final String GREETING_PATH = "api/greeting";

protected static final String GREETING_PATH = "api/greeting";
@Value("${local.server.port}")
private int port;

Expand Down
Loading