You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by GitBox <gi...@apache.org> on 2019/02/25 13:34:57 UTC

[GitHub] lburgazzoli commented on a change in pull request #496: Perform garbage collection asynchronously

lburgazzoli commented on a change in pull request #496: Perform garbage collection asynchronously
URL: https://github.com/apache/camel-k/pull/496#discussion_r259823945
 
 

 ##########
 File path: pkg/trait/gc.go
 ##########
 @@ -72,36 +74,47 @@ func (t *garbageCollectorTrait) Apply(e *Environment) error {
 	}
 	// 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 {
-		selectors := []string{
-			fmt.Sprintf("camel.apache.org/integration=%s", e.Integration.Name),
-			"camel.apache.org/generation",
-			fmt.Sprintf("camel.apache.org/generation notin (%d)", e.Integration.GetGeneration()),
-		}
-
-		// Retrieve older generation resources that may can enlisted for garbage collection
-		resources, err := kubernetes.LookUpResources(context.TODO(), e.Client, e.Integration.Namespace, selectors)
-		if err != nil {
-			return err
-		}
-		// And delete them
-		for _, resource := range resources {
-			// pind the resource
-			resource := resource
-
-			err = e.Client.Delete(context.TODO(), &resource)
-			if err != nil {
-				// The resource may have already been deleted
-				if !k8serrors.IsNotFound(err) {
-					t.L.ForIntegration(e.Integration).Errorf(err, "cannot delete child resource: %s/%s", resource.GetKind(), resource.GetName())
-				}
-			} else {
-				t.L.ForIntegration(e.Integration).Debugf("child resource deleted: %s/%s", resource.GetKind(), resource.GetName())
-			}
-		}
-
+		go t.garbageCollectResources(e)
 		return nil
 	})
 
 	return nil
 }
+
+func (t *garbageCollectorTrait) garbageCollectResources(e *Environment) {
+	// Retrieve older generation resources that may can enlisted for garbage collection
+	// We rely on the discovery API to retrieve all the resources group and kind.
+	// That results in an unbounded collection that can be a bit slow.
+	// We may want to refine that step by white-listing or enlisting types to speed-up
+	// the collection duration.
+
+	selectors := []string{
+		fmt.Sprintf("camel.apache.org/integration=%s", e.Integration.Name),
+		"camel.apache.org/generation",
+		fmt.Sprintf("camel.apache.org/generation notin (%d)", e.Integration.GetGeneration()),
 
 Review comment:
   Can't this delete running resources ? 
   
   Assuming we are on generation 2: at the time this method runs it could be possible that there is a new generation 3 running which that may get deleted by this method.
   
   Isn't it ?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services