You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2022/06/24 14:44:16 UTC
[camel] branch main updated (97045a93cce -> 4bf48eaf2a0)
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
from 97045a93cce CAMEL-18222: camel-kubernetes - KubernetesClient should be autowried
new 6dec16ab59e CAMEL-18171: camel-main - LocationHelper to make it easier to get summary logs
new 4bf48eaf2a0 CAMEL-18171: camel-kubernetes - Allow to configure k8s client from application.properties.
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../properties/BasePropertiesFunction.java | 45 ++++++++++++++++
.../org/apache/camel/main/BaseMainSupport.java | 32 +----------
.../java/org/apache/camel/util/LocationHelper.java | 62 ++++++++++++++++++++++
3 files changed, 108 insertions(+), 31 deletions(-)
create mode 100644 core/camel-util/src/main/java/org/apache/camel/util/LocationHelper.java
[camel] 02/02: CAMEL-18171: camel-kubernetes - Allow to configure k8s client from application.properties.
Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 4bf48eaf2a017f213820a4d33663c6c7346fd739
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Jun 24 16:43:58 2022 +0200
CAMEL-18171: camel-kubernetes - Allow to configure k8s client from application.properties.
---
.../properties/BasePropertiesFunction.java | 45 ++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/properties/BasePropertiesFunction.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/properties/BasePropertiesFunction.java
index b8ff0740bb5..c78fbcd9e37 100644
--- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/properties/BasePropertiesFunction.java
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/properties/BasePropertiesFunction.java
@@ -21,21 +21,33 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Locale;
+import java.util.Map;
+import io.fabric8.kubernetes.client.ConfigBuilder;
+import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import org.apache.camel.CamelContext;
import org.apache.camel.CamelContextAware;
+import org.apache.camel.spi.PropertiesComponent;
import org.apache.camel.spi.PropertiesFunction;
import org.apache.camel.support.CamelContextHelper;
+import org.apache.camel.support.PropertyBindingSupport;
import org.apache.camel.support.service.ServiceSupport;
+import org.apache.camel.util.LocationHelper;
import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.OrderedLocationProperties;
+import org.apache.camel.util.SensitiveUtils;
import org.apache.camel.util.StringHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Base for kubernetes {@link PropertiesFunction}.
*/
abstract class BasePropertiesFunction extends ServiceSupport implements PropertiesFunction, CamelContextAware {
+ private static final Logger LOG = LoggerFactory.getLogger(BasePropertiesFunction.class);
+
// keys in application.properties for mount paths
public static final String MOUNT_PATH_CONFIGMAPS = "org.apache.camel.component.kubernetes.properties.mount-path-configmaps";
public static final String MOUNT_PATH_SECRETS = "org.apache.camel.component.kubernetes.properties.mount-path-secrets";
@@ -50,6 +62,7 @@ abstract class BasePropertiesFunction extends ServiceSupport implements Properti
private String mountPathSecrets;
@Override
+ @SuppressWarnings("unchecked")
protected void doInit() throws Exception {
ObjectHelper.notNull(camelContext, "CamelContext");
if (mountPathConfigMaps == null) {
@@ -63,6 +76,38 @@ abstract class BasePropertiesFunction extends ServiceSupport implements Properti
if (client == null) {
client = CamelContextHelper.findSingleByType(camelContext, KubernetesClient.class);
}
+ if (client == null) {
+ // try to auto-configure via properties
+ PropertiesComponent pc = camelContext.getPropertiesComponent();
+ OrderedLocationProperties properties = (OrderedLocationProperties) pc
+ .loadProperties(k -> k.startsWith("camel.kubernetes-client.") || k.startsWith("camel.kubernetesClient."));
+ if (!properties.isEmpty()) {
+ ConfigBuilder config = new ConfigBuilder();
+ PropertyBindingSupport.build()
+ .withProperties((Map) properties)
+ .withFluentBuilder(true)
+ .withIgnoreCase(true)
+ .withReflection(true)
+ .withTarget(config)
+ .withCamelContext(camelContext)
+ .bind();
+ client = new DefaultKubernetesClient(config.build());
+ LOG.info("Auto-configuration io.fabric8.kubernetes.client.KubernetesClient summary");
+ for (var entry : properties.entrySet()) {
+ String k = entry.getKey().toString();
+ Object v = entry.getValue();
+ String loc = LocationHelper.locationSummary(properties, k);
+ if (SensitiveUtils.containsSensitive(k)) {
+ LOG.info(" {} {}=xxxxxx", loc, k);
+ } else {
+ LOG.info(" {} {}={}", loc, k, v);
+ }
+ }
+ // add to registry so the client can be reused
+ camelContext.getRegistry().bind("camelKubernetesClient", client);
+ }
+ }
+
if (client == null && getMountPath() == null) {
throw new IllegalArgumentException("Either a mount path or the Kubernetes Client must be configured");
}
[camel] 01/02: CAMEL-18171: camel-main - LocationHelper to make it easier to get summary logs
Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 6dec16ab59e95072c93ae62c0b63226ea91265ed
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Jun 24 16:20:39 2022 +0200
CAMEL-18171: camel-main - LocationHelper to make it easier to get summary logs
---
.../org/apache/camel/main/BaseMainSupport.java | 32 +----------
.../java/org/apache/camel/util/LocationHelper.java | 62 ++++++++++++++++++++++
2 files changed, 63 insertions(+), 31 deletions(-)
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
index bb03247c31e..ed6632a1bca 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
@@ -80,6 +80,7 @@ import static org.apache.camel.main.MainHelper.computeProperties;
import static org.apache.camel.main.MainHelper.optionKey;
import static org.apache.camel.main.MainHelper.setPropertiesOnTarget;
import static org.apache.camel.main.MainHelper.validateOptionAndValue;
+import static org.apache.camel.util.LocationHelper.locationSummary;
import static org.apache.camel.util.StringHelper.matches;
/**
@@ -1687,37 +1688,6 @@ public abstract class BaseMainSupport extends BaseService {
return answer;
}
- private static String locationSummary(OrderedLocationProperties autoConfiguredProperties, String key) {
- String loc = autoConfiguredProperties.getLocation(key);
- if (loc == null) {
- loc = "";
- }
- // remove scheme to make it shorter
- if (loc.contains(":")) {
- loc = StringHelper.after(loc, ":");
- }
- // strip paths so location is only the name
- loc = FileUtil.stripPath(loc);
- // clip long name
- if (loc.length() > 28) {
- int pos = loc.length() - 28;
- loc = loc.substring(pos);
- }
- // let us have human friendly locations
- if ("initial".equals(loc) || "override".equals(loc)) {
- loc = "camel-main";
- } else if ("SYS".equals(loc)) {
- loc = "JVM System Property";
- } else if ("ENV".equals(loc)) {
- loc = "OS Environment Variable";
- } else if ("arguments".equals(loc) || "CLI".equals(loc)) {
- loc = "Command Line";
- }
- loc = "[" + loc + "]";
- loc = String.format("%-30s", loc);
- return loc;
- }
-
private static final class PropertyPlaceholderListener implements PropertiesLookupListener {
private final OrderedLocationProperties olp;
diff --git a/core/camel-util/src/main/java/org/apache/camel/util/LocationHelper.java b/core/camel-util/src/main/java/org/apache/camel/util/LocationHelper.java
new file mode 100644
index 00000000000..30b8e752ef4
--- /dev/null
+++ b/core/camel-util/src/main/java/org/apache/camel/util/LocationHelper.java
@@ -0,0 +1,62 @@
+/*
+ * 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.
+ */
+package org.apache.camel.util;
+
+public final class LocationHelper {
+
+ private LocationHelper() {
+ }
+
+ /**
+ * The location as human-readable with the given key from the properties
+ *
+ * @param properties the properties
+ * @param key the key
+ * @return the location or empty if not possible to resolve a location.
+ */
+ public static String locationSummary(OrderedLocationProperties properties, String key) {
+ String loc = properties.getLocation(key);
+ if (loc == null) {
+ loc = "";
+ }
+ // remove scheme to make it shorter
+ if (loc.contains(":")) {
+ loc = StringHelper.after(loc, ":");
+ }
+ // strip paths so location is only the name
+ loc = FileUtil.stripPath(loc);
+ // clip long name
+ if (loc.length() > 28) {
+ int pos = loc.length() - 28;
+ loc = loc.substring(pos);
+ }
+ // let us have human friendly locations
+ if ("initial".equals(loc) || "override".equals(loc)) {
+ loc = "camel-main";
+ } else if ("SYS".equals(loc)) {
+ loc = "JVM System Property";
+ } else if ("ENV".equals(loc)) {
+ loc = "OS Environment Variable";
+ } else if ("arguments".equals(loc) || "CLI".equals(loc)) {
+ loc = "Command Line";
+ }
+ loc = "[" + loc + "]";
+ loc = String.format("%-30s", loc);
+ return loc;
+ }
+
+}