Skip to content

Commit

Permalink
Add args parameter to jbang plugin kubernetes export action
Browse files Browse the repository at this point in the history
  • Loading branch information
gansheer committed Jan 24, 2025
1 parent 33ba00d commit b1978b9
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ public void doExecute(TestContext context) {
List<String> fullArgs = new ArrayList<>();
fullArgs.add("add");
fullArgs.add(name);
fullArgs.addAll(args);
if (args != null){
fullArgs.addAll(args);
}
camelJBang().camelApp().run("plugin", fullArgs.toArray(String[]::new));
} else {
logger.info("Adding Camel plugin '%s' skipped: already installed".formatted(name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public class ExportKubernetesCamelPluginAction extends AbstractCamelJBangAction
/** Camel Jbang command traits */
private final List<String> traits;

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

/**
* Default constructor.
*/
Expand All @@ -63,45 +66,49 @@ public ExportKubernetesCamelPluginAction(ExportKubernetesCamelPluginAction.Build
this.imageBuilder = builder.imageBuilder;
this.imageRegistry = builder.imageRegistry;
this.traits = builder.traits;
this.args = builder.args;
}
@Override
public void doExecute(TestContext context) {
logger.debug("Export kubernetes camel plugin action:");
logger.info("Exporting integration in a Camel Kubernetes project ...");
Path integrationFile;
if (integrationResource != null) {
integrationFile = integrationResource.getFile().toPath();
} else {
throw new CitrusRuntimeException("Missing Camel integration source code or file");
}
Path integrationFile;
if (integrationResource != null) {
integrationFile = integrationResource.getFile().toPath();
} else {
throw new CitrusRuntimeException("Missing Camel integration source code or file");
}

List<String> fullArgs = new ArrayList<>();
fullArgs.add("export");
fullArgs.add(integrationFile.toAbsolutePath().toString());
if (imageBuilder != null){
fullArgs.add("--image-builder");
fullArgs.add(imageBuilder);
}
if (imageRegistry != null){
fullArgs.add("--image-registry");
fullArgs.add(imageRegistry);
}
List<String> fullArgs = new ArrayList<>();
fullArgs.add("export");
fullArgs.add(integrationFile.toAbsolutePath().toString());
if (imageBuilder != null){
fullArgs.add("--image-builder");
fullArgs.add(imageBuilder);
}
if (imageRegistry != null){
fullArgs.add("--image-registry");
fullArgs.add(imageRegistry);
}

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

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

if (args != null){
fullArgs.addAll(args);
}

camelJBang().camelApp().run("plugin", fullArgs.toArray(String[]::new));
camelJBang().camelApp().run("plugin", fullArgs.toArray(String[]::new));
}

public Resource getIntegrationResource() {
Expand All @@ -124,6 +131,10 @@ public List<String> getTraits() {
return traits;
}

public List<String> getArgs() {
return args;
}

/**
* Action builder.
*/
Expand All @@ -136,6 +147,7 @@ public static final class Builder extends AbstractCamelJBangAction.Builder<Expor

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


/**
Expand Down Expand Up @@ -208,6 +220,39 @@ public Builder withTraits(String... traits) {
return this;
}


/**
* Adds a command argument.
* @param arg
* @return
*/
public Builder withArg(String arg) {
this.args.add(arg);
return this;
}

/**
* Adds a command argument with name and value.
* @param name
* @param value
* @return
*/
public Builder withArg(String name, String value) {
this.args.add(name);
this.args.add(value);
return this;
}

/**
* Adds command arguments.
* @param args
* @return
*/
public Builder withArgs(String... args) {
this.args.addAll(Arrays.asList(args));
return this;
}

@Override
public ExportKubernetesCamelPluginAction build() {
return new ExportKubernetesCamelPluginAction(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ public Camel setJBang(JBang jbang) {
if (jbang.getPlugin().getKubernetes().getExport().getTraits() != null) {
jbang.getPlugin().getKubernetes().getExport().getTraits().getTraits().forEach(trait -> builder.withTrait(trait.getName()+"="+trait.getValue()));
}
if (jbang.getPlugin().getKubernetes().getExport().getArgs() != null) {
builder.withArgs(jbang.getPlugin().getKubernetes().getExport().getArgs().getArgs().toArray(String[]::new));
}

this.builder = builder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,9 @@ public static class Export {
@XmlElement(name = "traits")
protected Traits traits;

@XmlElement(name = "args")
protected Args args;

public Integration getIntegration() {
return integration;
}
Expand Down Expand Up @@ -627,6 +630,15 @@ public void setTraits(Traits traits) {
this.traits = traits;
}


public Args getArgs() {
return args;
}

public void setArgs(Args args) {
this.args = args;
}

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "")
public static class Integration {
Expand Down Expand Up @@ -728,6 +740,27 @@ public void setValue(String value) {

}
}

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"args",
})
public static class Args {

@XmlElement(name = "argument")
protected List<String> args;

public List<String> getArgs() {
if (args == null) {
args = new ArrayList<>();
}
return args;
}

public void setArgs(List<String> args) {
this.args = args;
}
}
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ public void setKubernetes(Kubernetes kubernetes) {
if (kubernetes.getExport().getTraits() != null && kubernetes.getExport().getTraits().size() > 0) {
kubernetes.getExport().getTraits().forEach(trait -> builder.withTrait(trait));
}
if (kubernetes.getExport().getArgs() != null && kubernetes.getExport().getArgs().size() > 0) {
kubernetes.getExport().getArgs().forEach(arg -> builder.withArg(arg));
}
this.builder.exportKubernetesPluginAction(builder.build());
}

Expand Down Expand Up @@ -440,6 +443,7 @@ public static class Export {

protected List<String> buildProperties;
protected List<String> traits;
protected List<String> args;

public Integration getIntegration() {
return integration;
Expand Down Expand Up @@ -489,6 +493,17 @@ public List<String> getTraits() {
return this.traits;
}

public List<String> getArgs() {
if (args == null) {
args = new ArrayList<>();
}
return this.args;
}

public void setArgs(List<String> args) {
this.args = args;
}

public static class Integration {
protected String file;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public void shouldLoadCamelPluginActions() throws Exception {
Assert.assertEquals(exportKubernetesAction.getImageRegistry(), "registry.minikube");
Assert.assertEquals(exportKubernetesAction.getTraits().size(), 2);
Assert.assertEquals(exportKubernetesAction.getBuildProperties().size(), 1);
Assert.assertEquals(exportKubernetesAction.getArgs().size(), 2);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,6 @@ public void shouldLoadCamelPluginActions() throws Exception {
Assert.assertEquals(pluginAction.getExportKubernetes().getImageRegistry(), "registry.minikube");
Assert.assertEquals(pluginAction.getExportKubernetes().getTraits().size(), 2);
Assert.assertEquals(pluginAction.getExportKubernetes().getBuildProperties().size(), 1);
Assert.assertEquals(pluginAction.getExportKubernetes().getArgs().size(), 2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
<trait name="container.image-pull-policy" value="IfNotPresent"/>
<trait name="container.image-push" value="true"/>
</traits>
<args>
<argument>--runtime</argument>
<argument>quarkus</argument>
</args>
</export>
</kubernetes>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ actions:
- "quarkus.kubernetes.image-pull-policy=Never"
traits:
- "container.image-pull-policy=IfNotPresent"
- "container.image-push=true"
- "container.image-push=true"
args:
- "--runtime"
- "quarkus"
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,13 @@
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="args" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="argument" type="xs:string" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
Expand Down

0 comments on commit b1978b9

Please sign in to comment.