Skip to content

Commit

Permalink
Fix apache#2638: sync owned integration kit to avoid gc
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaferraro authored and astefanutti committed Sep 22, 2021
1 parent e3debb7 commit 4992c08
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 39 deletions.
6 changes: 5 additions & 1 deletion pkg/apis/camel/v1/integration_types_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 --
Expand Down
86 changes: 48 additions & 38 deletions pkg/trait/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}

Expand Down

0 comments on commit 4992c08

Please sign in to comment.