Skip to content

Commit

Permalink
Merge pull request #7 from christophd/1.8.x
Browse files Browse the repository at this point in the history
chore: Use Camel K 1.8.x and introduce automated e2e tests
  • Loading branch information
christophd committed Jul 11, 2022
2 parents 41e370b + 52c4cbf commit ff90ec0
Show file tree
Hide file tree
Showing 9 changed files with 243 additions and 39 deletions.
107 changes: 107 additions & 0 deletions .github/workflows/kubernetes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# ---------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.
# ---------------------------------------------------------------------------

name: Kubernetes

on:
pull_request:
branches:
- main
- 1.6.x
- 1.8.x
push:
branches:
- main
- 1.6.x
- 1.8.x

jobs:
test:
runs-on: ubuntu-latest
env:
CAMEL_K_VERSION: 1.8.2
YAKS_VERSION: 0.11.0-202207071318
YAKS_IMAGE_NAME: "docker.io/yaks/yaks"
YAKS_RUN_OPTIONS: "--timeout=15m"
KUBECTL_WAIT_TIMEOUT: "180s"
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Cleanup
run: |
ls -lart
echo "Initial status:"
df -h
echo "Cleaning up resources:"
sudo swapoff -a
sudo rm -f /swapfile
sudo apt clean
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
docker rmi $(docker image ls -aq)
echo "Final status:"
df -h
- name: Set up JDK 11
uses: AdoptOpenJDK/install-jdk@v1
with:
version: "11"
- name: Kind Cluster
uses: container-tools/kind-action@v1
with:
version: v0.11.0
node_image: kindest/node:v1.21.1@sha256:fae9a58f17f18f06aeac9772ca8b5ac680ebbed985e266f711d936e91d113bad
- name: Info
run: |
kubectl version
kubectl cluster-info
kubectl describe nodes
- name: Camel K Tools
uses: container-tools/camel-k-action@v1
with:
version: v${{ env.CAMEL_K_VERSION }}
- name: Install Camel K
run: |
# Configure install options
export KAMEL_INSTALL_BUILD_PUBLISH_STRATEGY=Spectrum
export KAMEL_INSTALL_REGISTRY=$KIND_REGISTRY
export KAMEL_INSTALL_REGISTRY_INSECURE=true
kamel install
- name: YAKS tools
uses: citrusframework/yaks-install-action@v1.0
with:
version: ${{ env.YAKS_VERSION }}
- name: Install YAKS
run: |
yaks install --operator-image $YAKS_IMAGE_NAME:$YAKS_VERSION
- name: YAKS Tests
run: |
# Then run integration tests
yaks run test/datasource.feature $YAKS_RUN_OPTIONS
- name: YAKS Report
if: failure()
run: |
yaks report
- uses: actions/upload-artifact@v2
if: failure()
with:
name: dumps
path: _output/*-dump.log
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/.vscode/settings.json

.project
.metadata
.classpath
.settings

*.iml
/.idea

# Test output folder
_output/

# Dependency library folder for IDE setup
lib/
34 changes: 20 additions & 14 deletions JDBCInsert.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,29 @@
* limitations under the License.
*/

// You can use the sample postgres database available at /postgres-deploy/README.md
// You can use the sample postgres database available at https://github.com/apache/camel-k/tree/release-1.8.x/examples/databases/postgres-deploy
//
// kamel run JDBCInsert.java --dev -p quarkus.datasource.camel.db-kind=postgresql
// -p quarkus.datasource.camel.jdbc.url=jdbc:postgresql://postgres:5432/test
// -p quarkus.datasource.camel.username=postgresadmin
// -p quarkus.datasource.camel.password=admin123

// Alternatively, you can bundle your credentials as a secret properties file:
//
// kubectl create secret generic my-datasource --from-file=datasource.properties
//
// kamel run JDBCInsert.java --dev --build-property quarkus.datasource.camel.db-kind=postgresql
// --config secret:my-datasource
// -d mvn:io.quarkus:quarkus-jdbc-postgresql
//
// kamel run JDBCInsert.java --dev --config secret:my-datasource

// camel-k: dependency=mvn:io.quarkus:quarkus-jdbc-postgresql

import org.apache.camel.builder.RouteBuilder;

public class JDBCInsert extends RouteBuilder {
@Override
public void configure() throws Exception {
from("timer://sql-insert?period=10000")
.setBody(simple("INSERT INTO test (data) VALUES ('message #${exchangeProperty.CamelTimerCounter}')"))
.to("jdbc:camel")
.to("log:info");
}

}
@Override
public void configure() throws Exception {
from("timer://sql-insert?period=10000")
.setBody(simple("INSERT INTO test (data) VALUES ('message #${exchangeProperty.CamelTimerCounter}')"))
.to("jdbc:default")
.to("log:info");
}
}
35 changes: 20 additions & 15 deletions JDBCSelect.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,29 @@
* limitations under the License.
*/

