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

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


The following commit(s) were added to refs/heads/main by this push:
     new b8a6398ca feat: Auto-create platform when registry can be inferred 
from KEP-1755
b8a6398ca is described below

commit b8a6398cae07a37dc697192914119ae6acbab065
Author: Antonin Stefanutti <anto...@stefanutti.fr>
AuthorDate: Wed Sep 7 11:02:33 2022 +0200

    feat: Auto-create platform when registry can be inferred from KEP-1755
---
 pkg/trait/platform.go | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/pkg/trait/platform.go b/pkg/trait/platform.go
index 635bc1258..d2e7b6783 100644
--- a/pkg/trait/platform.go
+++ b/pkg/trait/platform.go
@@ -20,7 +20,7 @@ package trait
 import (
        "fmt"
 
-       k8serrors "k8s.io/apimachinery/pkg/api/errors"
+       apierrors "k8s.io/apimachinery/pkg/api/errors"
        "k8s.io/utils/pointer"
 
        v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
@@ -29,6 +29,7 @@ import (
        "github.com/apache/camel-k/pkg/platform"
        "github.com/apache/camel-k/pkg/util/defaults"
        "github.com/apache/camel-k/pkg/util/openshift"
+       image "github.com/apache/camel-k/pkg/util/registry"
 )
 
 type platformTrait struct {
@@ -59,6 +60,10 @@ func (t *platformTrait) Configure(e *Environment) (bool, 
error) {
                                        return false, err
                                } else if ocp {
                                        t.CreateDefault = &ocp
+                               } else if addr, err := 
image.GetRegistryAddress(e.Ctx, t.Client); err != nil {
+                                       return false, err
+                               } else if addr != nil {
+                                       t.CreateDefault = pointer.Bool(true)
                                }
                        }
                        if t.Global == nil {
@@ -96,7 +101,7 @@ func (t *platformTrait) Apply(e *Environment) error {
 
 func (t *platformTrait) getOrCreatePlatform(e *Environment) 
(*v1.IntegrationPlatform, error) {
        pl, err := platform.GetOrFindForResource(e.Ctx, t.Client, 
e.Integration, false)
-       if err != nil && k8serrors.IsNotFound(err) {
+       if err != nil && apierrors.IsNotFound(err) {
                if pointer.BoolDeref(t.CreateDefault, false) {
                        platformName := e.Integration.Status.Platform
                        if platformName == "" {
@@ -126,7 +131,7 @@ func (t *platformTrait) getOrCreatePlatform(e *Environment) 
(*v1.IntegrationPlat
                        e.Resources.Add(pl)
 
                        // Make sure that IntegrationPlatform installed in 
operator namespace can be seen by others
-                       if err := install.IntegrationPlatformViewerRole(e.Ctx, 
t.Client, namespace); err != nil && !k8serrors.IsAlreadyExists(err) {
+                       if err := install.IntegrationPlatformViewerRole(e.Ctx, 
t.Client, namespace); err != nil && !apierrors.IsAlreadyExists(err) {
                                t.L.Info(fmt.Sprintf("Cannot install global 
IntegrationPlatform viewer role in namespace '%s': skipping.", namespace))
                        }
 

Reply via email to