You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ma...@apache.org on 2022/06/21 23:55:01 UTC
[camel-karavan] branch main updated: Saas feature8 (#386)
This is an automated email from the ASF dual-hosted git repository.
marat pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-karavan.git
The following commit(s) were added to refs/heads/main by this push:
new b0c0a28 Saas feature8 (#386)
b0c0a28 is described below
commit b0c0a2805d03fe2c99da184267d5a131bcc8f551
Author: Marat Gubaidullin <ma...@gmail.com>
AuthorDate: Tue Jun 21 19:54:56 2022 -0400
Saas feature8 (#386)
* PVC for Pod
* Tekton client and API
---
karavan-app/pom.xml | 9 +++
.../apache/camel/karavan/api/TektonResource.java | 54 +++++++++++++++++
.../camel/karavan/service/KubernetesService.java | 69 ++++++++++++++++++++++
3 files changed, 132 insertions(+)
diff --git a/karavan-app/pom.xml b/karavan-app/pom.xml
index 4649aa7..d1a67ed 100644
--- a/karavan-app/pom.xml
+++ b/karavan-app/pom.xml
@@ -79,6 +79,15 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-infinispan-client</artifactId>
</dependency>
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-kubernetes-client</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.fabric8</groupId>
+ <artifactId>tekton-client</artifactId>
+ <version>5.12.2</version>
+ </dependency>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-core</artifactId>
diff --git a/karavan-app/src/main/java/org/apache/camel/karavan/api/TektonResource.java b/karavan-app/src/main/java/org/apache/camel/karavan/api/TektonResource.java
new file mode 100644
index 0000000..aa71762
--- /dev/null
+++ b/karavan-app/src/main/java/org/apache/camel/karavan/api/TektonResource.java
@@ -0,0 +1,54 @@
+/*
+ * 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.karavan.api;
+
+import org.apache.camel.karavan.model.Project;
+import org.apache.camel.karavan.model.ProjectFile;
+import org.apache.camel.karavan.service.InfinispanService;
+import org.apache.camel.karavan.service.KubernetesService;
+import org.jboss.logging.Logger;
+
+import javax.inject.Inject;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import java.util.List;
+
+@Path("/tekton")
+public class TektonResource {
+
+ @Inject
+ InfinispanService infinispanService;
+
+ @Inject
+ KubernetesService kubernetesService;
+
+ private static final Logger LOGGER = Logger.getLogger(TektonResource.class.getName());
+
+ @POST
+ @Produces(MediaType.APPLICATION_JSON)
+ @Consumes(MediaType.APPLICATION_JSON)
+ public Project push(@HeaderParam("username") String username, Project project) throws Exception {
+ Project p = infinispanService.getProject(project.getProjectId());
+ List<ProjectFile> files = infinispanService.getProjectFiles(project.getProjectId());
+ String pipelineRunId = kubernetesService.createPipelineRun(project);
+ return p;
+ }
+}
\ No newline at end of file
diff --git a/karavan-app/src/main/java/org/apache/camel/karavan/service/KubernetesService.java b/karavan-app/src/main/java/org/apache/camel/karavan/service/KubernetesService.java
new file mode 100644
index 0000000..1004343
--- /dev/null
+++ b/karavan-app/src/main/java/org/apache/camel/karavan/service/KubernetesService.java
@@ -0,0 +1,69 @@
+/*
+ * 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.karavan.service;
+
+import io.fabric8.kubernetes.api.model.ObjectMetaBuilder;
+import io.fabric8.kubernetes.client.DefaultKubernetesClient;
+import io.fabric8.tekton.client.DefaultTektonClient;
+import io.fabric8.tekton.pipeline.v1beta1.ParamBuilder;
+import io.fabric8.tekton.pipeline.v1beta1.PipelineRefBuilder;
+import io.fabric8.tekton.pipeline.v1beta1.PipelineRunBuilder;
+import io.fabric8.tekton.pipeline.v1beta1.PipelineRunSpecBuilder;
+import org.apache.camel.karavan.model.Project;
+import org.eclipse.microprofile.config.inject.ConfigProperty;
+import org.jboss.logging.Logger;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Produces;
+import java.util.Map;
+
+@ApplicationScoped
+public class KubernetesService {
+
+ @ConfigProperty(name = "karavan.config.runtime")
+ String runtime;
+
+ @Produces
+ public DefaultTektonClient tektonClient() {
+ return new DefaultTektonClient(new DefaultKubernetesClient());
+ }
+
+ private static final Logger LOGGER = Logger.getLogger(KubernetesService.class.getName());
+
+ public String createPipelineRun(Project project) throws Exception {
+
+ PipelineRunBuilder pipelineRun = new PipelineRunBuilder()
+ .withMetadata(
+ new ObjectMetaBuilder()
+ .withGenerateName("karavan-" + project.getProjectId() + "-")
+ .withLabels(Map.of(
+ "karavan-project-id", project.getProjectId(),
+ "tekton.dev/pipeline", "karavan-quarkus"
+ )).build()
+ )
+ .withSpec(
+ new PipelineRunSpecBuilder()
+ .withPipelineRef(
+ new PipelineRefBuilder().withName("karavan-quarkus").build()
+ )
+ .withServiceAccountName("pipeline")
+ .withParams(new ParamBuilder().withName("PROJECT_NAME").withNewValue(project.getProjectId()).build())
+ .build()
+ );
+ return tektonClient().v1beta1().pipelineRuns().create(pipelineRun.build()).getMetadata().getName();
+ }
+}