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

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


The following commit(s) were added to refs/heads/master by this push:
     new 942a616  chore(builder): small refactor to image context lookup
942a616 is described below

commit 942a6163198fad9c95b1294cf7fdea8e016044b8
Author: lburgazzoli <lburgazz...@gmail.com>
AuthorDate: Fri Apr 3 16:30:14 2020 +0200

    chore(builder): small refactor to image context lookup
---
 pkg/builder/builder_steps.go | 23 +++++++++--------------
 pkg/builder/builder_types.go |  6 ------
 2 files changed, 9 insertions(+), 20 deletions(-)

diff --git a/pkg/builder/builder_steps.go b/pkg/builder/builder_steps.go
index cef2dd6..e33597a 100644
--- a/pkg/builder/builder_steps.go
+++ b/pkg/builder/builder_steps.go
@@ -289,15 +289,14 @@ func incrementalImageContext(ctx *Context) error {
 
                bestImage, commonLibs := findBestImage(images, ctx.Artifacts)
                if bestImage.Image != "" {
-                       selectedArtifacts := make([]v1.Artifact, 0)
+                       ctx.BaseImage = bestImage.Image
+                       ctx.SelectedArtifacts = make([]v1.Artifact, 0)
+
                        for _, entry := range ctx.Artifacts {
                                if _, isCommon := commonLibs[entry.ID]; 
!isCommon {
-                                       selectedArtifacts = 
append(selectedArtifacts, entry)
+                                       ctx.SelectedArtifacts = 
append(ctx.SelectedArtifacts, entry)
                                }
                        }
-
-                       ctx.BaseImage = bestImage.Image
-                       ctx.SelectedArtifacts = selectedArtifacts
                }
 
                return nil
@@ -346,7 +345,7 @@ func imageContext(ctx *Context, selector artifactsSelector) 
error {
        return nil
 }
 
-func listPublishedImages(context *Context) ([]publishedImage, error) {
+func listPublishedImages(context *Context) ([]v1.IntegrationKitStatus, error) {
        options := []k8sclient.ListOption{
                k8sclient.InNamespace(context.Namespace),
                k8sclient.MatchingLabels{
@@ -364,7 +363,7 @@ func listPublishedImages(context *Context) 
([]publishedImage, error) {
                return nil, err
        }
 
-       images := make([]publishedImage, 0)
+       images := make([]v1.IntegrationKitStatus, 0)
        for _, item := range list.Items {
                kit := item
 
@@ -372,17 +371,13 @@ func listPublishedImages(context *Context) 
([]publishedImage, error) {
                        continue
                }
 
-               images = append(images, publishedImage{
-                       Image:        kit.Status.Image,
-                       Artifacts:    kit.Status.Artifacts,
-                       Dependencies: kit.Spec.Dependencies,
-               })
+               images = append(images, kit.Status)
        }
        return images, nil
 }
 
-func findBestImage(images []publishedImage, artifacts []v1.Artifact) 
(publishedImage, map[string]bool) {
-       var bestImage publishedImage
+func findBestImage(images []v1.IntegrationKitStatus, artifacts []v1.Artifact) 
(v1.IntegrationKitStatus, map[string]bool) {
+       var bestImage v1.IntegrationKitStatus
 
        if len(images) == 0 {
                return bestImage, nil
diff --git a/pkg/builder/builder_types.go b/pkg/builder/builder_types.go
index d7bdda9..529a78a 100644
--- a/pkg/builder/builder_types.go
+++ b/pkg/builder/builder_types.go
@@ -122,9 +122,3 @@ type Context struct {
 func (c *Context) HasRequiredImage() bool {
        return c.Build.Image != ""
 }
-
-type publishedImage struct {
-       Image        string
-       Artifacts    []v1.Artifact
-       Dependencies []string
-}

Reply via email to