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

commit 47b959e7f3f506006cd6c41331ac8e9c7f8055ee
Author: nferraro <ni.ferr...@gmail.com>
AuthorDate: Tue Dec 11 16:51:55 2018 +0100

    Fix #221: adding the publicImage field for deployments (image to be used 
for inheritance)
---
 pkg/apis/camel/v1alpha1/types.go             | 17 +++++++++++++----
 pkg/builder/builder.go                       | 12 +++++++-----
 pkg/builder/builder_types.go                 | 14 ++++++++------
 pkg/stub/action/context/build.go             |  1 +
 pkg/stub/action/integration/build_context.go |  4 ++--
 pkg/stub/action/integration/build_image.go   |  6 +++++-
 pkg/trait/builder.go                         |  2 +-
 7 files changed, 37 insertions(+), 19 deletions(-)

diff --git a/pkg/apis/camel/v1alpha1/types.go b/pkg/apis/camel/v1alpha1/types.go
index 3876e82..813c2b6 100644
--- a/pkg/apis/camel/v1alpha1/types.go
+++ b/pkg/apis/camel/v1alpha1/types.go
@@ -200,10 +200,19 @@ type IntegrationContextSpec struct {
 
 // IntegrationContextStatus --
 type IntegrationContextStatus struct {
-       Phase     IntegrationContextPhase `json:"phase,omitempty"`
-       Image     string                  `json:"image,omitempty"`
-       Digest    string                  `json:"digest,omitempty"`
-       Artifacts []Artifact              `json:"artifacts,omitempty"`
+       Phase       IntegrationContextPhase `json:"phase,omitempty"`
+       Image       string                  `json:"image,omitempty"`
+       PublicImage string                  `json:"publicImage,omitempty"`
+       Digest      string                  `json:"digest,omitempty"`
+       Artifacts   []Artifact              `json:"artifacts,omitempty"`
+}
+
+// ImageForIntegration returns the image to use when using it for running an 
integration
+func (c IntegrationContext) ImageForIntegration() string {
+       if c.Status.PublicImage != "" {
+               return c.Status.PublicImage
+       }
+       return c.Status.Image
 }
 
 // IntegrationContextPhase --
diff --git a/pkg/builder/builder.go b/pkg/builder/builder.go
index f4dad8b..ffe9f92 100644
--- a/pkg/builder/builder.go
+++ b/pkg/builder/builder.go
@@ -191,6 +191,7 @@ func (b *defaultBuilder) submit(request Request) {
 
        r.Status = StatusCompleted
        r.Image = c.Image
+       r.PublicImage = c.PublicImage
        r.Error = c.Error
        r.Task.CompletedAt = time.Now()
 
@@ -205,9 +206,10 @@ func (b *defaultBuilder) submit(request Request) {
        b.request.Store(request.Meta.Name, r)
 
        b.log.Infof("request to build context %s executed in %f seconds", 
request.Meta.Name, r.Task.Elapsed().Seconds())
-       b.log.Infof("dependencies       : %s", request.Dependencies)
-       b.log.Infof("artifacts          : %s", ArtifactIDs(c.Artifacts))
-       b.log.Infof("artifacts selected : %s", ArtifactIDs(c.SelectedArtifacts))
-       b.log.Infof("requested image    : %s", request.Image)
-       b.log.Infof("resolved image     : %s", c.Image)
+       b.log.Infof("dependencies          : %s", request.Dependencies)
+       b.log.Infof("artifacts             : %s", ArtifactIDs(c.Artifacts))
+       b.log.Infof("artifacts selected    : %s", 
ArtifactIDs(c.SelectedArtifacts))
+       b.log.Infof("requested image       : %s", request.Image)
+       b.log.Infof("resolved image        : %s", c.Image)
+       b.log.Infof("resolved public image : %s", c.PublicImage)
 }
diff --git a/pkg/builder/builder_types.go b/pkg/builder/builder_types.go
index 7d7768d..54f9774 100644
--- a/pkg/builder/builder_types.go
+++ b/pkg/builder/builder_types.go
@@ -125,12 +125,13 @@ func (t Task) Elapsed() time.Duration {
 
 // Result represents the result of a build
 type Result struct {
-       Request   Request
-       Image     string
-       Error     error
-       Status    Status
-       Artifacts []v1alpha1.Artifact
-       Task      Task
+       Request     Request
+       Image       string
+       PublicImage string
+       Error       error
+       Status      Status
+       Artifacts   []v1alpha1.Artifact
+       Task        Task
 }
 
 // Context --
@@ -138,6 +139,7 @@ type Context struct {
        C                 context.Context
        Request           Request
        Image             string
+       PublicImage       string
        Error             error
        Namespace         string
        Project           maven.Project
diff --git a/pkg/stub/action/context/build.go b/pkg/stub/action/context/build.go
index e36fc71..7f47bc3 100644
--- a/pkg/stub/action/context/build.go
+++ b/pkg/stub/action/context/build.go
@@ -89,6 +89,7 @@ func (action *buildAction) Handle(context 
*v1alpha1.IntegrationContext) error {
        case builder.StatusCompleted:
                target := context.DeepCopy()
                target.Status.Image = res.Image
+               target.Status.PublicImage = res.PublicImage
                target.Status.Phase = v1alpha1.IntegrationContextPhaseReady
                target.Status.Artifacts = make([]v1alpha1.Artifact, 0, 
len(res.Artifacts))
 
diff --git a/pkg/stub/action/integration/build_context.go 
b/pkg/stub/action/integration/build_context.go
index ecadcc5..97da4aa 100644
--- a/pkg/stub/action/integration/build_context.go
+++ b/pkg/stub/action/integration/build_context.go
@@ -78,7 +78,7 @@ func (action *buildContextAction) Handle(integration 
*v1alpha1.Integration) erro
 
                if ctx.Status.Phase == v1alpha1.IntegrationContextPhaseError {
                        target := integration.DeepCopy()
-                       target.Status.Image = ctx.Status.Image
+                       target.Status.Image = ctx.ImageForIntegration()
                        target.Spec.Context = ctx.Name
                        target.Status.Phase = v1alpha1.IntegrationPhaseError
 
@@ -94,7 +94,7 @@ func (action *buildContextAction) Handle(integration 
*v1alpha1.Integration) erro
 
                if ctx.Status.Phase == v1alpha1.IntegrationContextPhaseReady {
                        target := integration.DeepCopy()
-                       target.Status.Image = ctx.Status.Image
+                       target.Status.Image = ctx.ImageForIntegration()
                        target.Spec.Context = ctx.Name
 
                        dgst, err := digest.ComputeForIntegration(target)
diff --git a/pkg/stub/action/integration/build_image.go 
b/pkg/stub/action/integration/build_image.go
index fdc76d8..e23e6d0 100644
--- a/pkg/stub/action/integration/build_image.go
+++ b/pkg/stub/action/integration/build_image.go
@@ -122,7 +122,11 @@ func (action *buildImageAction) Handle(integration 
*v1alpha1.Integration) error
        case builder.StatusCompleted:
                target := integration.DeepCopy()
                target.Status.Phase = v1alpha1.IntegrationPhaseDeploying
-               target.Status.Image = res.Image
+               if res.PublicImage != "" {
+                       target.Status.Image = res.PublicImage
+               } else {
+                       target.Status.Image = res.Image
+               }
 
                dgst, err := digest.ComputeForIntegration(integration)
                if err != nil {
diff --git a/pkg/trait/builder.go b/pkg/trait/builder.go
index 273bed7..fd11fa2 100644
--- a/pkg/trait/builder.go
+++ b/pkg/trait/builder.go
@@ -96,7 +96,7 @@ func (t *builderTrait) Apply(e *Environment) error {
 }
 
 func (t *builderTrait) ReplaceHost(ctx *builder.Context) error {
-       ctx.Image = getImageWithOpenShiftHost(ctx.Image)
+       ctx.PublicImage = getImageWithOpenShiftHost(ctx.Image)
        return nil
 }
 

Reply via email to