This is an automated email from the ASF dual-hosted git repository.

tsato pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 642127041ebd45b4bdfa5a5a1c3ed32567b6bc7c
Author: Tadayoshi Sato <[email protected]>
AuthorDate: Sat Jul 2 22:20:38 2022 +0900

    fix(trait): refactor and fix quarkus native build
---
 .../bases/camel.apache.org_integrationkits.yaml    |   1 +
 .../camel.apache.org_integrationplatforms.yaml     |   2 +
 .../crd/bases/camel.apache.org_integrations.yaml   |   1 +
 .../bases/camel.apache.org_kameletbindings.yaml    |   1 +
 helm/camel-k/crds/crd-integration-kit.yaml         |   1 +
 helm/camel-k/crds/crd-integration-platform.yaml    |   2 +
 helm/camel-k/crds/crd-integration.yaml             |   1 +
 helm/camel-k/crds/crd-kamelet-binding.yaml         |   1 +
 pkg/apis/camel/v1/trait/quarkus.go                 |   5 +-
 pkg/resources/resources.go                         |  16 +-
 pkg/trait/quarkus.go                               | 234 ++++++++++++---------
 pkg/trait/util.go                                  |   9 +
 12 files changed, 166 insertions(+), 108 deletions(-)

diff --git a/config/crd/bases/camel.apache.org_integrationkits.yaml 
b/config/crd/bases/camel.apache.org_integrationkits.yaml
index 2757e6ceb..a6c966e2f 100644
--- a/config/crd/bases/camel.apache.org_integrationkits.yaml
+++ b/config/crd/bases/camel.apache.org_integrationkits.yaml
@@ -186,6 +186,7 @@ spec:
                           to the integration in case no existing kit that 
matches
                           the integration exists.
                         items:
+                          description: Quarkus package type.
                           type: string
                         type: array
                     type: object
diff --git a/config/crd/bases/camel.apache.org_integrationplatforms.yaml 
b/config/crd/bases/camel.apache.org_integrationplatforms.yaml
index 716a18b7e..97e728f3c 100644
--- a/config/crd/bases/camel.apache.org_integrationplatforms.yaml
+++ b/config/crd/bases/camel.apache.org_integrationplatforms.yaml
@@ -1444,6 +1444,7 @@ spec:
                           to the integration in case no existing kit that 
matches
                           the integration exists.
                         items:
+                          description: Quarkus package type.
                           type: string
                         type: array
                     type: object
@@ -3049,6 +3050,7 @@ spec:
                           to the integration in case no existing kit that 
matches
                           the integration exists.
                         items:
+                          description: Quarkus package type.
                           type: string
                         type: array
                     type: object
diff --git a/config/crd/bases/camel.apache.org_integrations.yaml 
b/config/crd/bases/camel.apache.org_integrations.yaml
index e0cc1dbae..aaa5cc3c1 100644
--- a/config/crd/bases/camel.apache.org_integrations.yaml
+++ b/config/crd/bases/camel.apache.org_integrations.yaml
@@ -6921,6 +6921,7 @@ spec:
                           to the integration in case no existing kit that 
matches
                           the integration exists.
                         items:
+                          description: Quarkus package type.
                           type: string
                         type: array
                     type: object
diff --git a/config/crd/bases/camel.apache.org_kameletbindings.yaml 
b/config/crd/bases/camel.apache.org_kameletbindings.yaml
index c8e451d32..3c937cb1b 100644
--- a/config/crd/bases/camel.apache.org_kameletbindings.yaml
+++ b/config/crd/bases/camel.apache.org_kameletbindings.yaml
@@ -7215,6 +7215,7 @@ spec:
                               be assigned to the integration in case no 
existing kit
                               that matches the integration exists.
                             items:
+                              description: Quarkus package type.
                               type: string
                             type: array
                         type: object
diff --git a/helm/camel-k/crds/crd-integration-kit.yaml 
b/helm/camel-k/crds/crd-integration-kit.yaml
index 2757e6ceb..a6c966e2f 100644
--- a/helm/camel-k/crds/crd-integration-kit.yaml
+++ b/helm/camel-k/crds/crd-integration-kit.yaml
@@ -186,6 +186,7 @@ spec:
                           to the integration in case no existing kit that 
matches
                           the integration exists.
                         items:
+                          description: Quarkus package type.
                           type: string
                         type: array
                     type: object
