nicolaferraro commented on a change in pull request #76: Context handling 
improvement
URL: https://github.com/apache/camel-k/pull/76#discussion_r217885329
 
 

 ##########
 File path: pkg/stub/action/integration/util.go
 ##########
 @@ -24,7 +25,81 @@ func LookupContextForIntegration(integration 
*v1alpha1.Integration) (*v1alpha1.I
                return &ctx, nil
        }
 
-       return nil, nil
+       ctxList := v1alpha1.NewIntegrationContextList()
+       if err := sdk.List(integration.Namespace, &ctxList); err != nil {
+               return nil, err
+       }
+
+       var c *v1alpha1.IntegrationContext
+
+       if len(integration.Spec.Dependencies) == 0 {
+               // The integration has no dependencies, try to find the one that
+               // has minimum dependencies requirement.
+
+               ndeps := math.MaxUint16
+
+               for _, ctx := range ctxList.Items {
+                       cdeps := len(ctx.Spec.Dependencies)
+                       if cdeps < ndeps {
+                               ndeps = cdeps
+                               c = &ctx
+                       }
+                       if ndeps == 0 {
+                               break
+                       }
+               }
+       } else {
+               ndeps := math.MaxUint16
+
+               for _, ctx := range ctxList.Items {
+                       // The integration has some dependencies, try to find 
the one that matches
+                       // the required dependencies with minimum "dependency 
overhead"
+
+                       if ctx.Labels["camel.apache.org/context.type"] == 
"platform" {
+                               if StringSliceContains(ctx.Spec.Dependencies, 
integration.Spec.Dependencies) {
+                                       ideps := 
len(integration.Spec.Dependencies)
+                                       cdeps := len(ctx.Spec.Dependencies)
+
+                                       if cdeps < ndeps || ideps == cdeps {
+                                               c = &ctx
+                                               ndeps = cdeps
+                                       }
+
+                                       if ideps == ndeps {
+                                               break
+                                       }
+                               }
+                       }
+               }
+       }
+
+       if c == nil {
+               // TODO: generate a new platform context
 
 Review comment:
   Don't you do it in the caller function?

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to