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

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

commit 9083b9c21e208205048d8f3bfa6d76834d874cc7
Author: Pasquale Congiusti <[email protected]>
AuthorDate: Mon Apr 10 12:10:29 2023 +0200

    fix(controller): camelcatalog default timeout
    
    Closes #4226
---
 .../camel.apache.org_integrationplatforms.yaml     |  8 +++++++
 docs/modules/ROOT/partials/apis/camel-k-crds.adoc  |  7 ++++++
 .../catalog_builder_test.go                        | 23 ++++++++++++++++++
 e2e/support/test_support.go                        | 10 ++++++++
 helm/camel-k/crds/crd-integration-platform.yaml    |  8 +++++++
 pkg/apis/camel/v1/integrationplatform_types.go     |  2 ++
 .../camel/v1/integrationplatformbuildspec.go       | 27 ++++++++++++++--------
 pkg/controller/catalog/initialize.go               | 20 +++++++++++++---
 pkg/platform/defaults.go                           |  4 ++++
 9 files changed, 97 insertions(+), 12 deletions(-)

diff --git a/config/crd/bases/camel.apache.org_integrationplatforms.yaml 
b/config/crd/bases/camel.apache.org_integrationplatforms.yaml
index 51672f39f..ff540749e 100644
--- a/config/crd/bases/camel.apache.org_integrationplatforms.yaml
+++ b/config/crd/bases/camel.apache.org_integrationplatforms.yaml
@@ -80,6 +80,10 @@ spec:
                       images. It can be useful if you want to provide some 
custom
                       base image with further utility softwares
                     type: string
+                  buildCatalogToolTimeout:
+                    description: the timeout (in seconds) to use when creating 
the
+                      build tools container image
+                    type: integer
                   buildStrategy:
                     description: the strategy to adopt for building an 
Integration
                       base image
@@ -1626,6 +1630,10 @@ spec:
                       images. It can be useful if you want to provide some 
custom
                       base image with further utility softwares
                     type: string
+                  buildCatalogToolTimeout:
+                    description: the timeout (in seconds) to use when creating 
the
+                      build tools container image
+                    type: integer
                   buildStrategy:
                     description: the strategy to adopt for building an 
Integration
                       base image
diff --git a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc 
b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc
index a2b565eef..04c256594 100644
--- a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc
+++ b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc
@@ -1877,6 +1877,13 @@ It can be useful if you want to provide some custom base 
image with further util
 
 the image registry used to push/pull Integration images
 
+|`buildCatalogToolTimeout` +
+int
+|
+
+
+the timeout (in seconds) to use when creating the build tools container image
+
 |`timeout` +
 
*https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#duration-v1-meta[Kubernetes
 meta/v1.Duration]*
 |