diff --git a/helm/camel-k/crds/crd-integration-platform.yaml 
b/helm/camel-k/crds/crd-integration-platform.yaml
index 716a18b7e..97e728f3c 100644
--- a/helm/camel-k/crds/crd-integration-platform.yaml
+++ b/helm/camel-k/crds/crd-integration-platform.yaml
@@ -1444,6 +1444,7 @@ spec:
                           to the integration in case no existing kit that 
matches
                           the integration exists.
                         items:
+                          description: Quarkus package type.
                           type: string
                         type: array
                     type: object
@@ -3049,6 +3050,7 @@ spec:
                           to the integration in case no existing kit that 
matches
                           the integration exists.
                         items:
+                          description: Quarkus package type.
                           type: string
                         type: array
                     type: object
diff --git a/helm/camel-k/crds/crd-integration.yaml 
b/helm/camel-k/crds/crd-integration.yaml
index e0cc1dbae..aaa5cc3c1 100644
--- a/helm/camel-k/crds/crd-integration.yaml
+++ b/helm/camel-k/crds/crd-integration.yaml
@@ -6921,6 +6921,7 @@ spec:
                           to the integration in case no existing kit that 
matches
                           the integration exists.
                         items:
+                          description: Quarkus package type.
                           type: string
                         type: array
                     type: object
diff --git a/helm/camel-k/crds/crd-kamelet-binding.yaml 
b/helm/camel-k/crds/crd-kamelet-binding.yaml
index c8e451d32..3c937cb1b 100644
--- a/helm/camel-k/crds/crd-kamelet-binding.yaml
+++ b/helm/camel-k/crds/crd-kamelet-binding.yaml
@@ -7215,6 +7215,7 @@ spec:
                               be assigned to the integration in case no 
existing kit
                               that matches the integration exists.
                             items:
+                              description: Quarkus package type.
                               type: string
                             type: array
                         type: object
diff --git a/pkg/apis/camel/v1/trait/quarkus.go 
b/pkg/apis/camel/v1/trait/quarkus.go
index 8432e68f9..c521fe616 100644
--- a/pkg/apis/camel/v1/trait/quarkus.go
+++ b/pkg/apis/camel/v1/trait/quarkus.go
@@ -39,9 +39,12 @@ type QuarkusTrait struct {
        PackageTypes []QuarkusPackageType `property:"package-type" 
json:"packageTypes,omitempty"`
 }
 
+// Quarkus package type.
 type QuarkusPackageType string
 
 const (
+       // Quarkus package type representing "fast jar" packaging.
        FastJarPackageType QuarkusPackageType = "fast-jar"
-       NativePackageType  QuarkusPackageType = "native"
+       // Quarkus package type representing "native" packaging.
+       NativePackageType QuarkusPackageType = "native"
 )
