Skip to content

Commit

Permalink
VERBOSE_OPTION
Browse files Browse the repository at this point in the history
  • Loading branch information
mgubaidullin committed Nov 14, 2024
1 parent e15d717 commit 0369e19
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public class KaravanConstants {
public static final String DEV = "dev";
public static final String DEVMODE_IMAGE = "karavan.devmode.image";
public static final String DEVMODE_IMAGE_PULL_POLICY = "karavan.devmode.withImagePullPolicy";
public static final String ENV_VAR_JBANG_OPTIONS = "JBANG_OPTIONS";
public static final String ENV_VAR_VERBOSE_OPTION_NAME = "VERBOSE_OPTION";
public static final String ENV_VAR_VERBOSE_OPTION_VALUE = "--verbose";

public static final String LABEL_PART_OF = "app.kubernetes.io/part-of";
public static final String LABEL_TYPE = "org.apache.camel.karavan/type";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ public class DevModeResource {
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/{jBangOptions}")
public Response runProjectWithJBangOptions(Project project, @PathParam("jBangOptions") String jBangOptions) {
@Path("/{verbose}")
public Response runProjectWithJBangOptions(Project project, @PathParam("verbose") boolean verbose) {
try {
String containerName = projectService.runProjectWithJBangOptions(project, jBangOptions, Map.of(), Map.of());
String containerName = projectService.runProjectWithJBangOptions(project, verbose, Map.of(), Map.of());
if (containerName != null) {
return Response.ok(containerName).build();
} else {
Expand All @@ -73,7 +73,7 @@ public Response runProjectWithJBangOptions(Project project, @PathParam("jBangOpt
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response runProject(Project project) throws Exception {
return runProjectWithJBangOptions(project, "");
return runProjectWithJBangOptions(project, false);
}

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,24 @@ public class DockerForKaravan {
@Inject
DockerService dockerService;

public void runProjectInDevMode(String projectId, String jBangOptions, DockerComposeService composeService,
public void runProjectInDevMode(String projectId, Boolean verbose, DockerComposeService composeService,
Map<String, String> files, String projectDevmodeImage, Map<String, String> labels, Map<String, String> envVars) throws Exception {
Container c = createDevmodeContainer(projectId, jBangOptions, composeService, projectDevmodeImage, labels, envVars);
Container c = createDevmodeContainer(projectId, verbose, composeService, projectDevmodeImage, labels, envVars);
dockerService.runContainer(projectId);
dockerService.copyFiles(c.getId(), "/karavan/code", files, true);
}

protected Container createDevmodeContainer(String projectId, String jBangOptions, DockerComposeService compose,
protected Container createDevmodeContainer(String projectId, Boolean verbose, DockerComposeService compose,
String projectDevmodeImage, Map<String, String> labels, Map<String, String> envVars) throws InterruptedException {
LOGGER.infof("DevMode starting for %s with JBANG_OPTIONS=%s", projectId, jBangOptions);
LOGGER.infof("DevMode starting for %s with verbose=%s", projectId, verbose);

HealthCheck healthCheck = new HealthCheck().withTest(List.of("CMD", "curl", "-f", "http://localhost:8080/q/dev/health"))
.withInterval(10000000000L).withTimeout(10000000000L).withStartPeriod(10000000000L).withRetries(30);

List<String> env = new ArrayList<>(compose.getEnvironmentList());
envVars.forEach((k,v) -> env.add(k + "=" + v));
if (jBangOptions != null && !jBangOptions.trim().isEmpty()) {
env.add(ENV_VAR_JBANG_OPTIONS + "=" + jBangOptions);
if (verbose) {
env.add(ENV_VAR_VERBOSE_OPTION_NAME + "=" + ENV_VAR_VERBOSE_OPTION_VALUE);
}

if (createM2.orElse(false)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public List<String> getServices(String namespace) {
return result;
}

public void runDevModeContainer(Project project, String jBangOptions, Map<String, String> files, String projectDevmodeImage, String deploymentFragment, Map<String, String> labels, Map<String, String> envVars) {
public void runDevModeContainer(Project project, Boolean verbose, Map<String, String> files, String projectDevmodeImage, String deploymentFragment, Map<String, String> labels, Map<String, String> envVars) {
String name = project.getProjectId();
Map<String, String> podLabels = new HashMap<>(labels);
podLabels.putAll(getLabels(name, project, ContainerType.devmode));
Expand All @@ -346,7 +346,7 @@ public void runDevModeContainer(Project project, String jBangOptions, Map<String
}
Pod old = client.pods().inNamespace(getNamespace()).withName(name).get();
if (old == null) {
Pod pod = getDevModePod(name, jBangOptions, podLabels, projectDevmodeImage, deploymentFragment, envVars);
Pod pod = getDevModePod(name, verbose, podLabels, projectDevmodeImage, deploymentFragment, envVars);
Pod result = client.resource(pod).serverSideApply();
copyFilesToContainer(result, files, "/karavan/code");
LOGGER.info("Created pod " + result.getMetadata().getName());
Expand Down Expand Up @@ -389,7 +389,7 @@ public ResourceRequirements getResourceRequirements(Map<String, String> containe
.build();
}

private Pod getDevModePod(String name, String jbangOptions, Map<String, String> labels, String projectDevmodeImage, String deploymentFragment, Map<String, String> envVars) {
private Pod getDevModePod(String name, Boolean verbose, Map<String, String> labels, String projectDevmodeImage, String deploymentFragment, Map<String, String> envVars) {

Deployment deployment = Serialization.unmarshal(deploymentFragment, Deployment.class);
PodSpec podSpec = null;
Expand Down Expand Up @@ -420,7 +420,7 @@ private Pod getDevModePod(String name, String jbangOptions, Map<String, String>

List<EnvVar> environmentVariables = new ArrayList<>();
envVars.forEach((k, v) -> environmentVariables.add(new EnvVarBuilder().withName(k).withValue(v).build()));
environmentVariables.add(new EnvVarBuilder().withName(ENV_VAR_JBANG_OPTIONS).withValue(jbangOptions).build());
environmentVariables.add(new EnvVarBuilder().withName(ENV_VAR_VERBOSE_OPTION_NAME).withValue(ENV_VAR_VERBOSE_OPTION_VALUE).build());

Container container = new ContainerBuilder()
.withName(name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import jakarta.enterprise.inject.Produces;
import jakarta.inject.Inject;
import org.apache.camel.karavan.KaravanConstants;
import org.apache.camel.karavan.model.ContainerType;
import org.apache.camel.karavan.service.ConfigService;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipse.microprofile.health.HealthCheck;
Expand All @@ -45,8 +44,6 @@
import java.util.Map;
import java.util.Optional;

import static org.apache.camel.karavan.KaravanConstants.LABEL_TYPE;

@Default
@Readiness
@ApplicationScoped
Expand Down Expand Up @@ -97,17 +94,15 @@ public void startInformers() {

KubernetesClient client = kubernetesClient();

String[] values = new String[]{ContainerType.project.name(), ContainerType.build.name(), ContainerType.devmode.name(), ContainerType.devservice.name(), ContainerType.internal.name(),};

SharedIndexInformer<Deployment> deploymentInformer = client.apps().deployments().inNamespace(getNamespace()).withLabelIn(LABEL_TYPE, values).inform();
SharedIndexInformer<Deployment> deploymentInformer = client.apps().deployments().inNamespace(getNamespace()).inform();
deploymentInformer.addEventHandlerWithResyncPeriod(new DeploymentEventHandler(this, eventBus), 30 * 1000L);
informers.add(deploymentInformer);

SharedIndexInformer<Service> serviceInformer = client.services().inNamespace(getNamespace()).withLabelIn(LABEL_TYPE, values).inform();
SharedIndexInformer<Service> serviceInformer = client.services().inNamespace(getNamespace()).inform();
serviceInformer.addEventHandlerWithResyncPeriod(new ServiceEventHandler(this, eventBus), 30 * 1000L);
informers.add(serviceInformer);

SharedIndexInformer<Pod> podRunInformer = client.pods().inNamespace(getNamespace()).withLabelIn(LABEL_TYPE, values).inform();
SharedIndexInformer<Pod> podRunInformer = client.pods().inNamespace(getNamespace()).inform();
podRunInformer.addEventHandlerWithResyncPeriod(new PodEventHandler( this, eventBus), 30 * 1000L);
informers.add(podRunInformer);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public Project commitAndPushProject(String projectId, String message, String aut
}
}

public String runProjectWithJBangOptions(Project project, String jBangOptions, Map<String, String> labels, Map<String, String> envVars) throws Exception {
public String runProjectWithJBangOptions(Project project, Boolean verbose, Map<String, String> labels, Map<String, String> envVars) throws Exception {
String containerName = project.getProjectId();
PodContainerStatus status = karavanCache.getDevModePodContainerStatus(project.getProjectId(), environment);
if (status == null) {
Expand All @@ -107,10 +107,10 @@ public String runProjectWithJBangOptions(Project project, String jBangOptions, M
String projectDevmodeImage = codeService.getProjectDevModeImage(project.getProjectId());
if (ConfigService.inKubernetes()) {
String deploymentFragment = codeService.getDeploymentFragment(project.getProjectId());
kubernetesService.runDevModeContainer(project, jBangOptions, files, projectDevmodeImage, deploymentFragment, labels, envVars);
kubernetesService.runDevModeContainer(project, verbose, files, projectDevmodeImage, deploymentFragment, labels, envVars);
} else {
DockerComposeService compose = getProjectDockerComposeService(project.getProjectId());
dockerForKaravan.runProjectInDevMode(project.getProjectId(), jBangOptions, compose, files, projectDevmodeImage, labels, envVars);
dockerForKaravan.runProjectInDevMode(project.getProjectId(), verbose, compose, files, projectDevmodeImage, labels, envVars);
}
return containerName;
} else {
Expand Down
2 changes: 1 addition & 1 deletion karavan-app/src/main/webui/src/api/KaravanApi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ export class KaravanApi {
}

static async startDevModeContainer(project: Project, verbose: boolean, after: (res: AxiosResponse<any>) => void) {
instance.post('/ui/devmode' + (verbose ? '/--verbose' : ''), project)
instance.post('/ui/devmode/' + verbose.toString(), project)
.then(res => {
after(res);
}).catch(err => {
Expand Down
2 changes: 1 addition & 1 deletion karavan-generator/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
</repositories>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<version.camel-kamelet>4.8.0</version.camel-kamelet>
<version.camel-kamelet>4.8.1</version.camel-kamelet>
<compiler-plugin.version>3.8.1</compiler-plugin.version>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<version.vertx>4.5.9</version.vertx>
Expand Down

0 comments on commit 0369e19

Please sign in to comment.