Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CAMEL-21507 : Camel jbang Kubernetes - Backport new Trait model #16430

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.apache.camel.dsl.jbang.core.commands.bind.TemplateProvider;
import org.apache.camel.dsl.jbang.core.commands.kubernetes.KubernetesBaseCommand;
import org.apache.camel.dsl.jbang.core.commands.kubernetes.KubernetesHelper;
import org.apache.camel.dsl.jbang.core.commands.kubernetes.traits.TraitHelper;
import org.apache.camel.util.ObjectHelper;
import org.apache.camel.v1.Pipe;
import org.apache.camel.v1.integrationspec.Traits;
Expand Down Expand Up @@ -163,14 +162,14 @@ public Integer doCall() throws Exception {
String integrationSpec = "";
Traits traitsSpec = null;
if (traits != null && traits.length > 0) {
traitsSpec = TraitHelper.parseTraits(traits);
traitsSpec = IntegrationTraitHelper.parseTraits(traits);
}

if (connects != null) {
if (traitsSpec == null) {
traitsSpec = new Traits();
}
TraitHelper.configureConnects(traitsSpec, connects);
IntegrationTraitHelper.configureConnects(traitsSpec, connects);
}

if (traitsSpec != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.apache.camel.dsl.jbang.core.common.SourceHelper;
import org.apache.camel.v1.Integration;
import org.apache.camel.v1.Pipe;
import org.apache.camel.v1.integrationspec.Traits;
import picocli.CommandLine;

@CommandLine.Command(name = "export",
Expand Down Expand Up @@ -100,16 +99,20 @@ public Integer export() throws Exception {
}

@Override
protected Traits getTraitSpec(String[] applicationProperties, String[] applicationProfileProperties) {
protected org.apache.camel.dsl.jbang.core.commands.kubernetes.traits.model.Traits getTraitSpec(
String[] applicationProperties, String[] applicationProfileProperties) {
if (integration != null && integration.getSpec().getTraits() != null) {
return integration.getSpec().getTraits();
return KubernetesHelper.yaml(this.getClass().getClassLoader())
.loadAs(KubernetesHelper.dumpYaml(integration.getSpec().getTraits()),
org.apache.camel.dsl.jbang.core.commands.kubernetes.traits.model.Traits.class);
}

if (pipe != null && pipe.getSpec().getIntegration() != null
&& pipe.getSpec().getIntegration().getTraits() != null) {
// convert pipe spec traits to integration spec traits
return KubernetesHelper.yaml(this.getClass().getClassLoader())
.loadAs(KubernetesHelper.dumpYaml(pipe.getSpec().getIntegration().getTraits()), Traits.class);
.loadAs(KubernetesHelper.dumpYaml(pipe.getSpec().getIntegration().getTraits()),
org.apache.camel.dsl.jbang.core.commands.kubernetes.traits.model.Traits.class);
}

return super.getTraitSpec(applicationProperties, applicationProfileProperties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.apache.camel.dsl.jbang.core.commands.kubernetes.KubernetesHelper;
import org.apache.camel.dsl.jbang.core.commands.kubernetes.traits.TraitCatalog;
import org.apache.camel.dsl.jbang.core.commands.kubernetes.traits.TraitContext;
import org.apache.camel.dsl.jbang.core.commands.kubernetes.traits.TraitHelper;
import org.apache.camel.dsl.jbang.core.commands.kubernetes.traits.TraitProfile;
import org.apache.camel.dsl.jbang.core.common.JSonHelper;
import org.apache.camel.dsl.jbang.core.common.Printer;
Expand Down Expand Up @@ -245,10 +244,10 @@ public Integer doCall() throws Exception {
.collect(Collectors.toMap(it -> it[0].trim(), it -> it[1].trim())));
}

Traits traitsSpec = TraitHelper.parseTraits(traits);
Traits traitsSpec = IntegrationTraitHelper.parseTraits(traits);

if (image != null) {
TraitHelper.configureContainerImage(traitsSpec, image, null, null, null, null);
IntegrationTraitHelper.configureContainerImage(traitsSpec, image, null, null, null, null);
} else {
List<Source> resolvedSources = SourceHelper.resolveSources(integrationSources, compression);

Expand Down Expand Up @@ -315,10 +314,14 @@ public Integer doCall() throws Exception {
List<Source> sources = SourceHelper.resolveSources(integrationSources);
TraitContext context
= new TraitContext(integration.getMetadata().getName(), "1.0-SNAPSHOT", printer(), sources);
TraitHelper.configureContainerImage(traitsSpec, image, "quay.io", null, integration.getMetadata().getName(),
IntegrationTraitHelper.configureContainerImage(traitsSpec, image, "quay.io", null,
integration.getMetadata().getName(),
"1.0-SNAPSHOT");

new TraitCatalog().apply(traitsSpec, context, traitProfile, RuntimeType.quarkus);
org.apache.camel.dsl.jbang.core.commands.kubernetes.traits.model.Traits kubernetesTraits
= KubernetesHelper.yaml(this.getClass().getClassLoader())
.loadAs(KubernetesHelper.dumpYaml(traits),
org.apache.camel.dsl.jbang.core.commands.kubernetes.traits.model.Traits.class);
new TraitCatalog().apply(kubernetesTraits, context, traitProfile, RuntimeType.quarkus);

printer().println(
context.buildItems().stream().map(KubernetesHelper::dumpYaml).collect(Collectors.joining("---")));
Expand Down Expand Up @@ -363,14 +366,14 @@ public Integer doCall() throws Exception {
}

private void convertOptionsToTraits(Traits traitsSpec) {
TraitHelper.configureMountTrait(traitsSpec, configs, resources, volumes);
IntegrationTraitHelper.configureMountTrait(traitsSpec, configs, resources, volumes);
if (openApis != null) {
Stream.of(openApis).forEach(openapi -> TraitHelper.configureOpenApiSpec(traitsSpec, openapi));
Stream.of(openApis).forEach(openapi -> IntegrationTraitHelper.configureOpenApiSpec(traitsSpec, openapi));
}
TraitHelper.configureProperties(traitsSpec, properties);
TraitHelper.configureBuildProperties(traitsSpec, buildProperties);
TraitHelper.configureEnvVars(traitsSpec, envVars);
TraitHelper.configureConnects(traitsSpec, connects);
IntegrationTraitHelper.configureProperties(traitsSpec, properties);
IntegrationTraitHelper.configureBuildProperties(traitsSpec, buildProperties);
IntegrationTraitHelper.configureEnvVars(traitsSpec, envVars);
IntegrationTraitHelper.configureConnects(traitsSpec, connects);
}

private String getIntegrationName(List<String> sources) {
Expand Down
Loading
Loading