christophd commented on code in PR #14757: URL: https://github.com/apache/camel/pull/14757#discussion_r1669875502
########## dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesRun.java: ########## @@ -0,0 +1,390 @@ +/* + * 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.dsl.jbang.core.commands.kubernetes; + +import java.io.File; +import java.io.FileFilter; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import io.fabric8.kubernetes.api.model.Pod; +import org.apache.camel.RuntimeCamelException; +import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain; +import org.apache.camel.dsl.jbang.core.commands.kubernetes.traits.BaseTrait; +import org.apache.camel.dsl.jbang.core.common.RuntimeCompletionCandidates; +import org.apache.camel.dsl.jbang.core.common.RuntimeType; +import org.apache.camel.dsl.jbang.core.common.RuntimeTypeConverter; +import org.apache.camel.impl.DefaultCamelContext; +import org.apache.camel.support.FileWatcherResourceReloadStrategy; +import org.apache.camel.util.FileUtil; +import org.apache.camel.util.IOHelper; +import picocli.CommandLine; + +@CommandLine.Command(name = "run", description = "Run Camel application on Kubernetes", sortOptions = false) +public class KubernetesRun extends KubernetesBaseCommand { + + @CommandLine.Parameters(description = "The Camel file(s) to run.", + arity = "0..9", paramLabel = "<files>") + String[] filePaths; + + @CommandLine.Option(names = { "--trait-profile" }, description = "The trait profile to use for the deployment.") + String traitProfile; + + @CommandLine.Option(names = { "--dependency", "-d" }, + description = "Adds dependency that should be included, use \"camel:\" prefix for a Camel component, \"mvn:org.my:app:1.0\" for a Maven dependency.") + String[] dependencies; + + @CommandLine.Option(names = { "--property", "-p" }, + description = "Add a runtime property or properties file from a path, a config map or a secret (syntax: [my-key=my-value|file:/path/to/my-conf.properties|[configmap|secret]:name]).") + String[] properties; + + @CommandLine.Option(names = { "--config" }, + description = "Add a runtime configuration from a ConfigMap or a Secret (syntax: [configmap|secret]:name[/key], where name represents the configmap/secret name and key optionally represents the configmap/secret key to be filtered).") + String[] configs; + + @CommandLine.Option(names = { "--resource" }, + description = "Add a runtime resource from a Configmap or a Secret (syntax: [configmap|secret]:name[/key][@path], where name represents the configmap/secret name, key optionally represents the configmap/secret key to be filtered and path represents the destination path).") + String[] resources; + + @CommandLine.Option(names = { "--open-api" }, description = "Add an OpenAPI spec (syntax: [configmap|file]:name).") + String[] openApis; + + @CommandLine.Option(names = { "--env", "-e" }, + description = "Set an environment variable in the integration container, for instance \"-e MY_VAR=my-value\".") + String[] envVars; + + @CommandLine.Option(names = { "--volume", "-v" }, + description = "Mount a volume into the integration container, for instance \"-v pvcname:/container/path\".") + String[] volumes; + + @CommandLine.Option(names = { "--connect", "-c" }, + description = "A Service that the integration should bind to, specified as [[apigroup/]version:]kind:[namespace/]name.") + String[] connects; + + @CommandLine.Option(names = { "--annotation" }, + description = "Add an annotation to the integration. Use name values pairs like \"--annotation my.company=hello\".") + String[] annotations; + + @CommandLine.Option(names = { "--label" }, + description = "Add a label to the integration. Use name values pairs like \"--label my.company=hello\".") + String[] labels; + + @CommandLine.Option(names = { "--traits", "-t" }, + description = "Add a trait configuration to the integration. Use name values pairs like \"--trait trait.name.config=hello\".") + String[] traits; + + @CommandLine.Option(names = { "--wait", "-w" }, description = "Wait for the deployment to become ready.") + boolean wait; + + @CommandLine.Option(names = { "--logs", "-l" }, description = "Print logs after Camel application has been started.") + boolean logs; + + @CommandLine.Option(names = { "--reload", "--dev" }, + description = "Enables dev mode (live reload when source files are updated and saved)") + boolean dev; + + @CommandLine.Option(names = { "--output", "-o" }, + description = "Just output the generated integration custom resource (supports: yaml or json).") + String output; + + // Export options + + @CommandLine.Option(names = { "--image" }, + description = "The image name to be built.") + String image; + + @CommandLine.Option(names = { "--image-registry" }, + defaultValue = "quay.io", + description = "The image registry to hold the app container image.") + String imageRegistry = "quay.io"; + + @CommandLine.Option(names = { "--image-group" }, + description = "The image registry group used to push images to.") + String imageGroup; + + @CommandLine.Option(names = { "--image-platforms" }, + description = "List of target platforms. Each platform is defined using the pattern.") + String imagePlatforms; + + @CommandLine.Option(names = { "--gav" }, description = "The Maven group:artifact:version") + String gav; + + @CommandLine.Option(names = { "--runtime" }, + completionCandidates = RuntimeCompletionCandidates.class, + defaultValue = "quarkus", + converter = RuntimeTypeConverter.class, + description = "Runtime (${COMPLETION-CANDIDATES})") + RuntimeType runtime = RuntimeType.quarkus; + + @CommandLine.Option(names = { "--quarkus-version" }, description = "Quarkus Platform version", + defaultValue = RuntimeType.QUARKUS_VERSION) + String quarkusVersion = RuntimeType.QUARKUS_VERSION; + + public KubernetesRun(CamelJBangMain main) { + super(main); + } + + public Integer doCall() throws Exception { + String projectName = getProjectName(); + + String workingDir = RUN_PLATFORM_DIR + "/" + projectName; + + KubernetesExport export = new KubernetesExport( + getMain(), new KubernetesExport.ExportConfigurer( + runtime, + quarkusVersion, + true, + true, + false, + workingDir, + List.of(filePaths), + gav, + true, + true, + false, + false, + "off")); + + export.image = image; + export.imageRegistry = imageRegistry; + export.imageGroup = imageGroup; + export.traitProfile = traitProfile; + export.dependencies = dependencies; + export.properties = properties; + export.configs = configs; + export.resources = resources; + export.openApis = openApis; + export.envVars = envVars; + export.volumes = volumes; + export.connects = connects; + export.annotations = annotations; + export.labels = labels; + export.traits = traits; + + printer().println("Exporting application ..."); + + int exit = export.export(); + if (exit != 0) { + printer().println("Project export failed!"); + return exit; + } + + if (output != null) { + if (RuntimeType.quarkus == runtime) { + exit = buildQuarkus(workingDir); + } else if (RuntimeType.springBoot == runtime) { + exit = buildSpringBoot(workingDir); + } + + if (exit != 0) { + printer().println("Project build failed!"); + return exit; + } + + File manifest; + switch (output) { + case "yaml" -> manifest = new File(workingDir, "target/kubernetes/kubernetes.yml"); + case "json" -> manifest = new File(workingDir, "target/kubernetes/kubernetes.json"); + default -> { + printer().printf("Unsupported output format '%s' (supported: yaml, json)%n", output); + return -1; + } + } + + try (FileInputStream fis = new FileInputStream(manifest)) { + printer().println(IOHelper.loadText(fis)); + } + + return 0; + } + + if (RuntimeType.quarkus == runtime) { + exit = deployQuarkus(workingDir); + } else if (RuntimeType.springBoot == runtime) { + exit = deploySpringBoot(workingDir); + } + + if (exit != 0) { + printer().println("Deployment to Kubernetes failed!"); + return exit; + } + + if (dev) { + DefaultCamelContext reloadContext = new DefaultCamelContext(false); + configureFileWatch(reloadContext, export, workingDir); + reloadContext.start(); + } + + if (dev || wait || logs) { Review Comment: No, it does not. This is a good idea. Let me see if I can add this, thx -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@camel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org