This is an automated email from the ASF dual-hosted git repository.
bvahdat pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k-examples.git
The following commit(s) were added to refs/heads/main by this push:
new aaf5b34 fix 02-serverless-api example to work on camel-k 2.2.0 (#94)
aaf5b34 is described below
commit aaf5b349c472759d0277c8504e6e637a4730b967
Author: Babak Vahdat <[email protected]>
AuthorDate: Fri Feb 9 15:55:34 2024 +0100
fix 02-serverless-api example to work on camel-k 2.2.0 (#94)
* fix 02-serverless-api example to work on kamel 2.2.0
* polish
---
02-serverless-api/readme.didact.md | 31 +++++++++++++++++++++----
02-serverless-api/s3.properties | 6 +++--
02-serverless-api/test/MinioCustomizer.java | 36 -----------------------------
02-serverless-api/test/minio.properties | 14 ++++++-----
02-serverless-api/test/minio.yaml | 6 ++---
02-serverless-api/test/yaks-config.yaml | 2 +-
6 files changed, 42 insertions(+), 53 deletions(-)
diff --git a/02-serverless-api/readme.didact.md
b/02-serverless-api/readme.didact.md
index 5f88f00..e92763f 100644
--- a/02-serverless-api/readme.didact.md
+++ b/02-serverless-api/readme.didact.md
@@ -161,23 +161,44 @@ The file can be edited manually or better using an online
editor, such as [Apicu
The endpoints defined in the API can be implemented in a Camel K integration
using a `direct:<operationId>` endpoint.
This has been implemented in the
[API.java](didact://?commandId=vscode.open&projectFilePath=02-serverless-api/API.java
"Opens the integration file"){.didact} file.
-To run the integration, you need to link it to the proper configuration, that
depends on what configuration you've chosen.
+To run the integration, you need to link it to the proper configuration, that
depends on what configuration you've chosen (either S3 or Minio). Additionally
you need to expose the OpenAPI spec. as ConfigMap:
+
+```
+kubectl create configmap my-openapi --from-file=openapi.yaml
+```
### 4.1 [Alternative 1] Using the test Minio server
-As alternative, to connect the integration to the **test Minio server**
deployed before using the
[test/MinioCustomizer.java](didact://?commandId=vscode.open&projectFilePath=02-serverless-api/test/MinioCustomizer.java
"Opens the customizer file"){.didact} class:
+As alternative, to connect the integration to the **test Minio server**
deployed before:
+
+```
+kamel run API.java --open-api configmap:my-openapi --property
file:test/minio.properties --dev
+```
+([^
execute](didact://?commandId=vscode.didact.sendNamedTerminalAString&text=camelTerm$$kamel%20run%20API.java%20--property%20file%3Atest%2Fminio.properties&completion=Integration%20run.
"Opens a new terminal and sends the command above"){.didact})
+
+In case you run on Minikube then you can't use `http://minio:9000` as your S3
endpoint in `minio.properties` because `EXTERNAL-IP` would be `<pending>` since
Minikube doesn't support LoadBalancer services, so the service will never get
an external IP. For this to work you can run Minikube service to get the URL
for connection to use:
+
+```
+$> minikube service -n camel-api minio
+|-----------|-------|-------------|-----------------------------|
+| NAMESPACE | NAME | TARGET PORT | URL |
+|-----------|-------|-------------|-----------------------------|
+| camel-api | minio | 9000 | http://192.168.105.26:32393 |
+|-----------|-------|-------------|-----------------------------|
+```
+
+Given the example above then use the following configuration in
`minio.properties`:
```
-kamel run API.java --open-api file:openapi.yaml --source
test/MinioCustomizer.java --property file:test/minio.properties
+camel.component.aws2-s3.uri-endpoint-override=http://192.168.105.26:32393
```
-([^
execute](didact://?commandId=vscode.didact.sendNamedTerminalAString&text=camelTerm$$kamel%20run%20API.java%20--source%20test%2FMinioCustomizer.java%20--property%20file%3Atest%2Fminio.properties&completion=Integration%20run.
"Opens a new terminal and sends the command above"){.didact})
### 4.2 [Alternative 2] Using the S3 service
To connect the integration to the **AWS S3 service**:
```
-kamel run API.java --open-api file:openapi.yaml --property file:s3.properties
+kamel run API.java --open-api configmap:my-openapi --property
file:s3.properties --dev
```
([^
execute](didact://?commandId=vscode.didact.sendNamedTerminalAString&text=camelTerm$$kamel%20run%20API.java%20--property%20file%3As3.properties&completion=Integration%20run.
"Opens a new terminal and sends the command above"){.didact})
diff --git a/02-serverless-api/s3.properties b/02-serverless-api/s3.properties
index 14ce141..7d8f9e0 100644
--- a/02-serverless-api/s3.properties
+++ b/02-serverless-api/s3.properties
@@ -5,11 +5,13 @@
# Bucket (referenced in the routes)
api.bucket=camel-k
# Region of the buket
-camel.component.aws2-s3.region=EU_WEST_1
+camel.component.aws2-s3.region=eu-west-1
# AWS Access Key ID
camel.component.aws2-s3.access-key=<put-your-aws-access-key-id-here>
# AWS Access Key Secret
camel.component.aws2-s3.secret-key=<put-your-aws-access-key-secret-here>
+# Autocreate the bucket if it doesn't exist
+camel.component.aws2-s3.autoCreateBucket=true
# General configuration
-camel.context.rest-configuration.api-context-path=/openapi.json
+camel.rest.api-context-path=/openapi.json
\ No newline at end of file
diff --git a/02-serverless-api/test/MinioCustomizer.java
b/02-serverless-api/test/MinioCustomizer.java
deleted file mode 100644
index ff59716..0000000
--- a/02-serverless-api/test/MinioCustomizer.java
+++ /dev/null
@@ -1,36 +0,0 @@
-// camel-k: language=java
-package test;
-
-import org.apache.camel.BindToRegistry;
-import org.apache.camel.PropertyInject;
-
-import com.amazonaws.auth.AWSCredentials;
-import com.amazonaws.auth.AWSCredentialsProvider;
-import com.amazonaws.auth.AWSStaticCredentialsProvider;
-import com.amazonaws.auth.BasicAWSCredentials;
-import com.amazonaws.client.builder.AwsClientBuilder;
-import com.amazonaws.services.s3.AmazonS3;
-import com.amazonaws.services.s3.AmazonS3ClientBuilder;
-
-public class MinioCustomizer {
-
- @BindToRegistry
- public static AmazonS3 minioClient(
- @PropertyInject("minio.endpoint") String endpointAddress,
- @PropertyInject("minio.access-key") String accessKey,
- @PropertyInject("minio.secret-key") String secretKey) {
-
- AwsClientBuilder.EndpointConfiguration endpoint = new
AwsClientBuilder.EndpointConfiguration(endpointAddress, "US_EAST_1");
- AWSCredentials credentials = new BasicAWSCredentials(accessKey,
secretKey);
- AWSCredentialsProvider credentialsProvider = new
AWSStaticCredentialsProvider(credentials);
-
- return AmazonS3ClientBuilder
- .standard()
- .withEndpointConfiguration(endpoint)
- .withCredentials(credentialsProvider)
- .withPathStyleAccessEnabled(true)
- .build();
-
- }
-
-}
diff --git a/02-serverless-api/test/minio.properties
b/02-serverless-api/test/minio.properties
index 9d15b40..6bdde81 100644
--- a/02-serverless-api/test/minio.properties
+++ b/02-serverless-api/test/minio.properties
@@ -5,11 +5,13 @@
# Bucket (referenced in the routes)
api.bucket=camel-k
-# Minio information injected into the MinioCustomizer
-minio.endpoint=http://minio:9000
-minio.access-key=minio
-minio.secret-key=minio123
-
+# Camel AWS2 S3
+camel.component.aws2-s3.region=eu-west-1
+camel.component.aws2-s3.access-key=minio
+camel.component.aws2-s3.secret-key=minio123
+camel.component.aws2-s3.uri-endpoint-override=http://192.168.105.26:32393
+camel.component.aws2-s3.override-endpoint=true
+camel.component.aws2-s3.autoCreateBucket=true
# General configuration
-camel.context.rest-configuration.api-context-path=/openapi.json
+camel.rest.api-context-path=/openapi.json
\ No newline at end of file
diff --git a/02-serverless-api/test/minio.yaml
b/02-serverless-api/test/minio.yaml
index cd5f52d..eecfcad 100644
--- a/02-serverless-api/test/minio.yaml
+++ b/02-serverless-api/test/minio.yaml
@@ -20,16 +20,16 @@ spec:
containers:
- name: minio
volumeMounts:
- - name: data
+ - name: data
mountPath: "/data"
image: minio/minio
args:
- server
- /data
env:
- - name: MINIO_ACCESS_KEY
+ - name: MINIO_ROOT_USER
value: minio
- - name: MINIO_SECRET_KEY
+ - name: MINIO_ROOT_PASSWORD
value: minio123
ports:
- containerPort: 9000
diff --git a/02-serverless-api/test/yaks-config.yaml
b/02-serverless-api/test/yaks-config.yaml
index f9ad458..514cfe4 100644
--- a/02-serverless-api/test/yaks-config.yaml
+++ b/02-serverless-api/test/yaks-config.yaml
@@ -11,4 +11,4 @@ pre:
run: |
kamel install -w -n ${YAKS_NAMESPACE}
- kamel run API.java --source test/MinioCustomizer.java --property
file:test/minio.properties -w -n ${YAKS_NAMESPACE}
+ kamel run API.java --property file:test/minio.properties -w -n
${YAKS_NAMESPACE}