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 0aadb7e7f562c822d6ae8854c4f58eaa9da3423c Author: Pasquale Congiusti <[email protected]> AuthorDate: Tue Apr 11 10:34:07 2023 +0200 chore(api): make catalog timeout a Duration --- .../camel.apache.org_integrationplatforms.yaml | 4 +-- docs/modules/ROOT/partials/apis/camel-k-crds.adoc | 2 +- .../catalog_builder_test.go | 14 ++++++++-- e2e/support/test_support.go | 6 ++-- helm/camel-k/crds/crd-integration-platform.yaml | 4 +-- pkg/apis/camel/v1/integrationplatform_types.go | 2 +- .../camel/v1/integrationplatform_types_support.go | 10 ++++++- pkg/apis/camel/v1/zz_generated.deepcopy.go | 5 ++++ .../camel/v1/integrationplatformbuildspec.go | 4 +-- pkg/controller/catalog/initialize.go | 12 +++++--- pkg/platform/defaults.go | 32 ++++++++++++++++------ 11 files changed, 68 insertions(+), 27 deletions(-) diff --git a/config/crd/bases/camel.apache.org_integrationplatforms.yaml b/config/crd/bases/camel.apache.org_integrationplatforms.yaml index ff540749e..5589fbc0f 100644 --- a/config/crd/bases/camel.apache.org_integrationplatforms.yaml +++ b/config/crd/bases/camel.apache.org_integrationplatforms.yaml @@ -83,7 +83,7 @@ spec: buildCatalogToolTimeout: description: the timeout (in seconds) to use when creating the build tools container image - type: integer + type: string buildStrategy: description: the strategy to adopt for building an Integration base image @@ -1633,7 +1633,7 @@ spec: buildCatalogToolTimeout: description: the timeout (in seconds) to use when creating the build tools container image - type: integer + type: string 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 04c256594..5a093cd9a 100644 --- a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc +++ b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc @@ -1878,7 +1878,7 @@ 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 +*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 93abed2f6..9184c1ff7 100644 --- a/e2e/commonwithcustominstall/catalog_builder_test.go +++ b/e2e/commonwithcustominstall/catalog_builder_test.go @@ -26,9 +26,11 @@ import ( "fmt" "strings" "testing" + "time" . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" . "github.com/apache/camel-k/v2/e2e/support" v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" @@ -153,11 +155,17 @@ func TestCamelCatalogBuilder(t *testing.T) { Eventually(Platform(ns)).ShouldNot(BeNil()) pl := Platform(ns)() - // set a very short timeout to simulate it - pl.Spec.Build.BuildCatalogToolTimeout = 1 + // set a very short timeout to simulate the timeout + pl.Spec.Build.BuildCatalogToolTimeout = &metav1.Duration{ + Duration: 1 * time.Second, + } TestClient().Update(TestContext, pl) Eventually(Platform(ns)).ShouldNot(BeNil()) - Eventually(PlatformBuildCatalogToolTimeout(ns)).Should(Equal(1)) + Eventually(PlatformBuildCatalogToolTimeout(ns)).Should(Equal( + &metav1.Duration{ + Duration: 1 * time.Second, + }, + )) Eventually(PlatformConditionStatus(ns, v1.IntegrationPlatformConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionTrue)) diff --git a/e2e/support/test_support.go b/e2e/support/test_support.go index db42596ac..bc058c843 100644 --- a/e2e/support/test_support.go +++ b/e2e/support/test_support.go @@ -1779,11 +1779,11 @@ func PlatformProfile(ns string) func() v1.TraitProfile { } } -func PlatformBuildCatalogToolTimeout(ns string) func() int { - return func() int { +func PlatformBuildCatalogToolTimeout(ns string) func() *metav1.Duration { + return func() *metav1.Duration { p := Platform(ns)() if p == nil { - return 0 + return &metav1.Duration{} } return p.Status.Build.BuildCatalogToolTimeout } diff --git a/helm/camel-k/crds/crd-integration-platform.yaml b/helm/camel-k/crds/crd-integration-platform.yaml index ff540749e..5589fbc0f 100644 --- a/helm/camel-k/crds/crd-integration-platform.yaml +++ b/helm/camel-k/crds/crd-integration-platform.yaml @@ -83,7 +83,7 @@ spec: buildCatalogToolTimeout: description: the timeout (in seconds) to use when creating the build tools container image - type: integer + type: string buildStrategy: description: the strategy to adopt for building an Integration base image @@ -1633,7 +1633,7 @@ spec: buildCatalogToolTimeout: description: the timeout (in seconds) to use when creating the build tools container image - type: integer + type: string 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 d8b0a3f58..f63163094 100644 --- a/pkg/apis/camel/v1/integrationplatform_types.go +++ b/pkg/apis/camel/v1/integrationplatform_types.go @@ -121,7 +121,7 @@ type IntegrationPlatformBuildSpec struct { // 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"` + BuildCatalogToolTimeout *metav1.Duration `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/apis/camel/v1/integrationplatform_types_support.go b/pkg/apis/camel/v1/integrationplatform_types_support.go index 0d9b0a2e4..599f40ef7 100644 --- a/pkg/apis/camel/v1/integrationplatform_types_support.go +++ b/pkg/apis/camel/v1/integrationplatform_types_support.go @@ -186,7 +186,7 @@ func (b IntegrationPlatformBuildSpec) IsOptionEnabled(option string) bool { return false } -// Add a publish strategy option +// AddOption add a publish strategy option func (b *IntegrationPlatformBuildSpec) AddOption(option string, value string) { options := b.PublishStrategyOptions if options == nil { @@ -204,6 +204,14 @@ func (b IntegrationPlatformBuildSpec) GetTimeout() metav1.Duration { return *b.Timeout } +// GetBuildCatalogToolTimeout returns the specified duration or a default one +func (b IntegrationPlatformBuildSpec) GetBuildCatalogToolTimeout() metav1.Duration { + if b.BuildCatalogToolTimeout == nil { + return metav1.Duration{} + } + return *b.BuildCatalogToolTimeout +} + var _ ResourceCondition = IntegrationPlatformCondition{} // GetConditions -- diff --git a/pkg/apis/camel/v1/zz_generated.deepcopy.go b/pkg/apis/camel/v1/zz_generated.deepcopy.go index 1ace84bea..f7b543f17 100644 --- a/pkg/apis/camel/v1/zz_generated.deepcopy.go +++ b/pkg/apis/camel/v1/zz_generated.deepcopy.go @@ -991,6 +991,11 @@ func (in *IntegrationPlatform) DeepCopyObject() runtime.Object { func (in *IntegrationPlatformBuildSpec) DeepCopyInto(out *IntegrationPlatformBuildSpec) { *out = *in out.Registry = in.Registry + if in.BuildCatalogToolTimeout != nil { + in, out := &in.BuildCatalogToolTimeout, &out.BuildCatalogToolTimeout + *out = new(metav1.Duration) + **out = **in + } if in.Timeout != nil { in, out := &in.Timeout, &out.Timeout *out = new(metav1.Duration) diff --git a/pkg/client/camel/applyconfiguration/camel/v1/integrationplatformbuildspec.go b/pkg/client/camel/applyconfiguration/camel/v1/integrationplatformbuildspec.go index d2806ae60..d884675af 100644 --- a/pkg/client/camel/applyconfiguration/camel/v1/integrationplatformbuildspec.go +++ b/pkg/client/camel/applyconfiguration/camel/v1/integrationplatformbuildspec.go @@ -33,7 +33,7 @@ type IntegrationPlatformBuildSpecApplyConfiguration struct { RuntimeProvider *v1.RuntimeProvider `json:"runtimeProvider,omitempty"` BaseImage *string `json:"baseImage,omitempty"` Registry *RegistrySpecApplyConfiguration `json:"registry,omitempty"` - BuildCatalogToolTimeout *int `json:"buildCatalogToolTimeout,omitempty"` + BuildCatalogToolTimeout *metav1.Duration `json:"buildCatalogToolTimeout,omitempty"` Timeout *metav1.Duration `json:"timeout,omitempty"` Maven *MavenSpecApplyConfiguration `json:"maven,omitempty"` PublishStrategyOptions map[string]string `json:"PublishStrategyOptions,omitempty"` @@ -96,7 +96,7 @@ func (b *IntegrationPlatformBuildSpecApplyConfiguration) WithRegistry(value *Reg // 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 { +func (b *IntegrationPlatformBuildSpecApplyConfiguration) WithBuildCatalogToolTimeout(value metav1.Duration) *IntegrationPlatformBuildSpecApplyConfiguration { b.BuildCatalogToolTimeout = &value return b } diff --git a/pkg/controller/catalog/initialize.go b/pkg/controller/catalog/initialize.go index 28fe28b73..98d4ddfbe 100644 --- a/pkg/controller/catalog/initialize.go +++ b/pkg/controller/catalog/initialize.go @@ -72,14 +72,14 @@ func (action *initializeAction) Handle(ctx context.Context, catalog *v1.CamelCat return catalog, err } - return initialize(options, platform.Status.Build.Registry.Address, platform.Status.Build.BuildCatalogToolTimeout, catalog) + return initialize(options, platform, catalog) } -func initialize(options spectrum.Options, registryAddress string, buildCatalogTimeout int, catalog *v1.CamelCatalog) (*v1.CamelCatalog, error) { +func initialize(options spectrum.Options, ip *v1.IntegrationPlatform, catalog *v1.CamelCatalog) (*v1.CamelCatalog, error) { target := catalog.DeepCopy() imageName := fmt.Sprintf( "%s/camel-k-runtime-%s-builder:%s", - registryAddress, + ip.Status.Build.Registry.Address, catalog.Spec.Runtime.Provider, strings.ToLower(catalog.Spec.Runtime.Version), ) @@ -116,7 +116,7 @@ func initialize(options spectrum.Options, registryAddress string, buildCatalogTi options.Base = catalog.Spec.GetQuarkusToolingImage() options.Target = imageName - err := buildRuntimeBuilderWithTimeout(options, time.Duration(buildCatalogTimeout)*time.Second) + err := buildRuntimeBuilderWithTimeout(options, ip.Status.Build.GetBuildCatalogToolTimeout().Duration) if err != nil { target.Status.Phase = v1.CamelCatalogPhaseError @@ -161,6 +161,10 @@ func imageSnapshot(options spectrum.Options) bool { } func buildRuntimeBuilderWithTimeout(options spectrum.Options, timeout time.Duration) error { + // Backward compatibility with IP which had not a timeout field + if timeout == 0 { + return buildRuntimeBuilderImage(options) + } result := make(chan error, 1) go func() { result <- buildRuntimeBuilderImage(options) diff --git a/pkg/platform/defaults.go b/pkg/platform/defaults.go index 981863c72..fa24f4fa9 100644 --- a/pkg/platform/defaults.go +++ b/pkg/platform/defaults.go @@ -209,7 +209,12 @@ func setPlatformDefaults(p *v1.IntegrationPlatform, verbose bool) error { p.Status.Build.PublishStrategyOptions[builder.KanikoPVCName] = p.Name } - if p.Status.Build.GetTimeout().Duration != 0 { + // Build timeout + if p.Status.Build.GetTimeout().Duration == 0 { + p.Status.Build.Timeout = &metav1.Duration{ + Duration: 5 * time.Minute, + } + } else { d := p.Status.Build.GetTimeout().Duration.Truncate(time.Second) if verbose && p.Status.Build.GetTimeout().Duration != d { @@ -221,15 +226,26 @@ func setPlatformDefaults(p *v1.IntegrationPlatform, verbose bool) error { Duration: d, } } - if p.Status.Build.GetTimeout().Duration == 0 { - p.Status.Build.Timeout = &metav1.Duration{ - Duration: 5 * time.Minute, + + // Catalog tools build timeout + if p.Status.Build.GetBuildCatalogToolTimeout().Duration == 0 { + log.Debugf("Integration Platform [%s]: setting default build camel catalog tool timeout (1 minute)", p.Namespace) + p.Status.Build.BuildCatalogToolTimeout = &metav1.Duration{ + Duration: 1 * time.Minute, + } + } else { + d := p.Status.Build.GetBuildCatalogToolTimeout().Duration.Truncate(time.Second) + + if verbose && p.Status.Build.GetBuildCatalogToolTimeout().Duration != d { + log.Log.Infof("Build catalog tools timeout minimum unit is sec (configured: %s, truncated: %s)", p.Status.Build.GetBuildCatalogToolTimeout().Duration, d) + } + + log.Debugf("Integration Platform [%s]: setting build catalog tools timeout", p.Namespace) + p.Status.Build.BuildCatalogToolTimeout = &metav1.Duration{ + Duration: d, } } - 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