diff --git a/e2e/commonwithcustominstall/catalog_builder_test.go 
b/e2e/commonwithcustominstall/catalog_builder_test.go
index ee124db65..93abed2f6 100644
--- a/e2e/commonwithcustominstall/catalog_builder_test.go
+++ b/e2e/commonwithcustominstall/catalog_builder_test.go
@@ -36,6 +36,7 @@ import (
 )
 
 func TestCamelCatalogBuilder(t *testing.T) {
+
        WithNewTestNamespace(t, func(ns string) {
                operatorID := fmt.Sprintf("camel-k-%s", ns)
                Expect(KamelInstallWithID(operatorID, 
ns).Execute()).To(Succeed())
@@ -144,4 +145,26 @@ func TestCamelCatalogBuilder(t *testing.T) {
 
                Expect(Kamel("delete", "--all", "-n", 
ns).Execute()).To(Succeed())
        })
+
+       WithNewTestNamespace(t, func(ns string) {
+               operatorID := fmt.Sprintf("camel-k-%s", ns)
+               Expect(KamelInstallWithID(operatorID, 
ns).Execute()).To(Succeed())
+               Eventually(OperatorPod(ns)).ShouldNot(BeNil())
+               Eventually(Platform(ns)).ShouldNot(BeNil())
+
+               pl := Platform(ns)()
+               // set a very short timeout to simulate it
+               pl.Spec.Build.BuildCatalogToolTimeout = 1
+               TestClient().Update(TestContext, pl)
+               Eventually(Platform(ns)).ShouldNot(BeNil())
+               Eventually(PlatformBuildCatalogToolTimeout(ns)).Should(Equal(1))
+
+               Eventually(PlatformConditionStatus(ns, 
v1.IntegrationPlatformConditionReady), TestTimeoutShort).
+                       Should(Equal(corev1.ConditionTrue))
+               catalogName := fmt.Sprintf("camel-catalog-%s", 
strings.ToLower(defaults.DefaultRuntimeVersion))
+
+               Eventually(CamelCatalog(ns, catalogName)).ShouldNot(BeNil())
+               Eventually(CamelCatalogPhase(ns, 
catalogName)).Should(Equal(v1.CamelCatalogPhaseError))
+               Eventually(CamelCatalogCondition(ns, catalogName, 
v1.CamelCatalogConditionReady)().Message).Should(ContainSubstring("build 
timeout"))
+       })
 }
diff --git a/e2e/support/test_support.go b/e2e/support/test_support.go
index 877ca7f40..db42596ac 100644
--- a/e2e/support/test_support.go
+++ b/e2e/support/test_support.go
@@ -1779,6 +1779,16 @@ func PlatformProfile(ns string) func() v1.TraitProfile {
        }
 }
 
+func PlatformBuildCatalogToolTimeout(ns string) func() int {
+       return func() int {
+               p := Platform(ns)()
+               if p == nil {
+                       return 0
+               }
+               return p.Status.Build.BuildCatalogToolTimeout
+       }
+}
+
 func AssignPlatformToOperator(ns, operator string) error {
        pl := Platform(ns)()
        if pl == nil {
diff --git a/helm/camel-k/crds/crd-integration-platform.yaml 
b/helm/camel-k/crds/crd-integration-platform.yaml
index 51672f39f..ff540749e 100644
--- a/helm/camel-k/crds/crd-integration-platform.yaml
+++ b/helm/camel-k/crds/crd-integration-platform.yaml
@@ -80,6 +80,10 @@ spec:
                       images. It can be useful if you want to provide some 
custom
                       base image with further utility softwares
                     type: string
+                  buildCatalogToolTimeout:
+                    description: the timeout (in seconds) to use when creating 
the
+                      build tools container image
+                    type: integer
                   buildStrategy:
                     description: the strategy to adopt for building an 
Integration
                       base image
@@ -1626,6 +1630,10 @@ spec:
                       images. It can be useful if you want to provide some 
custom
                       base image with further utility softwares
                     type: string
+                  buildCatalogToolTimeout:
+                    description: the timeout (in seconds) to use when creating 
the
+                      build tools container image
+                    type: integer
                   buildStrategy:
                     description: the strategy to adopt for building an 
Integration
                       base image
diff --git a/pkg/apis/camel/v1/integrationplatform_types.go 
b/pkg/apis/camel/v1/integrationplatform_types.go
index 0c378f9c7..d8b0a3f58 100644
--- a/pkg/apis/camel/v1/integrationplatform_types.go
+++ b/pkg/apis/camel/v1/integrationplatform_types.go
@@ -120,6 +120,8 @@ type IntegrationPlatformBuildSpec struct {
        BaseImage string `json:"baseImage,omitempty"`
        // the image registry used to push/pull Integration images
        Registry RegistrySpec `json:"registry,omitempty"`
+       // the timeout (in seconds) to use when creating the build tools 
container image
+       BuildCatalogToolTimeout int `json:"buildCatalogToolTimeout,omitempty"`
        // how much time to wait before time out the build process
        Timeout *metav1.Duration `json:"timeout,omitempty"`
        // Maven configuration used to build the Camel/Camel-Quarkus 
applications
diff --git 
a/pkg/client/camel/applyconfiguration/camel/v1/integrationplatformbuildspec.go 
b/pkg/client/camel/applyconfiguration/camel/v1/integrationplatformbuildspec.go
index e57151e07..d2806ae60 100644
--- 
a/pkg/client/camel/applyconfiguration/camel/v1/integrationplatformbuildspec.go
+++ 
b/pkg/client/camel/applyconfiguration/camel/v1/integrationplatformbuildspec.go
@@ -27,15 +27,16 @@ import (
 // IntegrationPlatformBuildSpecApplyConfiguration represents an declarative 
configuration of the IntegrationPlatformBuildSpec type for use
 // with apply.
 type IntegrationPlatformBuildSpecApplyConfiguration struct {
-       BuildStrategy          *v1.BuildStrategy                           
`json:"buildStrategy,omitempty"`
-       PublishStrategy        *v1.IntegrationPlatformBuildPublishStrategy 
`json:"publishStrategy,omitempty"`
-       RuntimeVersion         *string                                     
`json:"runtimeVersion,omitempty"`
-       RuntimeProvider        *v1.RuntimeProvider                         
`json:"runtimeProvider,omitempty"`
-       BaseImage              *string                                     
`json:"baseImage,omitempty"`
-       Registry               *RegistrySpecApplyConfiguration             
`json:"registry,omitempty"`
-       Timeout                *metav1.Duration                            
`json:"timeout,omitempty"`
-       Maven                  *MavenSpecApplyConfiguration                
`json:"maven,omitempty"`
-       PublishStrategyOptions map[string]string                           
`json:"PublishStrategyOptions,omitempty"`
+       BuildStrategy           *v1.BuildStrategy                           
`json:"buildStrategy,omitempty"`
+       PublishStrategy         *v1.IntegrationPlatformBuildPublishStrategy 
`json:"publishStrategy,omitempty"`
+       RuntimeVersion          *string                                     
`json:"runtimeVersion,omitempty"`
+       RuntimeProvider         *v1.RuntimeProvider                         
`json:"runtimeProvider,omitempty"`
+       BaseImage               *string                                     
`json:"baseImage,omitempty"`
+       Registry                *RegistrySpecApplyConfiguration             
`json:"registry,omitempty"`
+       BuildCatalogToolTimeout *int                                        
`json:"buildCatalogToolTimeout,omitempty"`
+       Timeout                 *metav1.Duration                            
`json:"timeout,omitempty"`
+       Maven                   *MavenSpecApplyConfiguration                
`json:"maven,omitempty"`
+       PublishStrategyOptions  map[string]string                           
`json:"PublishStrategyOptions,omitempty"`
 }
 
 // IntegrationPlatformBuildSpecApplyConfiguration constructs an declarative 
configuration of the IntegrationPlatformBuildSpec type for use with
@@ -92,6 +93,14 @@ func (b *IntegrationPlatformBuildSpecApplyConfiguration) 
WithRegistry(value *Reg
        return b
 }
 
+// WithBuildCatalogToolTimeout sets the BuildCatalogToolTimeout field in the 
declarative configuration to the given value
+// and returns the receiver, so that objects can be built by chaining "With" 
function invocations.
+// If called multiple times, the BuildCatalogToolTimeout field is set to the 
value of the last call.
+func (b *IntegrationPlatformBuildSpecApplyConfiguration) 
WithBuildCatalogToolTimeout(value int) 
*IntegrationPlatformBuildSpecApplyConfiguration {
+       b.BuildCatalogToolTimeout = &value
+       return b
+}
+
 // WithTimeout sets the Timeout field in the declarative configuration to the 
given value
 // and returns the receiver, so that objects can be built by chaining "With" 
function invocations.
 // If called multiple times, the Timeout field is set to the value of the last 
call.
diff --git a/pkg/controller/catalog/initialize.go 
b/pkg/controller/catalog/initialize.go
index 11c4d7d33..28fe28b73 100644
--- a/pkg/controller/catalog/initialize.go
+++ b/pkg/controller/catalog/initialize.go
@@ -25,6 +25,7 @@ import (
        "os"
        "runtime"
        "strings"
+       "time"
 
        v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
        "github.com/apache/camel-k/v2/pkg/builder"
@@ -71,10 +72,10 @@ func (action *initializeAction) Handle(ctx context.Context, 
catalog *v1.CamelCat
                return catalog, err
        }
 
-       return initialize(options, platform.Spec.Build.Registry.Address, 
catalog)
+       return initialize(options, platform.Status.Build.Registry.Address, 
platform.Status.Build.BuildCatalogToolTimeout, catalog)
 }
 
-func initialize(options spectrum.Options, registryAddress string, catalog 
*v1.CamelCatalog) (*v1.CamelCatalog, error) {
+func initialize(options spectrum.Options, registryAddress string, 
buildCatalogTimeout int, catalog *v1.CamelCatalog) (*v1.CamelCatalog, error) {
        target := catalog.DeepCopy()
        imageName := fmt.Sprintf(
                "%s/camel-k-runtime-%s-builder:%s",
@@ -115,7 +116,7 @@ func initialize(options spectrum.Options, registryAddress 
string, catalog *v1.Ca
        options.Base = catalog.Spec.GetQuarkusToolingImage()
        options.Target = imageName
 
-       err := buildRuntimeBuilderImage(options)
+       err := buildRuntimeBuilderWithTimeout(options, 
time.Duration(buildCatalogTimeout)*time.Second)
 
        if err != nil {
                target.Status.Phase = v1.CamelCatalogPhaseError
@@ -159,6 +160,19 @@ func imageSnapshot(options spectrum.Options) bool {
        return strings.HasSuffix(options.Base, "snapshot")
 }
 
+func buildRuntimeBuilderWithTimeout(options spectrum.Options, timeout 
time.Duration) error {
+       result := make(chan error, 1)
+       go func() {
+               result <- buildRuntimeBuilderImage(options)
+       }()
+       select {
+       case <-time.After(timeout):
+               return fmt.Errorf("build timeout: %s", timeout.String())
+       case result := <-result:
+               return result
+       }
+}
+
 // This func will take care to dynamically build an image that will contain 
the tools required
 // by the catalog build plus kamel binary and a maven wrapper required for the 
build.
 func buildRuntimeBuilderImage(options spectrum.Options) error {
diff --git a/pkg/platform/defaults.go b/pkg/platform/defaults.go
index d585eb4f6..981863c72 100644
--- a/pkg/platform/defaults.go
+++ b/pkg/platform/defaults.go
@@ -226,6 +226,10 @@ func setPlatformDefaults(p *v1.IntegrationPlatform, 
verbose bool) error {
                        Duration: 5 * time.Minute,
                }
        }
+       if p.Status.Build.BuildCatalogToolTimeout == 0 {
+               log.Debugf("Integration Platform [%s]: setting build camel 
catalog tool timeout", p.Namespace)
+               p.Status.Build.BuildCatalogToolTimeout = 60
+       }
        _, cacheEnabled := 
p.Status.Build.PublishStrategyOptions[builder.KanikoBuildCacheEnabled]
        if p.Status.Build.PublishStrategy == 
v1.IntegrationPlatformBuildPublishStrategyKaniko && !cacheEnabled {
                // Default to disabling Kaniko cache warmer

Reply via email to