chore(GC): Run garbage collection in running phase instead of deploying
diff --git a/pkg/controller/integration/monitor.go b/pkg/controller/integration/monitor.go
index cbc3af5..95ec883 100644
--- a/pkg/controller/integration/monitor.go
+++ b/pkg/controller/integration/monitor.go
@@ -66,7 +66,7 @@
}
// Run traits that are enabled for the running phase,
- // such as the deployment and Knative service traits.
+ // such as the deployment, garbage collector and Knative service traits.
_, err = trait.Apply(ctx, action.client, integration, nil)
if err != nil {
return nil, err
diff --git a/pkg/trait/gc.go b/pkg/trait/gc.go
index 3512ae3..d54e523 100644
--- a/pkg/trait/gc.go
+++ b/pkg/trait/gc.go
@@ -50,39 +50,44 @@
return false, nil
}
- return e.IntegrationInPhase(v1alpha1.IntegrationPhaseInitialization) ||
- e.IntegrationInPhase(v1alpha1.IntegrationPhaseDeploying), nil
+ return e.IntegrationInPhase(
+ v1alpha1.IntegrationPhaseInitialization,
+ v1alpha1.IntegrationPhaseDeploying,
+ v1alpha1.IntegrationPhaseRunning),
+ nil
}
func (t *garbageCollectorTrait) Apply(e *Environment) error {
- // Register a post processor that adds the required labels to the new resources
- e.PostProcessors = append(e.PostProcessors, func(env *Environment) error {
- env.Resources.VisitMetaObject(func(resource metav1.Object) {
- labels := resource.GetLabels()
- if labels == nil {
- labels = map[string]string{}
- }
- // Label the resource with the current integration generation
- labels["camel.apache.org/generation"] = strconv.FormatInt(env.Integration.GetGeneration(), 10)
- // Make sure the integration label is set
- labels["camel.apache.org/integration"] = env.Integration.Name
- resource.SetLabels(labels)
+ if e.IntegrationInPhase(v1alpha1.IntegrationPhaseInitialization, v1alpha1.IntegrationPhaseDeploying) {
+ // Register a post processor that adds the required labels to the new resources
+ e.PostProcessors = append(e.PostProcessors, func(env *Environment) error {
+ env.Resources.VisitMetaObject(func(resource metav1.Object) {
+ labels := resource.GetLabels()
+ if labels == nil {
+ labels = map[string]string{}
+ }
+ // Label the resource with the current integration generation
+ labels["camel.apache.org/generation"] = strconv.FormatInt(env.Integration.GetGeneration(), 10)
+ // Make sure the integration label is set
+ labels["camel.apache.org/integration"] = env.Integration.Name
+ resource.SetLabels(labels)
+ })
+ return nil
})
- return nil
- })
+ } else if e.IntegrationInPhase(v1alpha1.IntegrationPhaseRunning) {
+ // Let's run garbage collection during the integration running phase
+ // TODO: this should be refined so that it's run when all the replicas for the newer generation
+ // are ready. This is to be added when the integration scale status is refined with ready replicas
- // Let's run garbage collection during the integration deploying phase
- if !e.IntegrationInPhase(v1alpha1.IntegrationPhaseDeploying) {
- return nil
+ // Register a post action that deletes the existing resources that are labelled
+ // with the previous integration generations.
+ e.PostActions = append(e.PostActions, func(environment *Environment) error {
+ // The collection and deletion are performed asynchronously to avoid blocking
+ // the reconcile loop.
+ go t.garbageCollectResources(e)
+ return nil
+ })
}
- // Register a post action that deletes the existing resources that are labelled
- // with the previous integration generations.
- // The collection and deletion are performed asynchronously to avoid blocking
- // the reconcile loop.
- e.PostActions = append(e.PostActions, func(environment *Environment) error {
- go t.garbageCollectResources(e)
- return nil
- })
return nil
}
diff --git a/pkg/trait/gc_test.go b/pkg/trait/gc_test.go
index 88086ab..7766638 100644
--- a/pkg/trait/gc_test.go
+++ b/pkg/trait/gc_test.go
@@ -51,7 +51,7 @@
err := gcTrait.Apply(environment)
assert.Nil(t, err)
- assert.Len(t, environment.PostProcessors, 1)
+ assert.Len(t, environment.PostProcessors, 0)
assert.Len(t, environment.PostActions, 1)
}
@@ -78,7 +78,7 @@
Name: "integration-name",
},
Status: v1alpha1.IntegrationStatus{
- Phase: v1alpha1.IntegrationPhaseDeploying,
+ Phase: v1alpha1.IntegrationPhaseRunning,
},
},
}