Skip to content

Commit

Permalink
Camel jbang kubernetes add paramaters
Browse files Browse the repository at this point in the history
* run: add runtime, cluster type and waiting for running integration parameter
* delete: add cluster type parameter
  • Loading branch information
gansheer committed Feb 4, 2025
1 parent d64dbce commit ea7f67c
Show file tree
Hide file tree
Showing 6 changed files with 273 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public class CamelKubernetesDeleteAction extends AbstractCamelJBangAction {
/** Camel integration name */
private final String integrationName;

/** Camel Jbang cluster type target */
private final String clusterType;

/** Project directory */
private final String workingDir;

Expand All @@ -52,6 +55,7 @@ public CamelKubernetesDeleteAction(Builder builder) {

this.integrationResource = builder.integrationResource;
this.integrationName = builder.integrationName;
this.clusterType = builder.clusterType;
this.workingDir = builder.workingDir;
this.namespace = builder.namespace;

Expand All @@ -65,15 +69,19 @@ public void doExecute(TestContext context) {
if (integrationResource != null) {
fullArgs.add(integrationResource.getFile().toPath().toAbsolutePath().toString());
}
if (integrationName != null){
if (integrationName != null) {
fullArgs.add("--name");
fullArgs.add(integrationName);
}
if (workingDir != null){
if (clusterType != null) {
fullArgs.add("--cluster-type");
fullArgs.add(clusterType);
}
if (workingDir != null) {
fullArgs.add("--working-dir");
fullArgs.add(workingDir);
}
if (namespace != null){
if (namespace != null) {
fullArgs.add("--namespace");
fullArgs.add(namespace);
}
Expand All @@ -89,6 +97,10 @@ public String getIntegrationName() {
return integrationName;
}

public String getClusterType() {
return clusterType;
}

public String getWorkingDir() {
return workingDir;
}
Expand All @@ -104,6 +116,7 @@ public static final class Builder extends AbstractCamelJBangAction.Builder<Camel

private Resource integrationResource;
private String integrationName;
private String clusterType;
private String workingDir;
private String namespace;

Expand All @@ -128,6 +141,16 @@ public Builder integration(String name) {
return this;
}

/**
* Set cluster type target.
* @param clusterType
* @return
*/
public Builder clusterType(String clusterType) {
this.clusterType = clusterType;
return this;
}

/**
* The working directory where to find exported project sources.
* @param dir directory path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.citrusframework.camel.actions;

import org.citrusframework.camel.jbang.CamelJBangSettings;
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.jbang.ProcessAndOutput;
Expand All @@ -37,37 +38,52 @@ public class CamelKubernetesRunIntegrationAction extends AbstractCamelJBangActio
/** Logger */
private static final Logger logger = LoggerFactory.getLogger(CamelKubernetesRunIntegrationAction.class);


/** Camel integration resource */
private final Resource integrationResource;

/** Camel integration project runtime */
private final String runtime;

/** Camel Jbang image builder */
private final String imageBuilder;

/** Camel Jbang image registry */
private final String imageRegistry;

/** Camel Jbang cluster type target */
private final String clusterType;

/** Camel Jbang command build properties */
private final List<String> buildProperties;

/** Camel Jbang command properties */
private final List<String> properties;

/** Camel Jbang command traits */
private final List<String> traits;

/** Camel Jbang command arguments */
private final List<String> args;

/** Wait for integration pod to be in Running state */
private final boolean waitForRunningState;

/**
* Default constructor.
*/
public CamelKubernetesRunIntegrationAction(CamelKubernetesRunIntegrationAction.Builder builder) {
super("run-integration-kubernetes", builder);

this.integrationResource = builder.integrationResource;
this.buildProperties = builder.buildProperties;
this.runtime = builder.runtime;
this.imageBuilder = builder.imageBuilder;
this.imageRegistry = builder.imageRegistry;
this.clusterType = builder.clusterType;
this.buildProperties = builder.buildProperties;
this.properties = builder.properties;
this.traits = builder.traits;
this.args = builder.args;
this.waitForRunningState = builder.waitForRunningState;
}
@Override
public void doExecute(TestContext context) {
Expand All @@ -82,23 +98,38 @@ public void doExecute(TestContext context) {
List<String> fullArgs = new ArrayList<>();
fullArgs.add("run");
fullArgs.add(integrationFile.toAbsolutePath().toString());
if (runtime != null){
fullArgs.add("--runtime");
fullArgs.add(runtime);
}
if (imageBuilder != null){
fullArgs.add("--image-builder");
fullArgs.add(imageBuilder);
}
if (imageRegistry != null){
if (imageRegistry != null) {
fullArgs.add("--image-registry");
fullArgs.add(imageRegistry);
}
if (clusterType != null) {
fullArgs.add("--cluster-type");
fullArgs.add(clusterType);
}

if (buildProperties != null){
if (buildProperties != null) {
for (String property : buildProperties) {
fullArgs.add("--build-property");
fullArgs.add(property);
}
}

if (traits != null){
if (properties != null) {
for (String property : properties) {
fullArgs.add("--property");
fullArgs.add(property);
}
}

if (traits != null) {
for (String trait : traits) {
fullArgs.add("--trait");
fullArgs.add(trait);
Expand All @@ -109,13 +140,11 @@ public void doExecute(TestContext context) {
fullArgs.addAll(args);
}

// TODO manage this better and maybe use --wait
ProcessAndOutput pao = camelJBang().camelApp().run("kubernetes", fullArgs.toArray(String[]::new));
while (pao.getProcess().isAlive()) {
continue;
if (waitForRunningState) {
fullArgs.add("--wait");
}

// TODO add a printLog ?
ProcessAndOutput pao = camelJBang().camelApp().run("kubernetes", fullArgs.toArray(String[]::new));
logger.info(pao.getOutput());
if (pao.getProcess().exitValue() != 0) {
throw new CitrusRuntimeException(String.format("Failed to start Camel integration in kubernetes - exit code %s", pao.getProcess().exitValue()));
Expand All @@ -128,6 +157,10 @@ public Resource getIntegrationResource() {
return integrationResource;
}

public String getRuntime() {
return runtime;
}

public String getImageBuilder() {
return imageBuilder;
}
Expand All @@ -140,6 +173,10 @@ public List<String> getBuildProperties() {
return buildProperties;
}

public List<String> getProperties() {
return properties;
}

public List<String> getTraits() {
return traits;
}
Expand All @@ -155,13 +192,17 @@ public static final class Builder extends AbstractCamelJBangAction.Builder<Camel

private Resource integrationResource;

private String runtime;
private String imageBuilder;
private String imageRegistry;
private String clusterType;

private final List<String> buildProperties = new ArrayList<>();
private final List<String> properties = new ArrayList<>();
private final List<String> traits = new ArrayList<>();
private final List<String> args = new ArrayList<>();

private boolean waitForRunningState = CamelJBangSettings.isWaitForRunningState();

/**
* Export given Camel integration resource.
Expand All @@ -173,6 +214,16 @@ public Builder integration(Resource resource) {
return this;
}

/**
* Define runtime.
* @param runtime
* @return
*/
public Builder runtime(String runtime) {
this.runtime = runtime;
return this;
}

/**
* Define container image builder type.
* @param imageBuilder
Expand All @@ -193,6 +244,16 @@ public Builder imageRegistry(String imageRegistry) {
return this;
}

/**
* Set cluster type target.
* @param clusterType
* @return
*/
public Builder clusterType(String clusterType) {
this.clusterType = clusterType;
return this;
}

/**
* Adds a command build property.
* @param property
Expand All @@ -213,6 +274,25 @@ public Builder withBuildProperties(String... properties) {
return this;
}

/**
* Adds a command property.
* @param property
* @return
*/
public Builder withProperty(String property) {
this.properties.add(property);
return this;
}

/**
* Adds command properties.
* @param properties
* @return
*/
public Builder withProperties(String... properties) {
this.properties.addAll(Arrays.asList(properties));
return this;
}
/**
* Adds a command trait.
* @param trait
Expand Down Expand Up @@ -266,6 +346,12 @@ public Builder withArgs(String... args) {
return this;
}


public Builder waitForRunningState(boolean enabled) {
this.waitForRunningState = enabled;
return this;
}

@Override
public CamelKubernetesRunIntegrationAction build() {
return new CamelKubernetesRunIntegrationAction(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,21 @@ public Camel setJBang(JBang jbang) {
builder.integration(Resources.create(jbang.getPlugin().getKubernetes().getRun().getIntegration().getFile()));
}

builder.imageBuilder(jbang.getPlugin().getKubernetes().getRun().getImageBuilder())
.imageRegistry(jbang.getPlugin().getKubernetes().getRun().getImageRegistry());
builder.runtime(jbang.getPlugin().getKubernetes().getRun().getRuntime())
.imageBuilder(jbang.getPlugin().getKubernetes().getRun().getImageBuilder())
.imageRegistry(jbang.getPlugin().getKubernetes().getRun().getImageRegistry())
.clusterType(jbang.getPlugin().getKubernetes().getRun().getClusterType());

if (jbang.getPlugin().getKubernetes().getRun().getBuildProperties() != null) {
jbang.getPlugin().getKubernetes().getRun().getBuildProperties()
.getProperties()
.forEach(property -> builder.withBuildProperties(property.getName()+"="+property.getValue()));
}
if (jbang.getPlugin().getKubernetes().getRun().getProperties() != null) {
jbang.getPlugin().getKubernetes().getRun().getProperties()
.getProperties()
.forEach(property -> builder.withProperties(property.getName()+"="+property.getValue()));
}
if (jbang.getPlugin().getKubernetes().getRun().getTraits() != null) {
jbang.getPlugin().getKubernetes().getRun().getTraits()
.getTraits()
Expand All @@ -287,6 +294,9 @@ public Camel setJBang(JBang jbang) {
builder.withArgs(jbang.getPlugin().getKubernetes().getRun().getArgs().getArgs().toArray(String[]::new));
}


builder.waitForRunningState(jbang.getPlugin().getKubernetes().getRun().isWaitForRunningState());

this.builder = builder;
} else if (jbang.getPlugin().getKubernetes().getVerify() != null) {
CamelKubernetesVerifyAction.Builder builder = new CamelKubernetesVerifyAction.Builder();
Expand Down Expand Up @@ -315,7 +325,8 @@ public Camel setJBang(JBang jbang) {
builder.integration(jbang.getPlugin().getKubernetes().getDelete().getIntegration().getName());
}
}
builder.namespace(jbang.getPlugin().getKubernetes().getDelete().getNamespace())
builder.clusterType(jbang.getPlugin().getKubernetes().getDelete().getClusterType())
.namespace(jbang.getPlugin().getKubernetes().getDelete().getNamespace())
.workingDir(jbang.getPlugin().getKubernetes().getDelete().getWorkingDir());
this.builder = builder;
}
Expand Down
Loading

0 comments on commit ea7f67c

Please sign in to comment.