// You can use the sample postgres database available at /postgres-deploy/README.md
// You can use the sample postgres database available at https://github.com/apache/camel-k/tree/release-1.8.x/examples/databases/postgres-deploy
//
// kamel run JDBCSelect.java --dev -p quarkus.datasource.camel.db-kind=postgresql
// -p quarkus.datasource.camel.jdbc.url=jdbc:postgresql://postgres:5432/test
// -p quarkus.datasource.camel.username=postgresadmin
// -p quarkus.datasource.camel.password=admin123

// Alternatively, you can bundle your credentials as a secret properties file:
//
// kubectl create secret generic my-datasource --from-file=datasource.properties
//
// kamel run JDBCSelect.java --dev --build-property quarkus.datasource.camel.db-kind=postgresql
// --config secret:my-datasource
// -d mvn:io.quarkus:quarkus-jdbc-postgresql
//
//
// kamel run JDBCSelect.java --dev --config secret:my-datasource

// camel-k: dependency=mvn:io.quarkus:quarkus-jdbc-postgresql

import org.apache.camel.builder.RouteBuilder;

public class JDBCSelect extends RouteBuilder {
@Override
public void configure() throws Exception {
from("timer://foo?period=10000")
.setBody(constant("SELECT * FROM test LIMIT 5 OFFSET 0"))
.to("jdbc:camel")
.to("log:info");
}

}
@Override
public void configure() throws Exception {
from("timer://foo?period=10000")
.setBody(constant("SELECT data FROM test LIMIT 5 OFFSET 0"))
.to("jdbc:default")
.to("log:info");
}
}
6 changes: 3 additions & 3 deletions datasource.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
quarkus.datasource.camel.jdbc.url=jdbc:postgresql://postgres:5432/test
quarkus.datasource.camel.username=postgresadmin
quarkus.datasource.camel.password=admin123
quarkus.datasource.jdbc.url=jdbc:postgresql://postgres:5432/test
quarkus.datasource.username=postgresadmin
quarkus.datasource.password=admin123
16 changes: 9 additions & 7 deletions readme.didact.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This example demonstrates how to get started with `Camel K` and an SQL database via `JDBC` drivers. We will show how to quickly set up an integration producing data into a Postgres database (you can use any relational database of your choice). We will show also how to read data from the same database.

