You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2018/12/11 21:18:35 UTC
[camel-k] 01/02: Fix #221: use registry name instead of IP in
Knative on Openshift
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 f6b4a599664ddf6e0cb492e0cdcc9195391e030c
Author: nferraro <ni...@gmail.com>
AuthorDate: Tue Dec 11 15:36:47 2018 +0100
Fix #221: use registry name instead of IP in Knative on Openshift
---
pkg/builder/builder_types.go | 4 ++--
pkg/trait/builder.go | 22 ++++++++++++++++++++++
pkg/trait/builder_test.go | 10 ++++++++++
pkg/trait/knative.go | 2 ++
pkg/trait/springboot.go | 2 +-
5 files changed, 37 insertions(+), 3 deletions(-)
diff --git a/pkg/builder/builder_types.go b/pkg/builder/builder_types.go
index 47c59e0..7d7768d 100644
--- a/pkg/builder/builder_types.go
+++ b/pkg/builder/builder_types.go
@@ -31,8 +31,8 @@ import (
)
const (
- // IntiPhase --
- IntiPhase int32 = 0
+ // InitPhase --
+ InitPhase int32 = 0
// ProjectGenerationPhase --
ProjectGenerationPhase int32 = 10
// ProjectBuildPhase --
diff --git a/pkg/trait/builder.go b/pkg/trait/builder.go
index e495510..273bed7 100644
--- a/pkg/trait/builder.go
+++ b/pkg/trait/builder.go
@@ -23,6 +23,11 @@ import (
"github.com/apache/camel-k/pkg/builder/kaniko"
"github.com/apache/camel-k/pkg/builder/s2i"
"github.com/apache/camel-k/pkg/platform"
+ "regexp"
+)
+
+const (
+ openshiftDockerRegistryHost = "docker-registry.default.svc"
)
// TODO: we should add a way to label a trait as platform so it cannot be disabled/removed
@@ -58,6 +63,9 @@ func (t *builderTrait) Apply(e *Environment) error {
if e.IntegrationContextInPhase(v1alpha1.IntegrationContextPhaseBuilding) {
if platform.SupportsS2iPublishStrategy(e.Platform) {
e.Steps = s2i.DefaultSteps
+ if e.DetermineProfile() == v1alpha1.TraitProfileKnative {
+ e.Steps = append(e.Steps, builder.NewStep("publisher/replaceHost", builder.ApplicationPublishPhase+1, t.ReplaceHost))
+ }
} else if platform.SupportsKanikoPublishStrategy(e.Platform) {
e.Steps = kaniko.DefaultSteps
e.BuildDir = kaniko.BuildDir
@@ -71,6 +79,9 @@ func (t *builderTrait) Apply(e *Environment) error {
builder.NewStep("publisher/s2i", builder.ApplicationPublishPhase, s2i.Publisher),
builder.NewStep("notify/integration", builder.NotifyPhase, builder.NotifyIntegration),
}
+ if e.DetermineProfile() == v1alpha1.TraitProfileKnative {
+ e.Steps = append(e.Steps, builder.NewStep("publisher/replaceHost", builder.ApplicationPublishPhase+1, t.ReplaceHost))
+ }
} else if platform.SupportsKanikoPublishStrategy(e.Platform) {
e.Steps = []builder.Step{
builder.NewStep("packager", builder.ApplicationPackagePhase, builder.StandardPackager),
@@ -83,3 +94,14 @@ func (t *builderTrait) Apply(e *Environment) error {
return nil
}
+
+func (t *builderTrait) ReplaceHost(ctx *builder.Context) error {
+ ctx.Image = getImageWithOpenShiftHost(ctx.Image)
+ return nil
+}
+
+func getImageWithOpenShiftHost(image string) string {
+ pattern := regexp.MustCompile(`^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+([:/].*)`)
+ return pattern.ReplaceAllString(image, openshiftDockerRegistryHost+"$1")
+ return image
+}
diff --git a/pkg/trait/builder_test.go b/pkg/trait/builder_test.go
index c4bb0ee..cb9147f 100644
--- a/pkg/trait/builder_test.go
+++ b/pkg/trait/builder_test.go
@@ -141,3 +141,13 @@ func createBuilderTestEnv(cluster v1alpha1.IntegrationPlatformCluster, strategy
Resources: kubernetes.NewCollection(),
}
}
+
+func TestIPReplacement(t *testing.T) {
+ assert.Equal(t, "docker-registry.default.svc:5000/myproject/camel-k:1234", getImageWithOpenShiftHost("172.30.1.1:5000/myproject/camel-k:1234"))
+ assert.Equal(t, "docker-registry.default.svc/myproject/camel-k:1234", getImageWithOpenShiftHost("172.30.1.1/myproject/camel-k:1234"))
+ assert.Equal(t, "docker-registry.default.svc/myproject/camel-k:1234", getImageWithOpenShiftHost("10.0.0.1/myproject/camel-k:1234"))
+ assert.Equal(t, "docker-registry.default.svc/camel-k", getImageWithOpenShiftHost("10.0.0.1/camel-k"))
+ assert.Equal(t, "10.0.2.3.4/camel-k", getImageWithOpenShiftHost("10.0.2.3.4/camel-k"))
+ assert.Equal(t, "gcr.io/camel-k/camel-k:latest", getImageWithOpenShiftHost("gcr.io/camel-k/camel-k:latest"))
+ assert.Equal(t, "docker.io/camel-k:latest", getImageWithOpenShiftHost("docker.io/camel-k:latest"))
+}
\ No newline at end of file
diff --git a/pkg/trait/knative.go b/pkg/trait/knative.go
index a40abb3..93e16a0 100644
--- a/pkg/trait/knative.go
+++ b/pkg/trait/knative.go
@@ -169,6 +169,8 @@ func (t *knativeTrait) getServiceFor(e *Environment) *serving.Service {
}
annotations := make(map[string]string)
+ // Resolve registry host names when used
+ annotations["alpha.image.policy.openshift.io/resolve-names"] = "*"
if t.MinScale != nil {
annotations[knativeMinScaleAnnotation] = strconv.Itoa(*t.MinScale)
}
diff --git a/pkg/trait/springboot.go b/pkg/trait/springboot.go
index 522a526..116c684 100644
--- a/pkg/trait/springboot.go
+++ b/pkg/trait/springboot.go
@@ -107,7 +107,7 @@ func (t *springBootTrait) Apply(e *Environment) error {
if e.Context != nil && e.Context.Status.Phase == v1alpha1.IntegrationContextPhaseBuilding {
// add custom initialization logic
- e.Steps = append(e.Steps, builder.NewStep("initialize/spring-boot", builder.IntiPhase, springboot.Initialize))
+ e.Steps = append(e.Steps, builder.NewStep("initialize/spring-boot", builder.InitPhase, springboot.Initialize))
e.Steps = append(e.Steps, builder.NewStep("build/compute-boot-dependencies", builder.ProjectBuildPhase+1, springboot.ComputeDependencies))
// replace project generator