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


The following commit(s) were added to refs/heads/main by this push:
     new cb464ed  Fix #2638: sync owned integration kit to avoid gc
cb464ed is described below

commit cb464ed37d2e84eec6852f23d8c3aebd4fc74b60
Author: nicolaferraro <ni.ferr...@gmail.com>
AuthorDate: Thu Sep 16 12:10:05 2021 +0200

    Fix #2638: sync owned integration kit to avoid gc
---
 pkg/apis/camel/v1/integration_types_support.go |  6 +-
 pkg/trait/container.go                         | 86 ++++++++++++++------------
 2 files changed, 53 insertions(+), 39 deletions(-)

diff --git a/pkg/apis/camel/v1/integration_types_support.go 
b/pkg/apis/camel/v1/integration_types_support.go
index c0df521..345a1c9 100644
--- a/pkg/apis/camel/v1/integration_types_support.go
+++ b/pkg/apis/camel/v1/integration_types_support.go
@@ -314,7 +314,11 @@ func (in *Integration) SetIntegrationKit(kit 
*IntegrationKit) {
                Namespace: kit.Namespace,
                Name:      kit.Name,
        }
-       in.Status.Image = kit.Status.Image
+       image := kit.Status.Image
+       if image == "" {
+               image = kit.Spec.Image
+       }
+       in.Status.Image = image
 }
 
 // GetIntegrationKitNamespace --
diff --git a/pkg/trait/container.go b/pkg/trait/container.go
index 3a08235..5ef07aa 100644
--- a/pkg/trait/container.go
+++ b/pkg/trait/container.go
@@ -154,7 +154,15 @@ func isValidPullPolicy(policy corev1.PullPolicy) bool {
 
 func (t *containerTrait) Apply(e *Environment) error {
        if e.IntegrationInPhase(v1.IntegrationPhaseInitialization) {
-               return t.configureDependencies(e)
+               if err := t.configureDependencies(e); err != nil {
+                       return err
+               }
+       }
+
+       if e.IntegrationInPhase(v1.IntegrationPhaseInitialization, 
v1.IntegrationPhaseDeploying, v1.IntegrationPhaseRunning) {
+               if err := t.configureImageIntegrationKit(e); err != nil {
+                       return err
+               }
        }
 
        if e.IntegrationInPhase(v1.IntegrationPhaseDeploying, 
v1.IntegrationPhaseRunning) {
@@ -170,49 +178,51 @@ func (t *containerTrait) IsPlatformTrait() bool {
 }
 
 func (t *containerTrait) configureDependencies(e *Environment) error {
-       if e.IntegrationInPhase(v1.IntegrationPhaseInitialization) {
-               if t.Image != "" {
-                       if e.Integration.Spec.IntegrationKit != nil {
-                               return fmt.Errorf(
-                                       "unsupported configuration: a container 
image has been set in conjunction with an IntegrationKit %v",
-                                       e.Integration.Spec.IntegrationKit)
-                       }
-                       if e.Integration.Spec.Kit != "" {
-                               return fmt.Errorf(
-                                       "unsupported configuration: a container 
image has been set in conjunction with an IntegrationKit %s",
-                                       e.Integration.Spec.Kit)
+       if IsTrue(t.ProbesEnabled) {
+               if capability, ok := 
e.CamelCatalog.Runtime.Capabilities[v1.CapabilityHealth]; ok {
+                       for _, dependency := range capability.Dependencies {
+                               
util.StringSliceUniqueAdd(&e.Integration.Status.Dependencies, 
dependency.GetDependencyID())
                        }
 
-                       kitName := fmt.Sprintf("kit-%s", e.Integration.Name)
-                       kit := v1.NewIntegrationKit(e.Integration.Namespace, 
kitName)
-                       kit.Spec.Image = t.Image
-
-                       // Add some information for post-processing, this may 
need to be refactored
-                       // to a proper data structure
-                       kit.Labels = map[string]string{
-                               v1.IntegrationKitTypeLabel:           
v1.IntegrationKitTypeExternal,
-                               kubernetes.CamelCreatorLabelKind:      
v1.IntegrationKind,
-                               kubernetes.CamelCreatorLabelName:      
e.Integration.Name,
-                               kubernetes.CamelCreatorLabelNamespace: 
e.Integration.Namespace,
-                               kubernetes.CamelCreatorLabelVersion:   
e.Integration.ResourceVersion,
-                       }
+                       // sort the dependencies to get always the same list if 
they don't change
+                       sort.Strings(e.Integration.Status.Dependencies)
+               }
+       }
 
-                       t.L.Infof("image %s", kit.Spec.Image)
-                       e.Resources.Add(kit)
-                       e.Integration.SetIntegrationKit(kit)
+       return nil
+}
+
+func (t *containerTrait) configureImageIntegrationKit(e *Environment) error {
+       if t.Image != "" {
+               if e.Integration.Spec.IntegrationKit != nil {
+                       return fmt.Errorf(
+                               "unsupported configuration: a container image 
has been set in conjunction with an IntegrationKit %v",
+                               e.Integration.Spec.IntegrationKit)
                }
-               if IsTrue(t.ProbesEnabled) {
-                       if capability, ok := 
e.CamelCatalog.Runtime.Capabilities[v1.CapabilityHealth]; ok {
-                               for _, dependency := range 
capability.Dependencies {
-                                       
util.StringSliceUniqueAdd(&e.Integration.Status.Dependencies, 
dependency.GetDependencyID())
-                               }
-
-                               // sort the dependencies to get always the same 
list if they don't change
-                               sort.Strings(e.Integration.Status.Dependencies)
-                       }
+               if e.Integration.Spec.Kit != "" {
+                       return fmt.Errorf(
+                               "unsupported configuration: a container image 
has been set in conjunction with an IntegrationKit %s",
+                               e.Integration.Spec.Kit)
+               }
+
+               kitName := fmt.Sprintf("kit-%s", e.Integration.Name)
+               kit := v1.NewIntegrationKit(e.Integration.Namespace, kitName)
+               kit.Spec.Image = t.Image
+
+               // Add some information for post-processing, this may need to 
be refactored
+               // to a proper data structure
+               kit.Labels = map[string]string{
+                       v1.IntegrationKitTypeLabel:            
v1.IntegrationKitTypeExternal,
+                       kubernetes.CamelCreatorLabelKind:      
v1.IntegrationKind,
+                       kubernetes.CamelCreatorLabelName:      
e.Integration.Name,
+                       kubernetes.CamelCreatorLabelNamespace: 
e.Integration.Namespace,
+                       kubernetes.CamelCreatorLabelVersion:   
e.Integration.ResourceVersion,
                }
-       }
 
+               t.L.Infof("image %s", kit.Spec.Image)
+               e.Resources.Add(kit)
+               e.Integration.SetIntegrationKit(kit)
+       }
        return nil
 }
 

Reply via email to