You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2018/07/09 10:00:33 UTC
[camel] 01/04: CAMEL-12583 - Camel-Kubernetes: Add an HPA component
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit e3cc783bf697f83cec672a1c410f5b868995b94e
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Mon Jul 9 11:17:55 2018 +0200
CAMEL-12583 - Camel-Kubernetes: Add an HPA component
---
.../component/kubernetes/KubernetesConstants.java | 2 +
.../component/kubernetes/KubernetesOperations.java | 7 +
.../kubernetes/consumer/common/HPAEvent.java | 48 +++++
.../kubernetes/hpa/KubernetesHPAComponent.java | 28 +++
.../kubernetes/hpa/KubernetesHPAConsumer.java | 143 +++++++++++++++
.../kubernetes/hpa/KubernetesHPAEndpoint.java | 52 ++++++
.../kubernetes/hpa/KubernetesHPAProducer.java | 202 +++++++++++++++++++++
.../org/apache/camel/component/kubernetes-hpa | 18 ++
.../producer/KubernetesHPAProducerTest.java | 131 +++++++++++++
.../producer/KubernetesPodsProducerTest.java | 195 ++++++++++----------
.../KubernetesHPAComponentAutoConfiguration.java | 129 +++++++++++++
.../KubernetesHPAComponentConfiguration.java | 50 +++++
.../src/main/resources/META-INF/spring.factories | 4 +-
13 files changed, 913 insertions(+), 96 deletions(-)
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesConstants.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesConstants.java
index eecc409..47d546a 100644
--- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesConstants.java
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesConstants.java
@@ -58,6 +58,8 @@ public interface KubernetesConstants {
String KUBERNETES_BUILD_CONFIGS_LABELS = "CamelKubernetesBuildConfigsLabels";
String KUBERNETES_BUILD_CONFIG_NAME = "CamelKubernetesBuildConfigName";
String KUBERNETES_DEPLOYMENT_REPLICAS = "CamelKubernetesDeploymentReplicas";
+ String KUBERNETES_HPA_NAME = "CamelKubernetesHPAName";
+ String KUBERNETES_HPA_SPEC = "CamelKubernetesHPASpec";
// Consumer
String KUBERNETES_EVENT_ACTION = "CamelKubernetesEventAction";
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesOperations.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesOperations.java
index 4eb8dc5..ea4666a 100644
--- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesOperations.java
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesOperations.java
@@ -85,6 +85,13 @@ public interface KubernetesOperations {
String LIST_NODES_BY_LABELS_OPERATION = "listNodesByLabels";
String GET_NODE_OPERATION = "getNode";
+ // HPA
+ String LIST_HPA = "listHPA";
+ String LIST_HPA_BY_LABELS_OPERATION = "listHPAByLabels";
+ String GET_HPA_OPERATION = "getHPA";
+ String CREATE_HPA_OPERATION = "createHPA";
+ String DELETE_HPA_OPERATION = "deleteHPA";
+
// Deployments
String LIST_DEPLOYMENTS = "listDeployments";
String LIST_DEPLOYMENTS_BY_LABELS_OPERATION = "listDeploymentsByLabels";
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/common/HPAEvent.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/common/HPAEvent.java
new file mode 100644
index 0000000..efa403f
--- /dev/null
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/common/HPAEvent.java
@@ -0,0 +1,48 @@
+/**
+ * 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.component.kubernetes.consumer.common;
+
+import io.fabric8.kubernetes.api.model.HorizontalPodAutoscaler;
+import io.fabric8.kubernetes.client.Watcher.Action;
+
+public class HPAEvent {
+ private io.fabric8.kubernetes.client.Watcher.Action action;
+
+ private HorizontalPodAutoscaler hpa;
+
+ public HPAEvent(Action action, HorizontalPodAutoscaler hpa) {
+ this.action = action;
+ this.hpa = hpa;
+ }
+
+ public io.fabric8.kubernetes.client.Watcher.Action getAction() {
+ return action;
+ }
+
+ public void setAction(io.fabric8.kubernetes.client.Watcher.Action action) {
+ this.action = action;
+ }
+
+ public HorizontalPodAutoscaler getHpa() {
+ return hpa;
+ }
+
+ public void setHpa(HorizontalPodAutoscaler hpa) {
+ this.hpa = hpa;
+ }
+
+}
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/hpa/KubernetesHPAComponent.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/hpa/KubernetesHPAComponent.java
new file mode 100644
index 0000000..d498551
--- /dev/null
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/hpa/KubernetesHPAComponent.java
@@ -0,0 +1,28 @@
+/**
+ * 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.component.kubernetes.hpa;
+
+import org.apache.camel.component.kubernetes.AbstractKubernetesComponent;
+import org.apache.camel.component.kubernetes.KubernetesConfiguration;
+
+public class KubernetesHPAComponent extends AbstractKubernetesComponent {
+
+ protected KubernetesHPAEndpoint doCreateEndpoint(String uri, String remaining, KubernetesConfiguration config) throws Exception {
+ KubernetesHPAEndpoint endpoint = new KubernetesHPAEndpoint(uri, this, config);
+ return endpoint;
+ }
+}
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/hpa/KubernetesHPAConsumer.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/hpa/KubernetesHPAConsumer.java
new file mode 100644
index 0000000..a3ae2d2
--- /dev/null
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/hpa/KubernetesHPAConsumer.java
@@ -0,0 +1,143 @@
+/**
+ * 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.component.kubernetes.hpa;
+
+import java.util.concurrent.ExecutorService;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.component.kubernetes.AbstractKubernetesEndpoint;
+import org.apache.camel.component.kubernetes.KubernetesConstants;
+import org.apache.camel.component.kubernetes.consumer.common.HPAEvent;
+import org.apache.camel.impl.DefaultConsumer;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import io.fabric8.kubernetes.api.model.DoneableHorizontalPodAutoscaler;
+import io.fabric8.kubernetes.api.model.HorizontalPodAutoscaler;
+import io.fabric8.kubernetes.api.model.HorizontalPodAutoscalerList;
+import io.fabric8.kubernetes.client.KubernetesClientException;
+import io.fabric8.kubernetes.client.Watch;
+import io.fabric8.kubernetes.client.Watcher;
+import io.fabric8.kubernetes.client.dsl.MixedOperation;
+import io.fabric8.kubernetes.client.dsl.Resource;
+
+public class KubernetesHPAConsumer extends DefaultConsumer {
+
+ private static final Logger LOG = LoggerFactory.getLogger(KubernetesHPAConsumer.class);
+
+ private final Processor processor;
+ private ExecutorService executor;
+ private HpaConsumerTask hpasWatcher;
+
+ public KubernetesHPAConsumer(AbstractKubernetesEndpoint endpoint, Processor processor) {
+ super(endpoint, processor);
+ this.processor = processor;
+ }
+
+ @Override
+ public AbstractKubernetesEndpoint getEndpoint() {
+ return (AbstractKubernetesEndpoint) super.getEndpoint();
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ super.doStart();
+ executor = getEndpoint().createExecutor();
+
+ hpasWatcher = new HpaConsumerTask();
+ executor.submit(hpasWatcher);
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ super.doStop();
+
+ LOG.debug("Stopping Kubernetes HPA Consumer");
+ if (executor != null) {
+ if (getEndpoint() != null && getEndpoint().getCamelContext() != null) {
+ if (hpasWatcher != null) {
+ hpasWatcher.getWatch().close();
+ }
+ getEndpoint().getCamelContext().getExecutorServiceManager().shutdownNow(executor);
+ } else {
+ if (hpasWatcher != null) {
+ hpasWatcher.getWatch().close();
+ }
+ executor.shutdownNow();
+ }
+ }
+ executor = null;
+ }
+
+ class HpaConsumerTask implements Runnable {
+
+ private Watch watch;
+
+ @Override
+ public void run() {
+ MixedOperation<HorizontalPodAutoscaler, HorizontalPodAutoscalerList, DoneableHorizontalPodAutoscaler, Resource<HorizontalPodAutoscaler, DoneableHorizontalPodAutoscaler>> w = getEndpoint()
+ .getKubernetesClient().autoscaling().horizontalPodAutoscalers();
+ if (ObjectHelper.isNotEmpty(getEndpoint().getKubernetesConfiguration().getNamespace())) {
+ w.inNamespace(getEndpoint().getKubernetesConfiguration().getNamespace());
+ }
+ if (ObjectHelper.isNotEmpty(getEndpoint().getKubernetesConfiguration().getLabelKey())
+ && ObjectHelper.isNotEmpty(getEndpoint().getKubernetesConfiguration().getLabelValue())) {
+ w.withLabel(getEndpoint().getKubernetesConfiguration().getLabelKey(),
+ getEndpoint().getKubernetesConfiguration().getLabelValue());
+ }
+ if (ObjectHelper.isNotEmpty(getEndpoint().getKubernetesConfiguration().getResourceName())) {
+ w.withName(getEndpoint().getKubernetesConfiguration().getResourceName());
+ }
+ watch = w.watch(new Watcher<HorizontalPodAutoscaler>() {
+
+ @Override
+ public void eventReceived(io.fabric8.kubernetes.client.Watcher.Action action,
+ HorizontalPodAutoscaler resource) {
+ HPAEvent hpae = new HPAEvent(action, resource);
+ Exchange exchange = getEndpoint().createExchange();
+ exchange.getIn().setBody(hpae.getHpa());
+ exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_EVENT_ACTION, hpae.getAction());
+ exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_EVENT_TIMESTAMP,
+ System.currentTimeMillis());
+ try {
+ processor.process(exchange);
+ } catch (Exception e) {
+ getExceptionHandler().handleException("Error during processing", exchange, e);
+ }
+ }
+
+ @Override
+ public void onClose(KubernetesClientException cause) {
+ if (cause != null) {
+ LOG.error(cause.getMessage(), cause);
+ }
+
+ }
+ });
+ }
+
+ public Watch getWatch() {
+ return watch;
+ }
+
+ public void setWatch(Watch watch) {
+ this.watch = watch;
+ }
+ }
+}
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/hpa/KubernetesHPAEndpoint.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/hpa/KubernetesHPAEndpoint.java
new file mode 100644
index 0000000..d30d0fe
--- /dev/null
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/hpa/KubernetesHPAEndpoint.java
@@ -0,0 +1,52 @@
+/**
+ * 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.component.kubernetes.hpa;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.component.kubernetes.AbstractKubernetesEndpoint;
+import org.apache.camel.component.kubernetes.KubernetesConfiguration;
+import org.apache.camel.spi.UriEndpoint;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The Kubernetes HPA component provides a producer to execute kubernetes hpa operations
+ * and a consumer to consume pod events.
+ */
+@UriEndpoint(firstVersion = "2.23.0", scheme = "kubernetes-hpa", title = "Kubernetes HPA",
+ syntax = "kubernetes-hpa:masterUrl", consumerClass = KubernetesHPAConsumer.class, label = "container,cloud,paas")
+public class KubernetesHPAEndpoint extends AbstractKubernetesEndpoint {
+
+ private static final Logger LOG = LoggerFactory.getLogger(KubernetesHPAEndpoint.class);
+
+ public KubernetesHPAEndpoint(String uri, KubernetesHPAComponent component, KubernetesConfiguration config) {
+ super(uri, component, config);
+ }
+
+ @Override
+ public Producer createProducer() throws Exception {
+ return new KubernetesHPAProducer(this);
+ }
+
+ @Override
+ public Consumer createConsumer(Processor processor) throws Exception {
+ return new KubernetesHPAConsumer(this, processor);
+ }
+
+}
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/hpa/KubernetesHPAProducer.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/hpa/KubernetesHPAProducer.java
new file mode 100644
index 0000000..9924844
--- /dev/null
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/hpa/KubernetesHPAProducer.java
@@ -0,0 +1,202 @@
+/**
+ * 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.component.kubernetes.hpa;
+
+import java.util.Map;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.kubernetes.AbstractKubernetesEndpoint;
+import org.apache.camel.component.kubernetes.KubernetesConstants;
+import org.apache.camel.component.kubernetes.KubernetesOperations;
+import org.apache.camel.impl.DefaultProducer;
+import org.apache.camel.util.MessageHelper;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import io.fabric8.kubernetes.api.model.HorizontalPodAutoscaler;
+import io.fabric8.kubernetes.api.model.HorizontalPodAutoscalerBuilder;
+import io.fabric8.kubernetes.api.model.HorizontalPodAutoscalerList;
+import io.fabric8.kubernetes.api.model.HorizontalPodAutoscalerSpec;
+import io.fabric8.kubernetes.client.Watch;
+import io.fabric8.kubernetes.client.Watcher;
+import io.fabric8.kubernetes.client.dsl.FilterWatchListMultiDeletable;
+
+public class KubernetesHPAProducer extends DefaultProducer {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(KubernetesHPAProducer.class);
+
+ public KubernetesHPAProducer(AbstractKubernetesEndpoint endpoint) {
+ super(endpoint);
+ }
+
+ @Override
+ public AbstractKubernetesEndpoint getEndpoint() {
+ return (AbstractKubernetesEndpoint) super.getEndpoint();
+ }
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ String operation;
+
+ if (ObjectHelper.isEmpty(getEndpoint().getKubernetesConfiguration()
+ .getOperation())) {
+ operation = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_OPERATION, String.class);
+ } else {
+ operation = getEndpoint().getKubernetesConfiguration()
+ .getOperation();
+ }
+
+ switch (operation) {
+
+ case KubernetesOperations.LIST_HPA:
+ doList(exchange, operation);
+ break;
+
+ case KubernetesOperations.LIST_HPA_BY_LABELS_OPERATION:
+ doListHPAByLabel(exchange, operation);
+ break;
+
+ case KubernetesOperations.GET_HPA_OPERATION:
+ doGetHPA(exchange, operation);
+ break;
+
+ case KubernetesOperations.CREATE_HPA_OPERATION:
+ doCreateHPA(exchange, operation);
+ break;
+
+ case KubernetesOperations.DELETE_HPA_OPERATION:
+ doDeleteHPA(exchange, operation);
+ break;
+
+ default:
+ throw new IllegalArgumentException("Unsupported operation "
+ + operation);
+ }
+ }
+
+ protected void doList(Exchange exchange, String operation) throws Exception {
+ HorizontalPodAutoscalerList hpaList = getEndpoint().getKubernetesClient().autoscaling().horizontalPodAutoscalers().list();
+
+ MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
+ exchange.getOut().setBody(hpaList.getItems());
+ }
+
+ protected void doListHPAByLabel(Exchange exchange, String operation) {
+ Map<String, String> labels = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_PODS_LABELS, Map.class);
+ if (ObjectHelper.isEmpty(labels)) {
+ LOG.error("Get HPA by labels require specify a labels set");
+ throw new IllegalArgumentException(
+ "Get HPA by labels require specify a labels set");
+ }
+
+ FilterWatchListMultiDeletable<HorizontalPodAutoscaler, HorizontalPodAutoscalerList, Boolean, Watch, Watcher<HorizontalPodAutoscaler>> hpas = getEndpoint().getKubernetesClient().autoscaling().horizontalPodAutoscalers();
+ for (Map.Entry<String, String> entry : labels.entrySet()) {
+ hpas.withLabel(entry.getKey(), entry.getValue());
+ }
+ HorizontalPodAutoscalerList hpaList = hpas.list();
+
+ MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
+ exchange.getOut().setBody(hpaList.getItems());
+ }
+
+ protected void doGetHPA(Exchange exchange, String operation)
+ throws Exception {
+ HorizontalPodAutoscaler hpa = null;
+ String podName = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_HPA_NAME, String.class);
+ String namespaceName = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
+ if (ObjectHelper.isEmpty(podName)) {
+ LOG.error("Get a specific hpa require specify an hpa name");
+ throw new IllegalArgumentException(
+ "Get a specific hpa require specify an hpa name");
+ }
+ if (ObjectHelper.isEmpty(namespaceName)) {
+ LOG.error("Get a specific hpa require specify a namespace name");
+ throw new IllegalArgumentException(
+ "Get a specific hpa require specify a namespace name");
+ }
+ hpa = getEndpoint().getKubernetesClient().autoscaling().horizontalPodAutoscalers()
+ .inNamespace(namespaceName).withName(podName).get();
+
+ MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
+ exchange.getOut().setBody(hpa);
+ }
+
+ protected void doCreateHPA(Exchange exchange, String operation)
+ throws Exception {
+ HorizontalPodAutoscaler hpa = null;
+ String hpaName = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_HPA_NAME, String.class);
+ String namespaceName = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
+ HorizontalPodAutoscalerSpec hpaSpec = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_HPA_SPEC, HorizontalPodAutoscalerSpec.class);
+ if (ObjectHelper.isEmpty(hpaName)) {
+ LOG.error("Create a specific hpa require specify a hpa name");
+ throw new IllegalArgumentException(
+ "Create a specific hpa require specify a hpa name");
+ }
+ if (ObjectHelper.isEmpty(namespaceName)) {
+ LOG.error("Create a specific hpa require specify a namespace name");
+ throw new IllegalArgumentException(
+ "Create a specific hpa require specify a namespace name");
+ }
+ if (ObjectHelper.isEmpty(hpaSpec)) {
+ LOG.error("Create a specific hpa require specify a hpa spec bean");
+ throw new IllegalArgumentException(
+ "Create a specific hpa require specify a hpa spec bean");
+ }
+ Map<String, String> labels = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_PODS_LABELS, Map.class);
+ HorizontalPodAutoscaler hpaCreating = new HorizontalPodAutoscalerBuilder().withNewMetadata()
+ .withName(hpaName).withLabels(labels).endMetadata()
+ .withSpec(hpaSpec).build();
+ hpa = getEndpoint().getKubernetesClient().autoscaling().horizontalPodAutoscalers()
+ .inNamespace(namespaceName).create(hpaCreating);
+
+ MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
+ exchange.getOut().setBody(hpa);
+ }
+
+ protected void doDeleteHPA(Exchange exchange, String operation)
+ throws Exception {
+ String hpaName = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_HPA_NAME, String.class);
+ String namespaceName = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
+ if (ObjectHelper.isEmpty(hpaName)) {
+ LOG.error("Delete a specific hpa require specify a hpa name");
+ throw new IllegalArgumentException(
+ "Delete a specific hpa require specify a hpa name");
+ }
+ if (ObjectHelper.isEmpty(namespaceName)) {
+ LOG.error("Delete a specific hpa require specify a namespace name");
+ throw new IllegalArgumentException(
+ "Delete a specific hpa require specify a namespace name");
+ }
+ boolean hpaDeleted = getEndpoint().getKubernetesClient().autoscaling().horizontalPodAutoscalers()
+ .inNamespace(namespaceName).withName(hpaName).delete();
+
+ MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
+ exchange.getOut().setBody(hpaDeleted);
+ }
+}
diff --git a/components/camel-kubernetes/src/main/resources/META-INF/services/org/apache/camel/component/kubernetes-hpa b/components/camel-kubernetes/src/main/resources/META-INF/services/org/apache/camel/component/kubernetes-hpa
new file mode 100644
index 0000000..e748dd3
--- /dev/null
+++ b/components/camel-kubernetes/src/main/resources/META-INF/services/org/apache/camel/component/kubernetes-hpa
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+class=org.apache.camel.component.kubernetes.hpa.KubernetesHPAComponent
diff --git a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesHPAProducerTest.java b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesHPAProducerTest.java
new file mode 100644
index 0000000..5f5e0ed
--- /dev/null
+++ b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesHPAProducerTest.java
@@ -0,0 +1,131 @@
+/**
+ * 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.component.kubernetes.producer;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.kubernetes.KubernetesConstants;
+import org.apache.camel.component.kubernetes.KubernetesTestSupport;
+import org.apache.camel.impl.JndiRegistry;
+import org.junit.Rule;
+import org.junit.Test;
+
+import io.fabric8.kubernetes.api.model.HorizontalPodAutoscaler;
+import io.fabric8.kubernetes.api.model.HorizontalPodAutoscalerBuilder;
+import io.fabric8.kubernetes.api.model.HorizontalPodAutoscalerListBuilder;
+import io.fabric8.kubernetes.api.model.PodListBuilder;
+import io.fabric8.kubernetes.client.server.mock.KubernetesServer;
+
+public class KubernetesHPAProducerTest extends KubernetesTestSupport {
+
+ @Rule
+ public KubernetesServer server = new KubernetesServer();
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry registry = super.createRegistry();
+ registry.bind("kubernetesClient", server.getClient());
+ return registry;
+ }
+
+ @Test
+ public void listTest() throws Exception {
+ server.expect().withPath("/apis/autoscaling/v1/namespaces/test/horizontalpodautoscalers").andReturn(200, new HorizontalPodAutoscalerListBuilder()
+ .addNewItem().and().addNewItem().and().addNewItem().and().build()).once();
+ List<HorizontalPodAutoscaler> result = template.requestBody("direct:list", "", List.class);
+
+ assertEquals(3, result.size());
+ }
+
+ @Test
+ public void listByLabelsTest() throws Exception {
+ server.expect().withPath("/apis/autoscaling/v1/namespaces/test/horizontalpodautoscalers?labelSelector=" + toUrlEncoded("key1=value1,key2=value2"))
+ .andReturn(200, new PodListBuilder().addNewItem().and().addNewItem().and().addNewItem().and().build()).once();
+ Exchange ex = template.request("direct:listByLabels", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ Map<String, String> labels = new HashMap<>();
+ labels.put("key1", "value1");
+ labels.put("key2", "value2");
+ exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_PODS_LABELS, labels);
+ }
+ });
+
+ List<HorizontalPodAutoscaler> result = ex.getOut().getBody(List.class);
+
+ assertEquals(3, result.size());
+ }
+
+ @Test
+ public void getHPATest() throws Exception {
+ HorizontalPodAutoscaler hpa1 = new HorizontalPodAutoscalerBuilder().withNewMetadata().withName("hpa1").withNamespace("test").and().build();
+ HorizontalPodAutoscaler hpa2 = new HorizontalPodAutoscalerBuilder().withNewMetadata().withName("hpa2").withNamespace("ns1").and().build();
+
+ server.expect().withPath("/apis/autoscaling/v1/namespaces/test/horizontalpodautoscalers/hpa1").andReturn(200, hpa1).once();
+ server.expect().withPath("/apis/autoscaling/v1/namespaces/ns1/horizontalpodautoscalers/hpa2").andReturn(200, hpa2).once();
+ Exchange ex = template.request("direct:getHPA", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "test");
+ exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_HPA_NAME, "hpa1");
+ }
+ });
+
+ HorizontalPodAutoscaler result = ex.getOut().getBody(HorizontalPodAutoscaler.class);
+
+ assertEquals("hpa1", result.getMetadata().getName());
+ }
+
+ @Test
+ public void deleteHPATest() throws Exception {
+ HorizontalPodAutoscaler hpa1 = new HorizontalPodAutoscalerBuilder().withNewMetadata().withName("hpa1").withNamespace("test").and().build();
+ server.expect().withPath("/apis/autoscaling/v1/namespaces/test/horizontalpodautoscalers/hpa1").andReturn(200, hpa1).once();
+
+ Exchange ex = template.request("direct:deleteHPA", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "test");
+ exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_HPA_NAME, "hpa1");
+ }
+ });
+
+ boolean podDeleted = ex.getOut().getBody(Boolean.class);
+
+ assertTrue(podDeleted);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:list").to("kubernetes-hpa:///?kubernetesClient=#kubernetesClient&operation=listHPA");
+ from("direct:listByLabels").to("kubernetes-hpa:///?kubernetesClient=#kubernetesClient&operation=listHPAByLabels");
+ from("direct:getHPA").to("kubernetes-hpa:///?kubernetesClient=#kubernetesClient&operation=getHPA");
+ from("direct:deleteHPA").to("kubernetes-hpa:///?kubernetesClient=#kubernetesClient&operation=deleteHPA");
+ }
+ };
+ }
+}
diff --git a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesPodsProducerTest.java b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesPodsProducerTest.java
index fc727ad..fbbd180 100644
--- a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesPodsProducerTest.java
+++ b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesPodsProducerTest.java
@@ -20,11 +20,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import io.fabric8.kubernetes.api.model.Pod;
-import io.fabric8.kubernetes.api.model.PodBuilder;
-import io.fabric8.kubernetes.api.model.PodListBuilder;
-import io.fabric8.kubernetes.client.server.mock.KubernetesServer;
-
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
@@ -34,96 +29,106 @@ import org.apache.camel.impl.JndiRegistry;
import org.junit.Rule;
import org.junit.Test;
+import io.fabric8.kubernetes.api.model.Pod;
+import io.fabric8.kubernetes.api.model.PodBuilder;
+import io.fabric8.kubernetes.api.model.PodListBuilder;
+import io.fabric8.kubernetes.client.server.mock.KubernetesServer;
+
public class KubernetesPodsProducerTest extends KubernetesTestSupport {
- @Rule
- public KubernetesServer server = new KubernetesServer();
-
- @Override
- protected JndiRegistry createRegistry() throws Exception {
- JndiRegistry registry = super.createRegistry();
- registry.bind("kubernetesClient", server.getClient());
- return registry;
- }
-
- @Test
- public void listTest() throws Exception {
- server.expect().withPath("/api/v1/pods").andReturn(200, new PodListBuilder().addNewItem().and().addNewItem().and().addNewItem().and().build()).once();
- List<Pod> result = template.requestBody("direct:list", "", List.class);
-
- assertEquals(3, result.size());
- }
-
- @Test
- public void listByLabelsTest() throws Exception {
- server.expect().withPath("/api/v1/pods?labelSelector=" + toUrlEncoded("key1=value1,key2=value2"))
- .andReturn(200, new PodListBuilder().addNewItem().and().addNewItem().and().addNewItem().and().build()).once();
- Exchange ex = template.request("direct:listByLabels", new Processor() {
-
- @Override
- public void process(Exchange exchange) throws Exception {
- Map<String, String> labels = new HashMap<>();
- labels.put("key1", "value1");
- labels.put("key2", "value2");
- exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_PODS_LABELS, labels);
- }
- });
-
- List<Pod> result = ex.getOut().getBody(List.class);
-
- assertEquals(3, result.size());
- }
-
- @Test
- public void getPodTest() throws Exception {
- Pod pod1 = new PodBuilder().withNewMetadata().withName("pod1").withNamespace("test").and().build();
- Pod pod2 = new PodBuilder().withNewMetadata().withName("pod2").withNamespace("ns1").and().build();
-
- server.expect().withPath("/api/v1/namespaces/test/pods/pod1").andReturn(200, pod1).once();
- server.expect().withPath("/api/v1/namespaces/ns1/pods/pod2").andReturn(200, pod2).once();
- Exchange ex = template.request("direct:getPod", new Processor() {
-
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "test");
- exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_POD_NAME, "pod1");
- }
- });
-
- Pod result = ex.getOut().getBody(Pod.class);
-
- assertEquals("pod1", result.getMetadata().getName());
- }
-
- @Test
- public void deletePod() throws Exception {
- Pod pod1 = new PodBuilder().withNewMetadata().withName("pod1").withNamespace("test").and().build();
- server.expect().withPath("/api/v1/namespaces/test/pods/pod1").andReturn(200, pod1).once();
-
- Exchange ex = template.request("direct:deletePod", new Processor() {
-
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "test");
- exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_POD_NAME, "pod1");
- }
- });
-
- boolean podDeleted = ex.getOut().getBody(Boolean.class);
-
- assertTrue(podDeleted);
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- @Override
- public void configure() throws Exception {
- from("direct:list").to("kubernetes-pods:///?kubernetesClient=#kubernetesClient&operation=listPods");
- from("direct:listByLabels").to("kubernetes-pods:///?kubernetesClient=#kubernetesClient&operation=listPodsByLabels");
- from("direct:getPod").to("kubernetes-pods:///?kubernetesClient=#kubernetesClient&operation=getPod");
- from("direct:deletePod").to("kubernetes-pods:///?kubernetesClient=#kubernetesClient&operation=deletePod");
- }
- };
- }
+ @Rule
+ public KubernetesServer server = new KubernetesServer();
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry registry = super.createRegistry();
+ registry.bind("kubernetesClient", server.getClient());
+ return registry;
+ }
+
+ @Test
+ public void listTest() throws Exception {
+ server.expect().withPath("/api/v1/pods")
+ .andReturn(200, new PodListBuilder().addNewItem().and().addNewItem().and().addNewItem().and().build())
+ .once();
+ List<Pod> result = template.requestBody("direct:list", "", List.class);
+
+ assertEquals(3, result.size());
+ }
+
+ @Test
+ public void listByLabelsTest() throws Exception {
+ server.expect().withPath("/api/v1/pods?labelSelector=" + toUrlEncoded("key1=value1,key2=value2"))
+ .andReturn(200, new PodListBuilder().addNewItem().and().addNewItem().and().addNewItem().and().build())
+ .once();
+ Exchange ex = template.request("direct:listByLabels", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ Map<String, String> labels = new HashMap<>();
+ labels.put("key1", "value1");
+ labels.put("key2", "value2");
+ exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_PODS_LABELS, labels);
+ }
+ });
+
+ List<Pod> result = ex.getOut().getBody(List.class);
+
+ assertEquals(3, result.size());
+ }
+
+ @Test
+ public void getPodTest() throws Exception {
+ Pod pod1 = new PodBuilder().withNewMetadata().withName("pod1").withNamespace("test").and().build();
+ Pod pod2 = new PodBuilder().withNewMetadata().withName("pod2").withNamespace("ns1").and().build();
+
+ server.expect().withPath("/api/v1/namespaces/test/pods/pod1").andReturn(200, pod1).once();
+ server.expect().withPath("/api/v1/namespaces/ns1/pods/pod2").andReturn(200, pod2).once();
+ Exchange ex = template.request("direct:getPod", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "test");
+ exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_POD_NAME, "pod1");
+ }
+ });
+
+ Pod result = ex.getOut().getBody(Pod.class);
+
+ assertEquals("pod1", result.getMetadata().getName());
+ }
+
+ @Test
+ public void deletePod() throws Exception {
+ Pod pod1 = new PodBuilder().withNewMetadata().withName("pod1").withNamespace("test").and().build();
+ server.expect().withPath("/api/v1/namespaces/test/pods/pod1").andReturn(200, pod1).once();
+
+ Exchange ex = template.request("direct:deletePod", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "test");
+ exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_POD_NAME, "pod1");
+ }
+ });
+
+ boolean podDeleted = ex.getOut().getBody(Boolean.class);
+
+ assertTrue(podDeleted);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:list").to("kubernetes-pods:///?kubernetesClient=#kubernetesClient&operation=listPods");
+ from("direct:listByLabels")
+ .to("kubernetes-pods:///?kubernetesClient=#kubernetesClient&operation=listPodsByLabels");
+ from("direct:getPod").to("kubernetes-pods:///?kubernetesClient=#kubernetesClient&operation=getPod");
+ from("direct:deletePod")
+ .to("kubernetes-pods:///?kubernetesClient=#kubernetesClient&operation=deletePod");
+ }
+ };
+ }
}
diff --git a/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/java/org/apache/camel/component/kubernetes/hpa/springboot/KubernetesHPAComponentAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/java/org/apache/camel/component/kubernetes/hpa/springboot/KubernetesHPAComponentAutoConfiguration.java
new file mode 100644
index 0000000..3c82897
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/java/org/apache/camel/component/kubernetes/hpa/springboot/KubernetesHPAComponentAutoConfiguration.java
@@ -0,0 +1,129 @@
+/**
+ * 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.component.kubernetes.hpa.springboot;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Generated;
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.kubernetes.hpa.KubernetesHPAComponent;
+import org.apache.camel.spi.ComponentCustomizer;
+import org.apache.camel.spi.HasId;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.apache.camel.spring.boot.ComponentConfigurationProperties;
+import org.apache.camel.spring.boot.util.CamelPropertiesHelper;
+import org.apache.camel.spring.boot.util.ConditionalOnCamelContextAndAutoConfigurationBeans;
+import org.apache.camel.spring.boot.util.GroupCondition;
+import org.apache.camel.spring.boot.util.HierarchicalPropertiesEvaluator;
+import org.apache.camel.util.IntrospectionSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Conditional;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Lazy;
+
+/**
+ * Generated by camel-package-maven-plugin - do not edit this file!
+ */
+@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo")
+@Configuration
+@Conditional({ConditionalOnCamelContextAndAutoConfigurationBeans.class,
+ KubernetesHPAComponentAutoConfiguration.GroupConditions.class})
+@AutoConfigureAfter(CamelAutoConfiguration.class)
+@EnableConfigurationProperties({ComponentConfigurationProperties.class,
+ KubernetesHPAComponentConfiguration.class})
+public class KubernetesHPAComponentAutoConfiguration {
+
+ private static final Logger LOGGER = LoggerFactory
+ .getLogger(KubernetesHPAComponentAutoConfiguration.class);
+ @Autowired
+ private ApplicationContext applicationContext;
+ @Autowired
+ private CamelContext camelContext;
+ @Autowired
+ private KubernetesHPAComponentConfiguration configuration;
+ @Autowired(required = false)
+ private List<ComponentCustomizer<KubernetesHPAComponent>> customizers;
+
+ static class GroupConditions extends GroupCondition {
+ public GroupConditions() {
+ super("camel.component", "camel.component.kubernetes-hpa");
+ }
+ }
+
+ @Lazy
+ @Bean(name = "kubernetes-hpa-component")
+ @ConditionalOnMissingBean(KubernetesHPAComponent.class)
+ public KubernetesHPAComponent configureKubernetesHPAComponent()
+ throws Exception {
+ KubernetesHPAComponent component = new KubernetesHPAComponent();
+ component.setCamelContext(camelContext);
+ Map<String, Object> parameters = new HashMap<>();
+ IntrospectionSupport.getProperties(configuration, parameters, null,
+ false);
+ for (Map.Entry<String, Object> entry : parameters.entrySet()) {
+ Object value = entry.getValue();
+ Class<?> paramClass = value.getClass();
+ if (paramClass.getName().endsWith("NestedConfiguration")) {
+ Class nestedClass = null;
+ try {
+ nestedClass = (Class) paramClass.getDeclaredField(
+ "CAMEL_NESTED_CLASS").get(null);
+ HashMap<String, Object> nestedParameters = new HashMap<>();
+ IntrospectionSupport.getProperties(value, nestedParameters,
+ null, false);
+ Object nestedProperty = nestedClass.newInstance();
+ CamelPropertiesHelper.setCamelProperties(camelContext,
+ nestedProperty, nestedParameters, false);
+ entry.setValue(nestedProperty);
+ } catch (NoSuchFieldException e) {
+ }
+ }
+ }
+ CamelPropertiesHelper.setCamelProperties(camelContext, component,
+ parameters, false);
+ if (ObjectHelper.isNotEmpty(customizers)) {
+ for (ComponentCustomizer<KubernetesHPAComponent> customizer : customizers) {
+ boolean useCustomizer = (customizer instanceof HasId)
+ ? HierarchicalPropertiesEvaluator.evaluate(
+ applicationContext.getEnvironment(),
+ "camel.component.customizer",
+ "camel.component.kubernetes-hpa.customizer",
+ ((HasId) customizer).getId())
+ : HierarchicalPropertiesEvaluator.evaluate(
+ applicationContext.getEnvironment(),
+ "camel.component.customizer",
+ "camel.component.kubernetes-hpa.customizer");
+ if (useCustomizer) {
+ LOGGER.debug("Configure component {}, with customizer {}",
+ component, customizer);
+ customizer.customize(component);
+ }
+ }
+ }
+ return component;
+ }
+}
\ No newline at end of file
diff --git a/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/java/org/apache/camel/component/kubernetes/hpa/springboot/KubernetesHPAComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/java/org/apache/camel/component/kubernetes/hpa/springboot/KubernetesHPAComponentConfiguration.java
new file mode 100644
index 0000000..d65cabc
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/java/org/apache/camel/component/kubernetes/hpa/springboot/KubernetesHPAComponentConfiguration.java
@@ -0,0 +1,50 @@
+/**
+ * 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.component.kubernetes.hpa.springboot;
+
+import javax.annotation.Generated;
+import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+/**
+ * The Kubernetes HPA component provides a producer to execute kubernetes hpa
+ * operations and a consumer to consume pod events.
+ *
+ * Generated by camel-package-maven-plugin - do not edit this file!
+ */
+@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo")
+@ConfigurationProperties(prefix = "camel.component.kubernetes-hpa")
+public class KubernetesHPAComponentConfiguration
+ extends
+ ComponentConfigurationPropertiesCommon {
+
+ /**
+ * Whether the component should resolve property placeholders on itself when
+ * starting. Only properties which are of String type can use property
+ * placeholders.
+ */
+ private Boolean resolvePropertyPlaceholders = true;
+
+ public Boolean getResolvePropertyPlaceholders() {
+ return resolvePropertyPlaceholders;
+ }
+
+ public void setResolvePropertyPlaceholders(
+ Boolean resolvePropertyPlaceholders) {
+ this.resolvePropertyPlaceholders = resolvePropertyPlaceholders;
+ }
+}
\ No newline at end of file
diff --git a/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/resources/META-INF/spring.factories b/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/resources/META-INF/spring.factories
index 2cd83c3..0a8bdfd 100644
--- a/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/resources/META-INF/spring.factories
+++ b/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/resources/META-INF/spring.factories
@@ -32,7 +32,9 @@ org.apache.camel.component.kubernetes.persistent_volumes_claims.springboot.Kuber
org.apache.camel.component.kubernetes.deployments.springboot.KubernetesDeploymentsComponentAutoConfiguration,\
org.apache.camel.component.kubernetes.service_accounts.springboot.KubernetesServiceAccountsComponentAutoConfiguration,\
org.apache.camel.component.openshift.builds.springboot.OpenshiftBuildsComponentAutoConfiguration,\
-org.apache.camel.component.openshift.build_configs.springboot.OpenshiftBuildConfigsComponentAutoConfiguration
+org.apache.camel.component.openshift.build_configs.springboot.OpenshiftBuildConfigsComponentAutoConfiguration,\
+org.apache.camel.component.kubernetes.hpa.springboot.KubernetesHPAComponentAutoConfiguration
+