You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by as...@apache.org on 2019/11/28 07:41:05 UTC

[camel-k] 05/13: feat: Patch generation labels of integration resources used by GC trait

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

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

commit f797de8de8ad5fb6adddeef3a6feee3172761bca
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Tue Nov 26 11:27:42 2019 +0100

    feat: Patch generation labels of integration resources used by GC trait
---
 pkg/trait/gc.go      | 36 ++++++++++++++++++------------------
 pkg/trait/gc_test.go |  2 +-
 2 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/pkg/trait/gc.go b/pkg/trait/gc.go
index 11b8ccb..b35a4a8 100644
--- a/pkg/trait/gc.go
+++ b/pkg/trait/gc.go
@@ -90,35 +90,35 @@ func (t *garbageCollectorTrait) Configure(e *Environment) (bool, error) {
 }
 
 func (t *garbageCollectorTrait) Apply(e *Environment) error {
-	if e.IntegrationInPhase(v1alpha1.IntegrationPhaseInitialization, v1alpha1.IntegrationPhaseDeploying) {
+	switch e.Integration.Status.Phase {
+
+	case v1alpha1.IntegrationPhaseRunning:
+		// Register a post action that deletes the existing resources that are labelled
+		// with the previous integration generations.
+		// 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
+		e.PostActions = append(e.PostActions, func(env *Environment) error {
+			// The collection and deletion are performed asynchronously to avoid blocking
+			// the reconcile loop.
+			go t.garbageCollectResources(env)
+			return nil
+		})
+		fallthrough
+
+	default:
 		// Register a post processor that adds the required labels to the new resources
 		e.PostProcessors = append(e.PostProcessors, func(env *Environment) error {
+			generation := strconv.FormatInt(env.Integration.GetGeneration(), 10)
 			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)
+				labels["camel.apache.org/generation"] = generation
 				// Make sure the integration label is set
 				labels["camel.apache.org/integration"] = env.Integration.Name
 				resource.SetLabels(labels)
 			})
 			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
-
-		// 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
-		})
 	}
 
 	return nil
diff --git a/pkg/trait/gc_test.go b/pkg/trait/gc_test.go
index 7766638..5a49058 100644
--- a/pkg/trait/gc_test.go
+++ b/pkg/trait/gc_test.go
@@ -51,7 +51,7 @@ func TestApplyGarbageCollectorTraitDoesSucceed(t *testing.T) {
 	err := gcTrait.Apply(environment)
 
 	assert.Nil(t, err)
-	assert.Len(t, environment.PostProcessors, 0)
+	assert.Len(t, environment.PostProcessors, 1)
 	assert.Len(t, environment.PostActions, 1)
 }