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

squakez 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 3942816b1 chore(trait): fail fast if registry is missing
3942816b1 is described below

commit 3942816b1795205730614024cb26c50bafabfc2c
Author: Pasquale Congiusti <[email protected]>
AuthorDate: Fri Oct 9 08:42:58 2026 +0200

    chore(trait): fail fast if registry is missing
---
 pkg/controller/integration/build_test.go | 39 ++++++++++++--------------------
 pkg/trait/builder.go                     | 17 ++++++++++----
 pkg/trait/builder_test.go                | 31 +++++++++++++++++++++++++
 3 files changed, 59 insertions(+), 28 deletions(-)

diff --git a/pkg/controller/integration/build_test.go 
b/pkg/controller/integration/build_test.go
index 682edd41d..b520cf951 100644
--- a/pkg/controller/integration/build_test.go
+++ b/pkg/controller/integration/build_test.go
@@ -24,6 +24,7 @@ import (
 
        v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
        "github.com/apache/camel-k/v2/pkg/internal"
+       "github.com/apache/camel-k/v2/pkg/platform"
        "github.com/apache/camel-k/v2/pkg/util/defaults"
        "github.com/apache/camel-k/v2/pkg/util/log"
        "github.com/stretchr/testify/assert"
@@ -34,15 +35,13 @@ import (
 )
 
 func TestIntegrationBuildSubmitted(t *testing.T) {
+       t.Setenv("REGISTRY_ADDRESS", "1.2.3.4")
+       platform.InitPlatform()
        it := &v1.Integration{
-               TypeMeta: metav1.TypeMeta{
-                       APIVersion: v1.SchemeGroupVersion.String(),
-                       Kind:       v1.IntegrationKind,
-               },
-               ObjectMeta: metav1.ObjectMeta{
-                       Namespace: "ns",
-                       Name:      "my-it",
-               },
+               APIVersion: v1.SchemeGroupVersion.String(),
+               Kind:       v1.IntegrationKind,
+               Namespace:  "ns",
+               Name:       "my-it",
                Spec: v1.IntegrationSpec{
                        Git: &v1.GitConfigSpec{
                                URL: "missing",
@@ -53,14 +52,10 @@ func TestIntegrationBuildSubmitted(t *testing.T) {
                },
        }
        catalog := &v1.CamelCatalog{
-               TypeMeta: metav1.TypeMeta{
-                       APIVersion: v1.SchemeGroupVersion.String(),
-                       Kind:       v1.CamelCatalogKind,
-               },
-               ObjectMeta: metav1.ObjectMeta{
-                       Namespace: "ns",
-                       Name:      "camel-k-catalog",
-               },
+               APIVersion: v1.SchemeGroupVersion.String(),
+               Kind:       v1.CamelCatalogKind,
+               Namespace:  "ns",
+               Name:       "camel-k-catalog",
                Spec: v1.CamelCatalogSpec{
                        Runtime: v1.RuntimeSpec{
                                Provider: v1.RuntimeProviderQuarkus,
@@ -88,14 +83,10 @@ func TestIntegrationBuildSubmitted(t *testing.T) {
 
        // Verify the downstream build created
        expectedBuild := &v1.Build{
-               TypeMeta: metav1.TypeMeta{
-                       APIVersion: v1.SchemeGroupVersion.String(),
-                       Kind:       v1.BuildKind,
-               },
-               ObjectMeta: metav1.ObjectMeta{
-                       Namespace: "ns",
-                       Name:      "my-it",
-               },
+               APIVersion: v1.SchemeGroupVersion.String(),
+               Kind:       v1.BuildKind,
+               Namespace:  "ns",
+               Name:       "my-it",
        }
        err = c.Get(context.Background(), 
ctrl.ObjectKeyFromObject(expectedBuild), expectedBuild)
        require.NoError(t, err)
diff --git a/pkg/trait/builder.go b/pkg/trait/builder.go
index e22812080..e8e0eed39 100644
--- a/pkg/trait/builder.go
+++ b/pkg/trait/builder.go
@@ -229,7 +229,10 @@ func (t *builderTrait) Apply(e *Environment) error {
                return err
        }
 
-       imageName := getImageName(e)
+       imageName, err := getImageName(e)
+       if err != nil {
+               return err
+       }
 
        // Building task
        builderTask, err := t.builderTask(e, taskConfOrDefault(tasksConf, 
"builder"))
@@ -485,7 +488,10 @@ func getDependencies(e *Environment) []string {
        return nil
 }
 
-func getImageName(e *Environment) string {
+func getImageName(e *Environment) (string, error) {
+       if e.Platform.Registry.Address == "" {
+               return "", errors.New("missing registry address")
+       }
        var imageName string
        if e.IntegrationKit != nil {
                imageName = fmt.Sprintf("%s:%s", e.IntegrationKit.Name, 
e.IntegrationKit.ResourceVersion)
@@ -498,7 +504,7 @@ func getImageName(e *Environment) string {
                organization = e.Platform.CatalogNamespace
        }
 
-       return e.Platform.Registry.Address + "/" + organization + "/camel-k-" + 
imageName
+       return e.Platform.Registry.Address + "/" + organization + "/camel-k-" + 
imageName, nil
 }
 
 func (t *builderTrait) getBaseImage(e *Environment) string {
@@ -511,7 +517,10 @@ func (t *builderTrait) getBaseImage(e *Environment) string 
{
 }
 
 func (t *builderTrait) determineCustomTasks(e *Environment, builderTask 
*v1.BuilderTask, tasksConf map[string]*v1.BuildConfiguration) ([]v1.Task, 
error) {
-       imageName := getImageName(e)
+       imageName, err := getImageName(e)
+       if err != nil {
+               return nil, err
+       }
 
        realBuildStrategy := builderTask.Configuration.Strategy
        if realBuildStrategy == "" {
diff --git a/pkg/trait/builder_test.go b/pkg/trait/builder_test.go
index 71c02cd77..fff5a73b4 100644
--- a/pkg/trait/builder_test.go
+++ b/pkg/trait/builder_test.go
@@ -778,3 +778,34 @@ func TestBuilderTraitTasksEnabledByDefault(t *testing.T) {
        }
        assert.False(t, found, "custom task must not be present when 
builder.tasks is disabled (default)")
 }
+
+func TestGetImageNameOk(t *testing.T) {
+       env := Environment{
+               Platform: platform.Platform{
+                       Registry: v1.RegistrySpec{
+                               Address: "1.2.3.4",
+                       },
+                       CatalogNamespace: "camel-k",
+               },
+               Integration: &v1.Integration{
+                       Name:            "my-it",
+                       ResourceVersion: "987",
+               },
+       }
+       imageName, err := getImageName(&env)
+       require.NoError(t, err)
+       assert.Equal(t, "1.2.3.4/camel-k/camel-k-my-it:987", imageName)
+}
+
+func TestGetImageNameFail(t *testing.T) {
+       env := Environment{
+               Platform: platform.Platform{},
+               Integration: &v1.Integration{
+                       Name:            "my-it",
+                       ResourceVersion: "987",
+               },
+       }
+       _, err := getImageName(&env)
+       require.Error(t, err)
+       assert.Equal(t, "missing registry address", err.Error())
+}

Reply via email to