The quickstart is based on the [Apache Camel K upstream database examples](https://github.com/apache/camel-k/blob/main/examples/databases/).
The quickstart is based on the [Apache Camel K upstream database examples](https://github.com/apache/camel-k/tree/release-1.8.x/examples/databases/).

## Before you begin

Expand Down Expand Up @@ -104,9 +104,11 @@ We assume you already have a database up and running. If it's not the case, you

### Prepare the database

For this tutorial, we're using a `Postgres` database service named `postgresql` deployed in the same `camel-k-jdbc` project. In order to configure the `JDBC` you will need to get the following settings: the `JDBC url`, `driver`, `username` and `password`. You may require assistance from your database administrator if you're not managing directly the database instance.
For this tutorial, we're using a `Postgres` database service named `postgresql` deployed in the same `camel-k-jdbc` project. In order to configure the `JDBC` you will need to get the following settings: the `JDBC url`, `driver`, `username` and `password`. You may require assistance from your database administrator if you are not managing directly the database instance.

If you are using the Postgres instance mentioned above, you will setup the credentials as part of the deployment process.
To set up the database tables and some test data you can use the sample postgres database available at the [Apache Camel K upstream database examples](https://github.com/apache/camel-k/tree/release-1.8.x/examples/databases/postgres-deploy)

If you are using the Postgres instance mentioned above, you will set up the credentials as part of the deployment process.

> **NOTE**: make sure your Openshift cluster have connectivity with your database if it's deployed outside the cluster.
Expand All @@ -124,9 +126,9 @@ oc create secret generic my-datasource --from-file=datasource.properties
At this stage, run a producer integration. This one will insert a row in a `test` table, every 10 seconds.

```
kamel run JDBCInsert.java --dev --build-property quarkus.datasource.camel.db-kind=postgresql --config secret:my-datasource -d mvn:io.quarkus:quarkus-jdbc-postgresql
kamel run JDBCInsert.java --dev --config secret:my-datasource
```
([^ execute](didact://?commandId=vscode.didact.sendNamedTerminalAString&text=camelProducerTerm$$kamel%20run%20JDBCInsert.java%20--dev%20--build-property%20quarkus.datasource.camel.db-kind=postgresql%20--config%20secret:my-datasource%20-d%20mvn:io.quarkus:quarkus-jdbc-postgresql&completion=Camel%20K%20integration%20run%20in%20dev%20mode. "Opens a new terminal and sends the command above"){.didact})
([^ execute](didact://?commandId=vscode.didact.sendNamedTerminalAString&text=camelProducerTerm$$kamel%20run%20JDBCInsert.java%20--dev%20--config%20secret:my-datasource&completion=Camel%20K%20integration%20run%20in%20dev%20mode. "Opens a new terminal and sends the command above"){.didact})

Please, notice that we must specify certain dependencies that will be needed at runtime. In particular, we will have to provide the `JDBC driver` that is expected by the database. In our example, we're using the `Postgresql` drivers: make sure you pick up the proper driver according to your database instance.

Expand All @@ -144,9 +146,9 @@ The producer will create a new message and push into the database and log some i
Now we can run a consumer integration. This one will read 5 rows from a `test` table, every 10 seconds.

```
kamel run JDBCSelect.java --dev --build-property quarkus.datasource.camel.db-kind=postgresql --config secret:my-datasource -d mvn:io.quarkus:quarkus-jdbc-postgresql
kamel run JDBCSelect.java --dev --config secret:my-datasource
```
([^ execute](didact://?commandId=vscode.didact.sendNamedTerminalAString&text=camelConsumerTerm$$kamel%20run%20JDBCSelect.java%20--dev%20--build-property%20quarkus.datasource.camel.db-kind=postgresql%20--config%20secret:my-datasource%20-d%20mvn:io.quarkus:quarkus-jdbc-postgresql&completion=Camel%20K%20integration%20run%20in%20dev%20mode. "Opens a new terminal and sends the command above"){.didact})
([^ execute](didact://?commandId=vscode.didact.sendNamedTerminalAString&text=camelConsumerTerm$$kamel%20run%20JDBCSelect.java%20--dev%20--config%20secret:my-datasource&completion=Camel%20K%20integration%20run%20in%20dev%20mode. "Opens a new terminal and sends the command above"){.didact})

Also here we had to specify certain dependencies that may change if you use a different database. A consumer will start logging the events found in the table:

Expand Down
3 changes: 3 additions & 0 deletions test/datasource-test.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
quarkus.datasource.jdbc.url=jdbc:postgresql://${YAKS_TESTCONTAINERS_POSTGRESQL_SERVICE_NAME}.${YAKS_NAMESPACE}:${YAKS_TESTCONTAINERS_POSTGRESQL_PORT}/${YAKS_TESTCONTAINERS_POSTGRESQL_DB_NAME}
quarkus.datasource.username=${YAKS_TESTCONTAINERS_POSTGRESQL_USERNAME}
quarkus.datasource.password=${YAKS_TESTCONTAINERS_POSTGRESQL_PASSWORD}
33 changes: 33 additions & 0 deletions test/datasource.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Feature: JDBC datasource

Background:
Given Camel K resource polling configuration
| maxAttempts | 200 |
| delayBetweenAttempts | 2000 |

Scenario: Start PostgreSQL
Given Database init script
"""
CREATE TABLE IF NOT EXISTS test (data TEXT PRIMARY KEY);
INSERT INTO test(data) VALUES ('hello'), ('world');
"""
Then start PostgreSQL container

Scenario: Create data integrations and verify
# Create select data integration
Given Camel K integration property file datasource-test.properties
When load Camel K integration JDBCSelect.java
Then Camel K integration jdbcselect should be running

# Create insert data integration
Given Camel K integration property file datasource-test.properties
When load Camel K integration JDBCInsert.java
Then Camel K integration jdbcinsert should be running

# Verify select integration to receive db entries (limit 5)
Then Camel K integration jdbcselect should print [{data=hello}, {data=world}, {data=message #1}, {data=message #2}, {data=message #3}]

Scenario: Remove Camel K integrations
Given delete Camel K integration jdbcinsert
Given delete Camel K integration jdbcselect
33 changes: 33 additions & 0 deletions test/yaks-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
config:
namespace:
temporary: false
runtime:
env:
- name: YAKS_CAMELK_AUTO_REMOVE_RESOURCES
value: false
- name: YAKS_KUBERNETES_AUTO_REMOVE_RESOURCES
value: false
- name: YAKS_TESTCONTAINERS_AUTO_REMOVE_RESOURCES
value: false
- name: YAKS_CAMELK_SUPPORT_VARIABLES_IN_SOURCES
value: false
resources:
- ../JDBCInsert.java
- ../JDBCSelect.java
- datasource-test.properties
testcontainers:
enabled: true
dump:
enabled: true
failedOnly: true
includes:
- app=camel-k
pre:
- name: Create secret holding database credentials
run: kubectl create secret generic test-datasource --from-file=datasource-test.properties
post:
- name: Delete secret
run: kubectl delete secret test-datasource
- name: print dump
if: env:CI=true && failure()
run: kamel dump

0 comments on commit ff90ec0

Please sign in to comment.