Skip to content

Commit

Permalink
fix(controller): camelcatalog default timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
squakez committed Apr 10, 2023
1 parent 419f563 commit e5d76fd
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 12 deletions.
8 changes: 8 additions & 0 deletions config/crd/bases/camel.apache.org_integrationplatforms.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions docs/modules/ROOT/partials/apis/camel-k-crds.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]*
|
Expand Down
23 changes: 23 additions & 0 deletions e2e/commonwithcustominstall/catalog_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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"))
})
}
10 changes: 10 additions & 0 deletions e2e/support/test_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions helm/camel-k/crds/crd-integration-platform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/camel/v1/integrationplatform_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 17 additions & 3 deletions pkg/controller/catalog/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions pkg/platform/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e5d76fd

Please sign in to comment.