From 4992c08f3aae04c36ec81f94ecfa58d402a013fa Mon Sep 17 00:00:00 2001 From: nicolaferraro Date: Thu, 16 Sep 2021 12:10:05 +0200 Subject: [PATCH] Fix #2638: sync owned integration kit to avoid gc --- .../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 c0df521e26..345a1c997f 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 b6c5caf4fe..a553410544 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{ - "camel.apache.org/kit.type": 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{ + "camel.apache.org/kit.type": 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 }