You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by as...@apache.org on 2021/09/09 09:52:44 UTC
[camel-k] 05/37: feat(native): Configure Integration runtime
depending on Quarkus packaging type
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit aec61ef1b29caf9d3fed66c08c5b369b8f2f5463
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Fri Aug 6 12:36:49 2021 +0200
feat(native): Configure Integration runtime depending on Quarkus packaging type
---
pkg/trait/jvm.go | 18 +++++++++++++++---
pkg/trait/quarkus.go | 47 ++++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 57 insertions(+), 8 deletions(-)
diff --git a/pkg/trait/jvm.go b/pkg/trait/jvm.go
index 5cefaae..8d9e3d3 100644
--- a/pkg/trait/jvm.go
+++ b/pkg/trait/jvm.go
@@ -37,7 +37,6 @@ import (
v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/builder"
"github.com/apache/camel-k/pkg/util"
- "github.com/apache/camel-k/pkg/util/defaults"
)
// The JVM trait is used to configure the JVM that runs the integration.
@@ -72,6 +71,12 @@ func (t *jvmTrait) Configure(e *Environment) (bool, error) {
return false, nil
}
+ if t := e.Catalog.GetTrait(quarkusTraitId); t != nil && t.(*quarkusTrait).isNativePackageType() {
+ if quarkus := t.(*quarkusTrait); IsNilOrTrue(quarkus.Enabled) && quarkus.isNativePackageType() {
+ return false, nil
+ }
+ }
+
return e.InPhase(v1.IntegrationKitPhaseReady, v1.IntegrationPhaseDeploying) ||
e.InPhase(v1.IntegrationKitPhaseReady, v1.IntegrationPhaseRunning), nil
}
@@ -185,8 +190,15 @@ func (t *jvmTrait) Apply(e *Environment) error {
args = append(args, "-cp", strings.Join(items, ":"))
args = append(args, e.CamelCatalog.Runtime.ApplicationClass)
- container.Command = []string{"./camel-k-integration-" + defaults.Version + "-runner"}
- container.WorkingDir = builder.DeploymentDir
+ if IsNilOrTrue(t.PrintCommand) {
+ args = append([]string{"exec", "java"}, args...)
+ container.Command = []string{"/bin/sh", "-c"}
+ cmd := strings.Join(args, " ")
+ container.Args = []string{"echo " + cmd + " && " + cmd}
+ } else {
+ container.Command = []string{"java"}
+ container.Args = args
+ }
return nil
}
diff --git a/pkg/trait/quarkus.go b/pkg/trait/quarkus.go
index 5c62f04..cec04cf 100644
--- a/pkg/trait/quarkus.go
+++ b/pkg/trait/quarkus.go
@@ -18,31 +18,64 @@ limitations under the License.
package trait
import (
+ "fmt"
+
+ v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/builder"
+ "github.com/apache/camel-k/pkg/util/defaults"
)
-// The Quarkus trait activates the Quarkus runtime.
+type quarkusPackageType string
+
+const (
+ quarkusTraitId = "quarkus"
+
+ fastJarPackageType quarkusPackageType = "fast-jar"
+ nativePackageType quarkusPackageType = "native"
+)
+
+// The Quarkus trait configures the Quarkus runtime.
//
// It's enabled by default.
//
// +camel-k:trait=quarkus
type quarkusTrait struct {
BaseTrait `property:",squash"`
- // The Quarkus runtime type (reserved for future use)
- Native bool `property:"native" json:"native,omitempty"`
+ // The Quarkus package type, either `fast-jar` or `native` (default `fast-jar`)
+ PackageType *quarkusPackageType `property:"package-type" json:"packageType,omitempty"`
}
func newQuarkusTrait() Trait {
return &quarkusTrait{
- BaseTrait: NewBaseTrait("quarkus", 700),
+ BaseTrait: NewBaseTrait(quarkusTraitId, 1700),
}
}
func (t *quarkusTrait) Configure(e *Environment) (bool, error) {
- return IsNilOrTrue(t.Enabled), nil
+ if IsFalse(t.Enabled) {
+ return false, nil
+ }
+
+ if t.PackageType == nil {
+ packageType := fastJarPackageType
+ t.PackageType = &packageType
+ }
+
+ return e.InPhase(v1.IntegrationKitPhaseReady, v1.IntegrationPhaseDeploying) ||
+ e.InPhase(v1.IntegrationKitPhaseReady, v1.IntegrationPhaseRunning), nil
}
func (t *quarkusTrait) Apply(e *Environment) error {
+ if t.isNativePackageType() {
+ container := e.getIntegrationContainer()
+ if container == nil {
+ return fmt.Errorf("unable to find integration container: %s", e.Integration.Name)
+ }
+
+ container.Command = []string{"./camel-k-integration-" + defaults.Version + "-runner"}
+ container.WorkingDir = builder.DeploymentDir
+ }
+
return nil
}
@@ -59,3 +92,7 @@ func (t *quarkusTrait) InfluencesKit() bool {
func (t *quarkusTrait) addBuildSteps(steps *[]builder.Step) {
*steps = append(*steps, builder.QuarkusSteps...)
}
+
+func (t *quarkusTrait) isNativePackageType() bool {
+ return t.PackageType != nil && *t.PackageType == nativePackageType
+}