diff --git a/pkg/resources/resources.go b/pkg/resources/resources.go
index a9851feea..d50f1734c 100644
--- a/pkg/resources/resources.go
+++ b/pkg/resources/resources.go
@@ -131,30 +131,30 @@ var assets = func() http.FileSystem {
                "/crd/bases/camel.apache.org_integrationkits.yaml": 
&vfsgen۰CompressedFileInfo{
                        name:             
"camel.apache.org_integrationkits.yaml",
                        modTime:          time.Time{},
-                       uncompressedSize: 15017,
+                       uncompressedSize: 15078,
 
-                       compressedContent: 
[]byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x3b\x5d\x73\xdb\x48\x72\xef\xfc\x15\x5d\xab\x07\xdb\x55\x24\x74\x9b\x5c\x5d\xa5\x94\xca\x83\x4e\xb6\xf7\x54\xb6\x25\xc7\xe4\xee\x65\xab\xf6\x41\x4d\xa0\x09\xce\x12\x98\xc1\xcd\x0c\x48\x31\xa9\xfc\xf7\x54\xf7\x0c\x40\x90\x04\x48\xae\x76\x9d\x7b\x31\x5e\x2c\x02\x33\x3d\xfd\xfd\x39\xbe\x82\xc9\x1f\xf7\x8c\xae\xe0\xa3\x4a\x49\x3b\xca\xc0\x1b\xf0\x4b\x82\xdb\x0a\xd3\x25\xc1\xd4\x2c\xfc\x06\x2d\xc1\x7b\x53\xeb\x0c\xbd\x
 [...]
+                       compressedContent: 
[]byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x3b\x5d\x6f\xdb\x48\x92\xef\xfa\x15\x85\xf1\x43\x12\x40\xa2\x77\xee\x16\x8b\x83\x0f\xf7\xe0\x75\x92\x59\x23\x89\x9d\x8b\x34\xb3\x37\xc0\x3c\xb8\x44\x96\xa8\x1e\x91\xdd\xdc\xee\xa6\x64\xdd\xe1\xfe\xfb\xa2\xaa\x9b\x14\x25\x91\x92\xc6\x33\xc1\xbe\x84\x2f\xb1\xc8\xee\xea\xfa\xfe\xec\x5c\xc1\xe4\x8f\x7b\x46\x57\xf0\x51\xa5\xa4\x1d\x65\xe0\x0d\xf8\x25\xc1\x6d\x85\xe9\x92\x60\x6a\x16\x7e\x83\x96\xe0\xbd\xa9\x75\x86\x5e\x
 [...]
                },
                "/crd/bases/camel.apache.org_integrationplatforms.yaml": 
&vfsgen۰CompressedFileInfo{
                        name:             
"camel.apache.org_integrationplatforms.yaml",
                        modTime:          time.Time{},
-                       uncompressedSize: 174247,
+                       uncompressedSize: 174369,
 
-                       compressedContent: 
[]byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xbd\x7d\x73\xdb\x36\xb6\x30\xfe\x7f\x3e\x05\xc6\xfd\x23\x4e\x46\x92\x9b\xdd\xdb\xdd\x5e\xdf\xe9\x3c\x8f\xd7\x49\x5b\x37\x71\xec\x6b\x3b\xb9\x77\xa7\xed\x54\x10\x79\x24\x21\x22\x01\x2e\x00\xca\x51\x7f\xfb\xfb\xee\xcf\xe0\x00\x20\x29\x89\x04\x29\xc9\x6f\x6d\xc4\xce\xec\xc6\x36\x01\x1e\x1c\x1c\x9c\x37\x9c\x97\xaf\x48\xff\xee\x9e\x67\x5f\x91\x77\x2c\x02\xae\x20\x26\x5a\x10\x3d\x05\x72\x92\xd1\x68\x0a\xe4\x5a\x8c\xf5\x
 [...]
+                       compressedContent: 
[]byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xbd\x7d\x73\xdb\x36\xb6\x30\xfe\x7f\x3e\x05\xc6\xfd\x23\x4e\x46\x92\x9b\xdd\xdb\xdd\x5e\xdf\xe9\x3c\x8f\xd7\x49\x5b\x37\x71\xec\x6b\x3b\xb9\x77\xa7\xed\x54\x10\x79\x24\x21\x22\x01\x2e\x00\xca\x51\x7f\xfb\xfb\xee\xcf\xe0\x00\x20\x29\x89\x04\x29\xc9\x6f\x6d\xc4\xce\xec\xc6\x36\x01\x1e\x1c\x1c\x9c\x37\x9c\x97\xaf\x48\xff\xee\x9e\x67\x5f\x91\x77\x2c\x02\xae\x20\x26\x5a\x10\x3d\x05\x72\x92\xd1\x68\x0a\xe4\x5a\x8c\xf5\x
 [...]
                },
                "/crd/bases/camel.apache.org_integrations.yaml": 
&vfsgen۰CompressedFileInfo{
                        name:             "camel.apache.org_integrations.yaml",
                        modTime:          time.Time{},
-                       uncompressedSize: 470887,
+                       uncompressedSize: 470948,
 
-                       compressedContent: 
[]byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xbd\x7b\x73\x1b\x37\xf6\x28\xf8\xbf\x3f\x05\x4a\x49\x5d\x49\x13\x91\xb2\x33\x73\x53\xbf\xf1\x4e\xdd\x94\x46\x92\x13\x6d\x6c\x99\x65\x29\xc9\x4d\x39\x9e\x04\xec\x06\x49\x5c\x35\x81\x1e\x00\x4d\x89\xbf\xf5\x7e\xf7\x2d\x1c\x00\xfd\xe0\xab\x0f\x5a\xa2\xe3\xcc\x36\xa6\x6a\x62\x52\xec\xd3\x78\x1c\x9c\xf7\xe3\x0b\x32\x78\xba\xf1\xec\x0b\xf2\x9a\x27\x4c\x68\x96\x12\x23\x89\x99\x31\x72\x96\xd3\x64\xc6\xc8\x8d\x9c\x98\x7b\x
 [...]
+                       compressedContent: 
[]byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xbd\x7b\x73\x1b\x37\xf6\x28\xf8\xbf\x3f\x05\x4a\x49\x5d\x49\x13\x91\xb2\x33\x73\x53\xbf\xf1\x4e\xdd\x94\x46\x92\x13\x6d\x6c\x99\x65\x29\xc9\x4d\x39\x9e\x04\xec\x06\x49\x5c\x35\x81\x1e\x00\x4d\x89\xbf\xf5\x7e\xf7\x2d\x1c\x00\xfd\xe0\xab\x0f\x5a\xa2\xe3\xcc\x36\xa6\x6a\x62\x52\xec\xd3\x78\x1c\x9c\xf7\xe3\x0b\x32\x78\xba\xf1\xec\x0b\xf2\x9a\x27\x4c\x68\x96\x12\x23\x89\x99\x31\x72\x96\xd3\x64\xc6\xc8\x8d\x9c\x98\x7b\x
 [...]
                },
                "/crd/bases/camel.apache.org_kameletbindings.yaml": 
&vfsgen۰CompressedFileInfo{
                        name:             
"camel.apache.org_kameletbindings.yaml",
                        modTime:          time.Time{},
-                       uncompressedSize: 543833,
+                       uncompressedSize: 543898,
 
-                       compressedContent: 
[]byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xfd\xfd\x73\x1b\x37\xb2\x2f\x8c\xff\xee\xbf\x02\x25\xa7\xae\xa4\x13\x92\xb2\xb3\xbb\xa9\xb3\xfe\x6e\xdd\x94\x56\x96\x13\x7d\x63\xcb\x2c\x4b\x71\x6e\xca\xc9\x49\xc0\x19\x90\xc4\xd5\x10\x98\x05\x30\x94\xb8\x8f\x9f\xff\xfd\x29\x34\x80\x79\xe1\x9b\xd0\x43\x51\x51\x36\x83\x53\x75\x36\x92\x35\x3d\x18\x00\xdd\xe8\xee\x4f\xbf\x3c\x27\xfd\x87\x1b\xcf\x9e\x93\xb7\x3c\x61\x42\xb3\x94\x18\x49\xcc\x94\x91\xd3\x9c\x26\x53\x46\x
 [...]
+                       compressedContent: 
[]byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xfd\xfd\x73\x1b\x37\xb2\x2f\x8c\xff\xee\xbf\x02\x25\xa7\xae\xa4\x13\x92\xb2\xb3\xbb\xa9\xb3\xfe\x6e\xdd\x94\x56\x96\x13\x7d\x63\xcb\x2c\x4b\x71\x6e\xca\xc9\x49\xc0\x19\x90\xc4\xd5\x10\x98\x05\x30\x94\xb8\x8f\x9f\xff\xfd\x29\x34\x80\x79\xe1\x9b\xd0\x43\x51\x51\x36\x83\x53\x75\x36\x92\x35\x3d\x18\x00\xdd\xe8\xee\x4f\xbf\x3c\x27\xfd\x87\x1b\xcf\x9e\x93\xb7\x3c\x61\x42\xb3\x94\x18\x49\xcc\x94\x91\xd3\x9c\x26\x53\x46\x
 [...]
                },
                "/crd/bases/camel.apache.org_kamelets.yaml": 
&vfsgen۰CompressedFileInfo{
                        name:             "camel.apache.org_kamelets.yaml",
diff --git a/pkg/trait/quarkus.go b/pkg/trait/quarkus.go
index 92e34fc19..0951fd3ad 100644
--- a/pkg/trait/quarkus.go
+++ b/pkg/trait/quarkus.go
@@ -79,13 +79,12 @@ func (t *quarkusTrait) Matches(trait Trait) bool {
                return false
        }
 
-types:
        for _, pt := range t.PackageTypes {
                if pt == traitv1.FastJarPackageType && len(qt.PackageTypes) == 
0 {
                        continue
                }
                if containsPackageType(qt.PackageTypes, pt) {
-                       continue types
+                       continue
                }
                return false
        }
@@ -106,110 +105,77 @@ func (t *quarkusTrait) Configure(e *Environment) (bool, 
error) {
 
 func (t *quarkusTrait) Apply(e *Environment) error {
        if e.IntegrationInPhase(v1.IntegrationPhaseBuildingKit) {
-               if containsPackageType(t.PackageTypes, 
traitv1.NativePackageType) {
-                       // Native compilation is only supported for a subset of 
languages,
-                       // so let's check for compatibility, and fail-fast the 
Integration,
-                       // to save compute resources and user time.
-                       for _, source := range e.Integration.Sources() {
-                               if language := source.InferLanguage(); language 
!= v1.LanguageKamelet &&
-                                       language != v1.LanguageYaml &&
-                                       language != v1.LanguageXML {
-                                       
t.L.ForIntegration(e.Integration).Infof("Integration %s contains a %s source 
that cannot be compiled to native executable", 
e.Integration.Namespace+"/"+e.Integration.Name, language)
-                                       e.Integration.Status.Phase = 
v1.IntegrationPhaseError
-                                       e.Integration.Status.SetCondition(
-                                               
v1.IntegrationConditionKitAvailable,
-                                               corev1.ConditionFalse,
-                                               
v1.IntegrationConditionUnsupportedLanguageReason,
-                                               fmt.Sprintf("native compilation 
for language %q is not supported", language))
-                                       // Let the calling controller handle 
the Integration update
-                                       return nil
-                               }
-                       }
-               }
-
-               switch len(t.PackageTypes) {
-               case 0:
-                       kit := t.newIntegrationKit(e, 
traitv1.FastJarPackageType)
-                       e.IntegrationKits = append(e.IntegrationKits, *kit)
-
-               case 1:
-                       kit := t.newIntegrationKit(e, t.PackageTypes[0])
-                       e.IntegrationKits = append(e.IntegrationKits, *kit)
-
-               default:
-                       for _, packageType := range t.PackageTypes {
-                               kit := t.newIntegrationKit(e, packageType)
-                               if kit.Spec.Traits.Quarkus == nil {
-                                       kit.Spec.Traits.Quarkus = 
&traitv1.QuarkusTrait{}
-                               }
-                               kit.Spec.Traits.Quarkus.PackageTypes = 
[]traitv1.QuarkusPackageType{packageType}
-                               e.IntegrationKits = append(e.IntegrationKits, 
*kit)
-                       }
-               }
+               t.applyWhileBuildingKit(e)
 
                return nil
        }
 
        switch e.IntegrationKit.Status.Phase {
-
        case v1.IntegrationKitPhaseBuildSubmitted:
-               build := getBuilderTask(e.BuildTasks)
-               if build == nil {
-                       return fmt.Errorf("unable to find builder task: %s", 
e.Integration.Name)
-               }
-
-               if build.Maven.Properties == nil {
-                       build.Maven.Properties = make(map[string]string)
-               }
-
-               steps, err := builder.StepsFrom(build.Steps...)
-               if err != nil {
+               if err := t.applyWhenBuildSubmitted(e); err != nil {
                        return err
                }
 
-               steps = append(steps, builder.Quarkus.CommonSteps...)
-
-               native, err := t.isNativeKit(e)
-               if err != nil {
+       case v1.IntegrationKitPhaseReady:
+               if err := t.applyWhenKitReady(e); err != nil {
                        return err
                }
+       }
 
-               if native {
-                       build.Maven.Properties["quarkus.package.type"] = 
string(traitv1.NativePackageType)
-                       steps = append(steps, builder.Image.NativeImageContext)
-                       // Spectrum does not rely on Dockerfile to assemble the 
image
-                       if e.Platform.Status.Build.PublishStrategy != 
v1.IntegrationPlatformBuildPublishStrategySpectrum {
-                               steps = append(steps, 
builder.Image.ExecutableDockerfile)
-                       }
-               } else {
-                       build.Maven.Properties["quarkus.package.type"] = 
string(traitv1.FastJarPackageType)
-                       steps = append(steps, 
builder.Quarkus.ComputeQuarkusDependencies, 
builder.Image.IncrementalImageContext)
-                       // Spectrum does not rely on Dockerfile to assemble the 
image
-                       if e.Platform.Status.Build.PublishStrategy != 
v1.IntegrationPlatformBuildPublishStrategySpectrum {
-                               steps = append(steps, 
builder.Image.JvmDockerfile)
-                       }
+       return nil
+}
+
+func (t *quarkusTrait) applyWhileBuildingKit(e *Environment) {
+       if containsPackageType(t.PackageTypes, traitv1.NativePackageType) {
+               // Native compilation is only supported for a subset of 
languages,
+               // so let's check for compatibility, and fail-fast the 
Integration,
+               // to save compute resources and user time.
+               if !t.validateNativeSupport(e) {
+                       // Let the calling controller handle the Integration 
update
+                       return
                }
+       }
 
-               // Sort steps by phase
-               sort.SliceStable(steps, func(i, j int) bool {
-                       return steps[i].Phase() < steps[j].Phase()
-               })
+       switch len(t.PackageTypes) {
+       case 0:
+               kit := t.newIntegrationKit(e, traitv1.FastJarPackageType)
+               e.IntegrationKits = append(e.IntegrationKits, *kit)
 
-               build.Steps = builder.StepIDsFor(steps...)
+       case 1:
+               kit := t.newIntegrationKit(e, t.PackageTypes[0])
+               e.IntegrationKits = append(e.IntegrationKits, *kit)
 
-       case v1.IntegrationKitPhaseReady:
-               if e.IntegrationInRunningPhases() && t.isNativeIntegration(e) {
-                       container := e.GetIntegrationContainer()
-                       if container == nil {
-                               return fmt.Errorf("unable to find integration 
container: %s", e.Integration.Name)
+       default:
+               for _, pt := range t.PackageTypes {
+                       packageType := pt
+                       kit := t.newIntegrationKit(e, packageType)
+                       if kit.Spec.Traits.Quarkus == nil {
+                               kit.Spec.Traits.Quarkus = 
&traitv1.QuarkusTrait{}
                        }
+                       kit.Spec.Traits.Quarkus.PackageTypes = 
[]traitv1.QuarkusPackageType{packageType}
+                       e.IntegrationKits = append(e.IntegrationKits, *kit)
+               }
+       }
+}
 
-                       container.Command = []string{"./camel-k-integration-" + 
defaults.Version + "-runner"}
-                       container.WorkingDir = builder.DeploymentDir
+func (t *quarkusTrait) validateNativeSupport(e *Environment) bool {
+       for _, source := range e.Integration.Sources() {
+               if language := source.InferLanguage(); language != 
v1.LanguageKamelet &&
+                       language != v1.LanguageYaml &&
+                       language != v1.LanguageXML {
+                       t.L.ForIntegration(e.Integration).Infof("Integration 
%s/%s contains a %s source that cannot be compiled to native executable", 
e.Integration.Namespace, e.Integration.Name, language)
+                       e.Integration.Status.Phase = v1.IntegrationPhaseError
+                       e.Integration.Status.SetCondition(
+                               v1.IntegrationConditionKitAvailable,
+                               corev1.ConditionFalse,
+                               
v1.IntegrationConditionUnsupportedLanguageReason,
+                               fmt.Sprintf("native compilation for language %q 
is not supported", language))
+
+                       return false
                }
        }
 
-       return nil
+       return true
 }
 
 func (t *quarkusTrait) newIntegrationKit(e *Environment, packageType 
traitv1.QuarkusPackageType) *v1.IntegrationKit {
@@ -242,16 +208,81 @@ func (t *quarkusTrait) newIntegrationKit(e *Environment, 
packageType traitv1.Qua
        kit.Spec = v1.IntegrationKitSpec{
                Dependencies: e.Integration.Status.Dependencies,
                Repositories: e.Integration.Spec.Repositories,
-               Traits: v1.IntegrationKitTraits{
-                       Builder:  e.Integration.Spec.Traits.Builder,
-                       Quarkus:  e.Integration.Spec.Traits.Quarkus,
-                       Registry: e.Integration.Spec.Traits.Registry,
-               },
+               Traits:       propagateKitTraits(e),
        }
 
        return kit
 }
 
+func propagateKitTraits(e *Environment) v1.IntegrationKitTraits {
+       traits := e.Integration.Spec.Traits
+       kitTraits := v1.IntegrationKitTraits{
+               Builder:  traits.Builder.DeepCopy(),
+               Quarkus:  traits.Quarkus.DeepCopy(),
+               Registry: traits.Registry.DeepCopy(),
+       }
+
+       // propagate addons that influence kits too
+       if len(traits.Addons) > 0 {
+               kitTraits.Addons = make(map[string]v1.AddonTrait)
+               for id, addon := range traits.Addons {
+                       if t := e.Catalog.GetTrait(id); t != nil && 
t.InfluencesKit() {
+                               kitTraits.Addons[id] = *addon.DeepCopy()
+                       }
+               }
+       }
+
+       return kitTraits
+}
+
+func (t *quarkusTrait) applyWhenBuildSubmitted(e *Environment) error {
+       build := getBuilderTask(e.BuildTasks)
+       if build == nil {
+               return fmt.Errorf("unable to find builder task: %s", 
e.Integration.Name)
+       }
+
+       if build.Maven.Properties == nil {
+               build.Maven.Properties = make(map[string]string)
+       }
+
+       steps, err := builder.StepsFrom(build.Steps...)
+       if err != nil {
+               return err
+       }
+
+       steps = append(steps, builder.Quarkus.CommonSteps...)
+
+       native, err := t.isNativeKit(e)
+       if err != nil {
+               return err
+       }
+
+       if native {
+               build.Maven.Properties["quarkus.package.type"] = 
string(traitv1.NativePackageType)
+               steps = append(steps, builder.Image.NativeImageContext)
+               // Spectrum does not rely on Dockerfile to assemble the image
+               if e.Platform.Status.Build.PublishStrategy != 
v1.IntegrationPlatformBuildPublishStrategySpectrum {
+                       steps = append(steps, 
builder.Image.ExecutableDockerfile)
+               }
+       } else {
+               build.Maven.Properties["quarkus.package.type"] = 
string(traitv1.FastJarPackageType)
+               steps = append(steps, 
builder.Quarkus.ComputeQuarkusDependencies, 
builder.Image.IncrementalImageContext)
+               // Spectrum does not rely on Dockerfile to assemble the image
+               if e.Platform.Status.Build.PublishStrategy != 
v1.IntegrationPlatformBuildPublishStrategySpectrum {
+                       steps = append(steps, builder.Image.JvmDockerfile)
+               }
+       }
+
+       // Sort steps by phase
+       sort.SliceStable(steps, func(i, j int) bool {
+               return steps[i].Phase() < steps[j].Phase()
+       })
+
+       build.Steps = builder.StepIDsFor(steps...)
+
+       return nil
+}
+
 func (t *quarkusTrait) isNativeKit(e *Environment) (bool, error) {
        switch types := t.PackageTypes; len(types) {
        case 0:
@@ -263,20 +294,25 @@ func (t *quarkusTrait) isNativeKit(e *Environment) (bool, 
error) {
        }
 }
 
-func (t *quarkusTrait) isNativeIntegration(e *Environment) bool {
-       // The current IntegrationKit determines the Integration runtime type
-       return e.IntegrationKit.Labels[v1.IntegrationKitLayoutLabel] == 
v1.IntegrationKitLayoutNative
-}
-
-func getBuilderTask(tasks []v1.Task) *v1.BuilderTask {
-       for i, task := range tasks {
-               if task.Builder != nil {
-                       return tasks[i].Builder
+func (t *quarkusTrait) applyWhenKitReady(e *Environment) error {
+       if e.IntegrationInRunningPhases() && t.isNativeIntegration(e) {
+               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
 }
 
+func (t *quarkusTrait) isNativeIntegration(e *Environment) bool {
+       // The current IntegrationKit determines the Integration runtime type
+       return e.IntegrationKit.Labels[v1.IntegrationKitLayoutLabel] == 
v1.IntegrationKitLayoutNative
+}
+
 func containsPackageType(types []traitv1.QuarkusPackageType, t 
traitv1.QuarkusPackageType) bool {
        for _, ti := range types {
                if t == ti {
diff --git a/pkg/trait/util.go b/pkg/trait/util.go
index 17e43a853..ef7b9ec31 100644
--- a/pkg/trait/util.go
+++ b/pkg/trait/util.go
@@ -267,3 +267,12 @@ func ToTrait(trait map[string]interface{}, target 
interface{}) error {
 
        return nil
 }
+
+func getBuilderTask(tasks []v1.Task) *v1.BuilderTask {
+       for i, task := range tasks {
+               if task.Builder != nil {
+                       return tasks[i].Builder
+               }
+       }
+       return nil
+}

Reply via email to