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 91df85c10d2369ae3cc45fce5b4dd4d83c9bd2fc Author: Pasquale Congiusti <[email protected]> AuthorDate: Wed May 10 12:14:54 2023 +0200 feat(trait): builder pod resources config * Enabled resource configuration for builder pod * Default resource configuration when Quarkus native build Closes #4177 --- .../duck/client/internalclientset/fake/register.go | 14 ++--- .../client/internalclientset/scheme/register.go | 14 ++--- config/crd/bases/camel.apache.org_builds.yaml | 33 +++++++++-- .../bases/camel.apache.org_integrationkits.yaml | 16 ++++++ .../camel.apache.org_integrationplatforms.yaml | 56 ++++++++++++++++--- .../crd/bases/camel.apache.org_integrations.yaml | 16 ++++++ .../bases/camel.apache.org_kameletbindings.yaml | 16 ++++++ config/crd/bases/camel.apache.org_pipes.yaml | 16 ++++++ docs/modules/ROOT/partials/apis/camel-k-crds.adoc | 44 ++++++++++++--- docs/modules/traits/pages/builder.adoc | 16 ++++++ helm/camel-k/crds/crd-build.yaml | 33 +++++++++-- helm/camel-k/crds/crd-integration-kit.yaml | 16 ++++++ helm/camel-k/crds/crd-integration-platform.yaml | 56 ++++++++++++++++--- helm/camel-k/crds/crd-integration.yaml | 16 ++++++ helm/camel-k/crds/crd-kamelet-binding.yaml | 16 ++++++ helm/camel-k/crds/crd-pipe.yaml | 16 ++++++ pkg/apis/camel/v1/build_types.go | 4 +- pkg/apis/camel/v1/common_types.go | 8 +-- pkg/apis/camel/v1/trait/builder.go | 8 +++ pkg/apis/camel/v1/zz_generated.deepcopy.go | 1 + .../camel/applyconfiguration/camel/v1/buildspec.go | 21 ++++--- .../camel/clientset/versioned/fake/register.go | 14 ++--- .../camel/clientset/versioned/scheme/register.go | 14 ++--- pkg/controller/build/build_controller.go | 4 +- pkg/controller/build/build_monitor_test.go | 4 +- pkg/controller/build/build_pod.go | 38 +++++++++++++ pkg/controller/integrationkit/build.go | 11 ++-- pkg/resources/resources.go | 8 +-- pkg/trait/builder.go | 13 +++++ pkg/trait/container.go | 65 +++++++++------------- pkg/trait/quarkus.go | 5 +- pkg/util/kubernetes/factory.go | 13 +++++ pkg/util/kubernetes/factory_test.go | 16 ++++++ resources/traits.yaml | 16 ++++++ 34 files changed, 520 insertions(+), 137 deletions(-) diff --git a/addons/strimzi/duck/client/internalclientset/fake/register.go b/addons/strimzi/duck/client/internalclientset/fake/register.go index 53a4309e7..e6ac15499 100644 --- a/addons/strimzi/duck/client/internalclientset/fake/register.go +++ b/addons/strimzi/duck/client/internalclientset/fake/register.go @@ -38,14 +38,14 @@ var localSchemeBuilder = runtime.SchemeBuilder{ // AddToScheme adds all types of this clientset into the given scheme. This allows composition // of clientsets, like in: // -// import ( -// "k8s.io/client-go/kubernetes" -// clientsetscheme "k8s.io/client-go/kubernetes/scheme" -// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" -// ) +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) // -// kclientset, _ := kubernetes.NewForConfig(c) -// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// kclientset, _ := kubernetes.NewForConfig(c) +// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) // // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types // correctly. diff --git a/addons/strimzi/duck/client/internalclientset/scheme/register.go b/addons/strimzi/duck/client/internalclientset/scheme/register.go index 11f233b92..6abeca247 100644 --- a/addons/strimzi/duck/client/internalclientset/scheme/register.go +++ b/addons/strimzi/duck/client/internalclientset/scheme/register.go @@ -38,14 +38,14 @@ var localSchemeBuilder = runtime.SchemeBuilder{ // AddToScheme adds all types of this clientset into the given scheme. This allows composition // of clientsets, like in: // -// import ( -// "k8s.io/client-go/kubernetes" -// clientsetscheme "k8s.io/client-go/kubernetes/scheme" -// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" -// ) +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) // -// kclientset, _ := kubernetes.NewForConfig(c) -// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// kclientset, _ := kubernetes.NewForConfig(c) +// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) // // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types // correctly. diff --git a/config/crd/bases/camel.apache.org_builds.yaml b/config/crd/bases/camel.apache.org_builds.yaml index 58c050154..70e54e1dd 100644 --- a/config/crd/bases/camel.apache.org_builds.yaml +++ b/config/crd/bases/camel.apache.org_builds.yaml @@ -79,6 +79,33 @@ spec: spec: description: BuildSpec defines the Build operation to be executed properties: + configuration: + description: The configuration that should be used to perform the + Build. + properties: + limitCPU: + description: The maximum amount of CPU required. Only used for + `pod` strategy + type: string + limitMemory: + description: The maximum amount of memory required. Only used + for `pod` strategy + type: string + requestCPU: + description: The minimum amount of CPU required. Only used for + `pod` strategy + type: string + requestMemory: + description: The minimum amount of memory required. Only used + for `pod` strategy + type: string + strategy: + description: the strategy to adopt + enum: + - routine + - pod + type: string + type: object maxRunningBuilds: description: the maximum amount of parallel running builds started by this operator instance @@ -88,12 +115,6 @@ spec: description: The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation). type: string - strategy: - description: The strategy that should be used to perform the Build. - enum: - - routine - - pod - type: string tasks: description: The sequence of Build tasks to be performed as part of the Build execution. diff --git a/config/crd/bases/camel.apache.org_integrationkits.yaml b/config/crd/bases/camel.apache.org_integrationkits.yaml index eec22bb01..530927802 100644 --- a/config/crd/bases/camel.apache.org_integrationkits.yaml +++ b/config/crd/bases/camel.apache.org_integrationkits.yaml @@ -203,12 +203,28 @@ spec: description: Can be used to enable or disable a trait. All traits share this common property. type: boolean + limitCPU: + description: When using `pod` strategy, the maximum amount + of CPU required by the pod builder. + type: string + limitMemory: + description: When using `pod` strategy, the maximum amount + of memory required by the pod builder. + type: string properties: description: A list of properties to be provided to the build task items: type: string type: array + requestCPU: + description: When using `pod` strategy, the minimum amount + of CPU required by the pod builder. + type: string + requestMemory: + description: When using `pod` strategy, the minimum amount + of memory required by the pod builder. + type: string strategy: description: The strategy to use, either `pod` or `routine` (default routine) diff --git a/config/crd/bases/camel.apache.org_integrationplatforms.yaml b/config/crd/bases/camel.apache.org_integrationplatforms.yaml index 44c7d72c2..09ca16fef 100644 --- a/config/crd/bases/camel.apache.org_integrationplatforms.yaml +++ b/config/crd/bases/camel.apache.org_integrationplatforms.yaml @@ -105,16 +105,20 @@ spec: container image properties: limitCPU: - description: The maximum amount of CPU required. + description: The maximum amount of CPU required. Only used + for `pod` strategy type: string limitMemory: - description: The maximum amount of memory required. + description: The maximum amount of memory required. Only used + for `pod` strategy type: string requestCPU: - description: The minimum amount of CPU required. + description: The minimum amount of CPU required. Only used + for `pod` strategy type: string requestMemory: - description: The minimum amount of memory required. + description: The minimum amount of memory required. Only used + for `pod` strategy type: string strategy: description: the strategy to adopt @@ -442,12 +446,28 @@ spec: description: Can be used to enable or disable a trait. All traits share this common property. type: boolean + limitCPU: + description: When using `pod` strategy, the maximum amount + of CPU required by the pod builder. + type: string + limitMemory: + description: When using `pod` strategy, the maximum amount + of memory required by the pod builder. + type: string properties: description: A list of properties to be provided to the build task items: type: string type: array + requestCPU: + description: When using `pod` strategy, the minimum amount + of CPU required by the pod builder. + type: string + requestMemory: + description: When using `pod` strategy, the minimum amount + of memory required by the pod builder. + type: string strategy: description: The strategy to use, either `pod` or `routine` (default routine) @@ -1708,16 +1728,20 @@ spec: container image properties: limitCPU: - description: The maximum amount of CPU required. + description: The maximum amount of CPU required. Only used + for `pod` strategy type: string limitMemory: - description: The maximum amount of memory required. + description: The maximum amount of memory required. Only used + for `pod` strategy type: string requestCPU: - description: The minimum amount of CPU required. + description: The minimum amount of CPU required. Only used + for `pod` strategy type: string requestMemory: - description: The minimum amount of memory required. + description: The minimum amount of memory required. Only used + for `pod` strategy type: string strategy: description: the strategy to adopt @@ -2093,12 +2117,28 @@ spec: description: Can be used to enable or disable a trait. All traits share this common property. type: boolean + limitCPU: + description: When using `pod` strategy, the maximum amount + of CPU required by the pod builder. + type: string + limitMemory: + description: When using `pod` strategy, the maximum amount + of memory required by the pod builder. + type: string properties: description: A list of properties to be provided to the build task items: type: string type: array + requestCPU: + description: When using `pod` strategy, the minimum amount + of CPU required by the pod builder. + type: string + requestMemory: + description: When using `pod` strategy, the minimum amount + of memory required by the pod builder. + type: string strategy: description: The strategy to use, either `pod` or `routine` (default routine) diff --git a/config/crd/bases/camel.apache.org_integrations.yaml b/config/crd/bases/camel.apache.org_integrations.yaml index 693220cb5..b29aac0b2 100644 --- a/config/crd/bases/camel.apache.org_integrations.yaml +++ b/config/crd/bases/camel.apache.org_integrations.yaml @@ -6186,12 +6186,28 @@ spec: description: Can be used to enable or disable a trait. All traits share this common property. type: boolean + limitCPU: + description: When using `pod` strategy, the maximum amount + of CPU required by the pod builder. + type: string + limitMemory: + description: When using `pod` strategy, the maximum amount + of memory required by the pod builder. + type: string properties: description: A list of properties to be provided to the build task items: type: string type: array + requestCPU: + description: When using `pod` strategy, the minimum amount + of CPU required by the pod builder. + type: string + requestMemory: + description: When using `pod` strategy, the minimum amount + of memory required by the pod builder. + type: string strategy: description: The strategy to use, either `pod` or `routine` (default routine) diff --git a/config/crd/bases/camel.apache.org_kameletbindings.yaml b/config/crd/bases/camel.apache.org_kameletbindings.yaml index 68234f1a3..5707985ca 100644 --- a/config/crd/bases/camel.apache.org_kameletbindings.yaml +++ b/config/crd/bases/camel.apache.org_kameletbindings.yaml @@ -6461,12 +6461,28 @@ spec: description: Can be used to enable or disable a trait. All traits share this common property. type: boolean + limitCPU: + description: When using `pod` strategy, the maximum amount + of CPU required by the pod builder. + type: string + limitMemory: + description: When using `pod` strategy, the maximum amount + of memory required by the pod builder. + type: string properties: description: A list of properties to be provided to the build task items: type: string type: array + requestCPU: + description: When using `pod` strategy, the minimum amount + of CPU required by the pod builder. + type: string + requestMemory: + description: When using `pod` strategy, the minimum amount + of memory required by the pod builder. + type: string strategy: description: The strategy to use, either `pod` or `routine` (default routine) diff --git a/config/crd/bases/camel.apache.org_pipes.yaml b/config/crd/bases/camel.apache.org_pipes.yaml index 103ac83fc..c1f04c4e2 100644 --- a/config/crd/bases/camel.apache.org_pipes.yaml +++ b/config/crd/bases/camel.apache.org_pipes.yaml @@ -6458,12 +6458,28 @@ spec: description: Can be used to enable or disable a trait. All traits share this common property. type: boolean + limitCPU: + description: When using `pod` strategy, the maximum amount + of CPU required by the pod builder. + type: string + limitMemory: + description: When using `pod` strategy, the maximum amount + of memory required by the pod builder. + type: string properties: description: A list of properties to be provided to the build task items: type: string type: array + requestCPU: + description: When using `pod` strategy, the minimum amount + of CPU required by the pod builder. + type: string + requestMemory: + description: When using `pod` strategy, the minimum amount + of memory required by the pod builder. + type: string strategy: description: The strategy to use, either `pod` or `routine` (default routine) diff --git a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc index 8c72fa7ed..4c8e52315 100644 --- a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc +++ b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc @@ -500,6 +500,7 @@ BuildConditionType -- *Appears on:* +* <<#_camel_apache_org_v1_BuildSpec, BuildSpec>> * <<#_camel_apache_org_v1_IntegrationPlatformBuildSpec, IntegrationPlatformBuildSpec>> BuildConfiguration represent the configuration required to build the runtime @@ -521,28 +522,28 @@ string | -The minimum amount of CPU required. +The minimum amount of CPU required. Only used for `pod` strategy |`requestMemory` + string | -The minimum amount of memory required. +The minimum amount of memory required. Only used for `pod` strategy |`limitCPU` + string | -The maximum amount of CPU required. +The maximum amount of CPU required. Only used for `pod` strategy |`limitMemory` + string | -The maximum amount of memory required. +The maximum amount of memory required. Only used for `pod` strategy |=== @@ -578,12 +579,12 @@ BuildSpec defines the Build operation to be executed The sequence of Build tasks to be performed as part of the Build execution. -|`strategy` + -*xref:#_camel_apache_org_v1_BuildStrategy[BuildStrategy]* +|`configuration` + +*xref:#_camel_apache_org_v1_BuildConfiguration[BuildConfiguration]* | -The strategy that should be used to perform the Build. +The configuration that should be used to perform the Build. |`toolImage` + string @@ -721,7 +722,6 @@ https://github.com/OAI/OpenAPI-Specification/issues/845 *Appears on:* * <<#_camel_apache_org_v1_BuildConfiguration, BuildConfiguration>> -* <<#_camel_apache_org_v1_BuildSpec, BuildSpec>> BuildStrategy specifies how the Build should be executed. It will trigger a Maven process (either as an Operator routine or Kubernetes Pod execution) that @@ -5317,6 +5317,34 @@ string The strategy to use, either `pod` or `routine` (default routine) +|`requestCPU` + +string +| + + +When using `pod` strategy, the minimum amount of CPU required by the pod builder. + +|`requestMemory` + +string +| + + +When using `pod` strategy, the minimum amount of memory required by the pod builder. + +|`limitCPU` + +string +| + + +When using `pod` strategy, the maximum amount of CPU required by the pod builder. + +|`limitMemory` + +string +| + + +When using `pod` strategy, the maximum amount of memory required by the pod builder. + |=== diff --git a/docs/modules/traits/pages/builder.adoc b/docs/modules/traits/pages/builder.adoc index 6bf2975cf..49aa11fe5 100755 --- a/docs/modules/traits/pages/builder.adoc +++ b/docs/modules/traits/pages/builder.adoc @@ -40,6 +40,22 @@ The following configuration options are available: | string | The strategy to use, either `pod` or `routine` (default routine) +| builder.request-cpu +| string +| When using `pod` strategy, the minimum amount of CPU required by the pod builder. + +| builder.request-memory +| string +| When using `pod` strategy, the minimum amount of memory required by the pod builder. + +| builder.limit-cpu +| string +| When using `pod` strategy, the maximum amount of CPU required by the pod builder. + +| builder.limit-memory +| string +| When using `pod` strategy, the maximum amount of memory required by the pod builder. + |=== // End of autogenerated code - DO NOT EDIT! (configuration) diff --git a/helm/camel-k/crds/crd-build.yaml b/helm/camel-k/crds/crd-build.yaml index 58c050154..70e54e1dd 100644 --- a/helm/camel-k/crds/crd-build.yaml +++ b/helm/camel-k/crds/crd-build.yaml @@ -79,6 +79,33 @@ spec: spec: description: BuildSpec defines the Build operation to be executed properties: + configuration: + description: The configuration that should be used to perform the + Build. + properties: + limitCPU: + description: The maximum amount of CPU required. Only used for + `pod` strategy + type: string + limitMemory: + description: The maximum amount of memory required. Only used + for `pod` strategy + type: string + requestCPU: + description: The minimum amount of CPU required. Only used for + `pod` strategy + type: string + requestMemory: + description: The minimum amount of memory required. Only used + for `pod` strategy + type: string + strategy: + description: the strategy to adopt + enum: + - routine + - pod + type: string + type: object maxRunningBuilds: description: the maximum amount of parallel running builds started by this operator instance @@ -88,12 +115,6 @@ spec: description: The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation). type: string - strategy: - description: The strategy that should be used to perform the Build. - enum: - - routine - - pod - type: string tasks: description: The sequence of Build tasks to be performed as part of the Build execution. diff --git a/helm/camel-k/crds/crd-integration-kit.yaml b/helm/camel-k/crds/crd-integration-kit.yaml index eec22bb01..530927802 100644 --- a/helm/camel-k/crds/crd-integration-kit.yaml +++ b/helm/camel-k/crds/crd-integration-kit.yaml @@ -203,12 +203,28 @@ spec: description: Can be used to enable or disable a trait. All traits share this common property. type: boolean + limitCPU: + description: When using `pod` strategy, the maximum amount + of CPU required by the pod builder. + type: string + limitMemory: + description: When using `pod` strategy, the maximum amount + of memory required by the pod builder. + type: string properties: description: A list of properties to be provided to the build task items: type: string type: array + requestCPU: + description: When using `pod` strategy, the minimum amount + of CPU required by the pod builder. + type: string + requestMemory: + description: When using `pod` strategy, the minimum amount + of memory required by the pod builder. + type: string strategy: description: The strategy to use, either `pod` or `routine` (default routine) diff --git a/helm/camel-k/crds/crd-integration-platform.yaml b/helm/camel-k/crds/crd-integration-platform.yaml index 44c7d72c2..09ca16fef 100644 --- a/helm/camel-k/crds/crd-integration-platform.yaml +++ b/helm/camel-k/crds/crd-integration-platform.yaml @@ -105,16 +105,20 @@ spec: container image properties: limitCPU: - description: The maximum amount of CPU required. + description: The maximum amount of CPU required. Only used + for `pod` strategy type: string limitMemory: - description: The maximum amount of memory required. + description: The maximum amount of memory required. Only used + for `pod` strategy type: string requestCPU: - description: The minimum amount of CPU required. + description: The minimum amount of CPU required. Only used + for `pod` strategy type: string requestMemory: - description: The minimum amount of memory required. + description: The minimum amount of memory required. Only used + for `pod` strategy type: string strategy: description: the strategy to adopt @@ -442,12 +446,28 @@ spec: description: Can be used to enable or disable a trait. All traits share this common property. type: boolean + limitCPU: + description: When using `pod` strategy, the maximum amount + of CPU required by the pod builder. + type: string + limitMemory: + description: When using `pod` strategy, the maximum amount + of memory required by the pod builder. + type: string properties: description: A list of properties to be provided to the build task items: type: string type: array + requestCPU: + description: When using `pod` strategy, the minimum amount + of CPU required by the pod builder. + type: string + requestMemory: + description: When using `pod` strategy, the minimum amount + of memory required by the pod builder. + type: string strategy: description: The strategy to use, either `pod` or `routine` (default routine) @@ -1708,16 +1728,20 @@ spec: container image properties: limitCPU: - description: The maximum amount of CPU required. + description: The maximum amount of CPU required. Only used + for `pod` strategy type: string limitMemory: - description: The maximum amount of memory required. + description: The maximum amount of memory required. Only used + for `pod` strategy type: string requestCPU: - description: The minimum amount of CPU required. + description: The minimum amount of CPU required. Only used + for `pod` strategy type: string requestMemory: - description: The minimum amount of memory required. + description: The minimum amount of memory required. Only used + for `pod` strategy type: string strategy: description: the strategy to adopt @@ -2093,12 +2117,28 @@ spec: description: Can be used to enable or disable a trait. All traits share this common property. type: boolean + limitCPU: + description: When using `pod` strategy, the maximum amount + of CPU required by the pod builder. + type: string + limitMemory: + description: When using `pod` strategy, the maximum amount + of memory required by the pod builder. + type: string properties: description: A list of properties to be provided to the build task items: type: string type: array + requestCPU: + description: When using `pod` strategy, the minimum amount + of CPU required by the pod builder. + type: string + requestMemory: + description: When using `pod` strategy, the minimum amount + of memory required by the pod builder. + type: string strategy: description: The strategy to use, either `pod` or `routine` (default routine) diff --git a/helm/camel-k/crds/crd-integration.yaml b/helm/camel-k/crds/crd-integration.yaml index 693220cb5..b29aac0b2 100644 --- a/helm/camel-k/crds/crd-integration.yaml +++ b/helm/camel-k/crds/crd-integration.yaml @@ -6186,12 +6186,28 @@ spec: description: Can be used to enable or disable a trait. All traits share this common property. type: boolean + limitCPU: + description: When using `pod` strategy, the maximum amount + of CPU required by the pod builder. + type: string + limitMemory: + description: When using `pod` strategy, the maximum amount + of memory required by the pod builder. + type: string properties: description: A list of properties to be provided to the build task items: type: string type: array + requestCPU: + description: When using `pod` strategy, the minimum amount + of CPU required by the pod builder. + type: string + requestMemory: + description: When using `pod` strategy, the minimum amount + of memory required by the pod builder. + type: string strategy: description: The strategy to use, either `pod` or `routine` (default routine) diff --git a/helm/camel-k/crds/crd-kamelet-binding.yaml b/helm/camel-k/crds/crd-kamelet-binding.yaml index 68234f1a3..5707985ca 100644 --- a/helm/camel-k/crds/crd-kamelet-binding.yaml +++ b/helm/camel-k/crds/crd-kamelet-binding.yaml @@ -6461,12 +6461,28 @@ spec: description: Can be used to enable or disable a trait. All traits share this common property. type: boolean + limitCPU: + description: When using `pod` strategy, the maximum amount + of CPU required by the pod builder. + type: string + limitMemory: + description: When using `pod` strategy, the maximum amount + of memory required by the pod builder. + type: string properties: description: A list of properties to be provided to the build task items: type: string type: array + requestCPU: + description: When using `pod` strategy, the minimum amount + of CPU required by the pod builder. + type: string + requestMemory: + description: When using `pod` strategy, the minimum amount + of memory required by the pod builder. + type: string strategy: description: The strategy to use, either `pod` or `routine` (default routine) diff --git a/helm/camel-k/crds/crd-pipe.yaml b/helm/camel-k/crds/crd-pipe.yaml index 103ac83fc..c1f04c4e2 100644 --- a/helm/camel-k/crds/crd-pipe.yaml +++ b/helm/camel-k/crds/crd-pipe.yaml @@ -6458,12 +6458,28 @@ spec: description: Can be used to enable or disable a trait. All traits share this common property. type: boolean + limitCPU: + description: When using `pod` strategy, the maximum amount + of CPU required by the pod builder. + type: string + limitMemory: + description: When using `pod` strategy, the maximum amount + of memory required by the pod builder. + type: string properties: description: A list of properties to be provided to the build task items: type: string type: array + requestCPU: + description: When using `pod` strategy, the minimum amount + of CPU required by the pod builder. + type: string + requestMemory: + description: When using `pod` strategy, the minimum amount + of memory required by the pod builder. + type: string strategy: description: The strategy to use, either `pod` or `routine` (default routine) diff --git a/pkg/apis/camel/v1/build_types.go b/pkg/apis/camel/v1/build_types.go index 2618c4d64..4e84cd899 100644 --- a/pkg/apis/camel/v1/build_types.go +++ b/pkg/apis/camel/v1/build_types.go @@ -29,8 +29,8 @@ import ( type BuildSpec struct { // The sequence of Build tasks to be performed as part of the Build execution. Tasks []Task `json:"tasks,omitempty"` - // The strategy that should be used to perform the Build. - Strategy BuildStrategy `json:"strategy,omitempty"` + // The configuration that should be used to perform the Build. + Configuration BuildConfiguration `json:"configuration,omitempty"` // The container image to be used to run the build. ToolImage string `json:"toolImage,omitempty"` // The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation). diff --git a/pkg/apis/camel/v1/common_types.go b/pkg/apis/camel/v1/common_types.go index 9a3b90781..d7ef30ad0 100644 --- a/pkg/apis/camel/v1/common_types.go +++ b/pkg/apis/camel/v1/common_types.go @@ -39,13 +39,13 @@ const ( type BuildConfiguration struct { // the strategy to adopt Strategy BuildStrategy `property:"strategy" json:"strategy,omitempty"` - // The minimum amount of CPU required. + // The minimum amount of CPU required. Only used for `pod` strategy RequestCPU string `property:"request-cpu" json:"requestCPU,omitempty"` - // The minimum amount of memory required. + // The minimum amount of memory required. Only used for `pod` strategy RequestMemory string `property:"request-memory" json:"requestMemory,omitempty"` - // The maximum amount of CPU required. + // The maximum amount of CPU required. Only used for `pod` strategy LimitCPU string `property:"limit-cpu" json:"limitCPU,omitempty"` - // The maximum amount of memory required. + // The maximum amount of memory required. Only used for `pod` strategy LimitMemory string `property:"limit-memory" json:"limitMemory,omitempty"` } diff --git a/pkg/apis/camel/v1/trait/builder.go b/pkg/apis/camel/v1/trait/builder.go index f8e2b8a41..4f62bc0b9 100644 --- a/pkg/apis/camel/v1/trait/builder.go +++ b/pkg/apis/camel/v1/trait/builder.go @@ -29,4 +29,12 @@ type BuilderTrait struct { Properties []string `property:"properties" json:"properties,omitempty"` // The strategy to use, either `pod` or `routine` (default routine) Strategy string `property:"strategy" json:"strategy,omitempty"` + // When using `pod` strategy, the minimum amount of CPU required by the pod builder. + RequestCPU string `property:"request-cpu" json:"requestCPU,omitempty"` + // When using `pod` strategy, the minimum amount of memory required by the pod builder. + RequestMemory string `property:"request-memory" json:"requestMemory,omitempty"` + // When using `pod` strategy, the maximum amount of CPU required by the pod builder. + LimitCPU string `property:"limit-cpu" json:"limitCPU,omitempty"` + // When using `pod` strategy, the maximum amount of memory required by the pod builder. + LimitMemory string `property:"limit-memory" json:"limitMemory,omitempty"` } diff --git a/pkg/apis/camel/v1/zz_generated.deepcopy.go b/pkg/apis/camel/v1/zz_generated.deepcopy.go index efd780e1a..b34d8ed9d 100644 --- a/pkg/apis/camel/v1/zz_generated.deepcopy.go +++ b/pkg/apis/camel/v1/zz_generated.deepcopy.go @@ -184,6 +184,7 @@ func (in *BuildSpec) DeepCopyInto(out *BuildSpec) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + out.Configuration = in.Configuration out.Timeout = in.Timeout } diff --git a/pkg/client/camel/applyconfiguration/camel/v1/buildspec.go b/pkg/client/camel/applyconfiguration/camel/v1/buildspec.go index 6ebf7927c..83a691a8a 100644 --- a/pkg/client/camel/applyconfiguration/camel/v1/buildspec.go +++ b/pkg/client/camel/applyconfiguration/camel/v1/buildspec.go @@ -20,19 +20,18 @@ limitations under the License. package v1 import ( - camelv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) // BuildSpecApplyConfiguration represents an declarative configuration of the BuildSpec type for use // with apply. type BuildSpecApplyConfiguration struct { - Tasks []TaskApplyConfiguration `json:"tasks,omitempty"` - Strategy *camelv1.BuildStrategy `json:"strategy,omitempty"` - ToolImage *string `json:"toolImage,omitempty"` - BuilderPodNamespace *string `json:"operatorNamespace,omitempty"` - Timeout *metav1.Duration `json:"timeout,omitempty"` - MaxRunningBuilds *int32 `json:"maxRunningBuilds,omitempty"` + Tasks []TaskApplyConfiguration `json:"tasks,omitempty"` + Configuration *BuildConfigurationApplyConfiguration `json:"configuration,omitempty"` + ToolImage *string `json:"toolImage,omitempty"` + BuilderPodNamespace *string `json:"operatorNamespace,omitempty"` + Timeout *metav1.Duration `json:"timeout,omitempty"` + MaxRunningBuilds *int32 `json:"maxRunningBuilds,omitempty"` } // BuildSpecApplyConfiguration constructs an declarative configuration of the BuildSpec type for use with @@ -54,11 +53,11 @@ func (b *BuildSpecApplyConfiguration) WithTasks(values ...*TaskApplyConfiguratio return b } -// WithStrategy sets the Strategy field in the declarative configuration to the given value +// WithConfiguration sets the Configuration 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 Strategy field is set to the value of the last call. -func (b *BuildSpecApplyConfiguration) WithStrategy(value camelv1.BuildStrategy) *BuildSpecApplyConfiguration { - b.Strategy = &value +// If called multiple times, the Configuration field is set to the value of the last call. +func (b *BuildSpecApplyConfiguration) WithConfiguration(value *BuildConfigurationApplyConfiguration) *BuildSpecApplyConfiguration { + b.Configuration = value return b } diff --git a/pkg/client/camel/clientset/versioned/fake/register.go b/pkg/client/camel/clientset/versioned/fake/register.go index 249a2b9e3..d55e6d595 100644 --- a/pkg/client/camel/clientset/versioned/fake/register.go +++ b/pkg/client/camel/clientset/versioned/fake/register.go @@ -40,14 +40,14 @@ var localSchemeBuilder = runtime.SchemeBuilder{ // AddToScheme adds all types of this clientset into the given scheme. This allows composition // of clientsets, like in: // -// import ( -// "k8s.io/client-go/kubernetes" -// clientsetscheme "k8s.io/client-go/kubernetes/scheme" -// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" -// ) +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) // -// kclientset, _ := kubernetes.NewForConfig(c) -// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// kclientset, _ := kubernetes.NewForConfig(c) +// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) // // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types // correctly. diff --git a/pkg/client/camel/clientset/versioned/scheme/register.go b/pkg/client/camel/clientset/versioned/scheme/register.go index 9366fb20c..493d56e4c 100644 --- a/pkg/client/camel/clientset/versioned/scheme/register.go +++ b/pkg/client/camel/clientset/versioned/scheme/register.go @@ -40,14 +40,14 @@ var localSchemeBuilder = runtime.SchemeBuilder{ // AddToScheme adds all types of this clientset into the given scheme. This allows composition // of clientsets, like in: // -// import ( -// "k8s.io/client-go/kubernetes" -// clientsetscheme "k8s.io/client-go/kubernetes/scheme" -// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" -// ) +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) // -// kclientset, _ := kubernetes.NewForConfig(c) -// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// kclientset, _ := kubernetes.NewForConfig(c) +// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) // // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types // correctly. diff --git a/pkg/controller/build/build_controller.go b/pkg/controller/build/build_controller.go index 1c08e8a95..13c8e1008 100644 --- a/pkg/controller/build/build_controller.go +++ b/pkg/controller/build/build_controller.go @@ -146,7 +146,7 @@ func (r *reconcileBuild) Reconcile(ctx context.Context, request reconcile.Reques maxRunningBuilds: instance.Spec.MaxRunningBuilds, } - switch instance.Spec.Strategy { + switch instance.Spec.Configuration.Strategy { case v1.BuildStrategyPod: actions = []Action{ newInitializePodAction(r.reader), @@ -209,7 +209,7 @@ func (r *reconcileBuild) Reconcile(ctx context.Context, request reconcile.Reques return reconcile.Result{RequeueAfter: 5 * time.Second}, nil } - if target.Spec.Strategy == v1.BuildStrategyPod && + if target.Spec.Configuration.Strategy == v1.BuildStrategyPod && (target.Status.Phase == v1.BuildPhasePending || target.Status.Phase == v1.BuildPhaseRunning) { // Requeue running Build to poll Pod and signal timeout return reconcile.Result{RequeueAfter: 1 * time.Second}, nil diff --git a/pkg/controller/build/build_monitor_test.go b/pkg/controller/build/build_monitor_test.go index aace7b647..51381b46d 100644 --- a/pkg/controller/build/build_monitor_test.go +++ b/pkg/controller/build/build_monitor_test.go @@ -228,7 +228,9 @@ func newBuildWithLayoutInPhase(namespace string, name string, layout string, pha }, }, Spec: v1.BuildSpec{ - Strategy: v1.BuildStrategyRoutine, + Configuration: v1.BuildConfiguration{ + Strategy: v1.BuildStrategyRoutine, + }, ToolImage: "camel:latest", BuilderPodNamespace: "ns", Tasks: []v1.Task{}, diff --git a/pkg/controller/build/build_pod.go b/pkg/controller/build/build_pod.go index fe51dcde8..da25ab3f0 100644 --- a/pkg/controller/build/build_pod.go +++ b/pkg/controller/build/build_pod.go @@ -165,9 +165,47 @@ func newBuildPod(ctx context.Context, c ctrl.Reader, build *v1.Build) (*corev1.P pod.Spec.Containers = pod.Spec.InitContainers[len(pod.Spec.InitContainers)-1 : len(pod.Spec.InitContainers)] pod.Spec.InitContainers = pod.Spec.InitContainers[:len(pod.Spec.InitContainers)-1] + if err := configureResources(build.Spec.Configuration, &pod.Spec.Containers[0]); err != nil { + return pod, err + } + return pod, nil } +func configureResources(conf v1.BuildConfiguration, container *corev1.Container) error { + requestsList := container.Resources.Requests + limitsList := container.Resources.Limits + var err error + if requestsList == nil { + requestsList = make(corev1.ResourceList) + } + if limitsList == nil { + limitsList = make(corev1.ResourceList) + } + + requestsList, err = kubernetes.ConfigureResource(conf.RequestCPU, requestsList, corev1.ResourceCPU) + if err != nil { + return err + } + requestsList, err = kubernetes.ConfigureResource(conf.RequestMemory, requestsList, corev1.ResourceMemory) + if err != nil { + return err + } + limitsList, err = kubernetes.ConfigureResource(conf.LimitCPU, limitsList, corev1.ResourceCPU) + if err != nil { + return err + } + limitsList, err = kubernetes.ConfigureResource(conf.LimitMemory, limitsList, corev1.ResourceMemory) + if err != nil { + return err + } + + container.Resources.Requests = requestsList + container.Resources.Limits = limitsList + + return nil +} + func deleteBuilderPod(ctx context.Context, c ctrl.Writer, build *v1.Build) error { pod := corev1.Pod{ TypeMeta: metav1.TypeMeta{ diff --git a/pkg/controller/integrationkit/build.go b/pkg/controller/integrationkit/build.go index 84cb3331d..d7dcea5dd 100644 --- a/pkg/controller/integrationkit/build.go +++ b/pkg/controller/integrationkit/build.go @@ -109,13 +109,10 @@ func (action *buildAction) handleBuildSubmitted(ctx context.Context, kit *v1.Int // It has to be the same namespace as the operator as they must share a PVC builderPodNamespace := platform.GetOperatorNamespace() - buildStrategy := env.Platform.Status.Build.BuildConfiguration.Strategy - if env.BuildConfiguration.Strategy != "" { - buildStrategy = env.BuildConfiguration.Strategy - } + buildConfig := env.Platform.Status.Build.BuildConfiguration // nolint: contextcheck - if buildStrategy == v1.BuildStrategyPod { + if buildConfig.Strategy == v1.BuildStrategyPod { // Pod strategy requires a PVC to exist. If it does not exist, we warn the user and fallback to Routine build strategy if pvc, err := kubernetes.LookupPersistentVolumeClaim(env.Ctx, env.Client, builderPodNamespace, defaults.DefaultPVC); pvc != nil || err != nil { err = platform.CreateBuilderServiceAccount(env.Ctx, env.Client, env.Platform) @@ -124,7 +121,7 @@ func (action *buildAction) handleBuildSubmitted(ctx context.Context, kit *v1.Int } } else { // Fallback to Routine strategy - buildStrategy = v1.BuildStrategyRoutine + buildConfig.Strategy = v1.BuildStrategyRoutine Log.Info(`Warning: the operator was installed with an ephemeral storage, builder "pod" strategy is not supported: using "routine" build strategy as a fallback. We recommend to configure a PersistentVolumeClaim in order to be able to use "pod" builder strategy. Please consider that certain features such as Quarkus native require a "pod" builder strategy (hence a PVC) to work properly.`) } } @@ -141,7 +138,7 @@ func (action *buildAction) handleBuildSubmitted(ctx context.Context, kit *v1.Int Annotations: annotations, }, Spec: v1.BuildSpec{ - Strategy: buildStrategy, + Configuration: buildConfig, ToolImage: env.CamelCatalog.Image, BuilderPodNamespace: builderPodNamespace, Tasks: env.BuildTasks, diff --git a/pkg/resources/resources.go b/pkg/resources/resources.go index 85e05d227..3b570ce21 100644 --- a/pkg/resources/resources.go +++ b/pkg/resources/resources.go @@ -138,9 +138,9 @@ var assets = func() http.FileSystem { "/crd/bases/camel.apache.org_integrationplatforms.yaml": &vfsgen۰CompressedFileInfo{ name: "camel.apache.org_integrationplatforms.yaml", modTime: time.Time{}, - uncompressedSize: 176747, + uncompressedSize: 178291, - compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xbd\x7d\x73\xdb\x36\xb6\x30\xfe\x7f\x3f\x05\xc6\x9d\x3b\x71\x32\x96\x9c\xee\xde\xee\xf6\xfa\x4e\xe7\x79\x5c\x27\x6d\xdd\xbc\xd8\xd7\x76\xb2\xbb\xd3\x76\x2a\x88\x3c\x92\x50\x83\x00\x2f\x00\xca\x56\x7f\xfb\xfb\xee\xcf\xe0\x00\x20\x29\x89\x04\x29\xc9\x71\xd2\x56\xec\xcc\x6e\x6c\x13\x87\x07\xc0\xc1\x79\xc3\x79\xf9\x9c\x0c\x1e\xee\xf9\xec\x73\xf2\x9a\x25\x20\x34\xa4\xc4\x48\x62\x66\x40\x4e\x73\x9a\xcc\x80\x5c\xcb\x89\x [...] + compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xbd\x7d\x73\xdb\x36\xb6\x30\xfe\x7f\x3f\x05\xc6\x9d\x3b\x71\x32\x96\x9c\xee\xde\xee\xf6\xfa\x4e\xe7\x79\x5c\x27\x6d\xdd\xbc\xd8\xd7\x76\xb2\xbb\xd3\x76\x2a\x88\x3c\x92\x50\x83\x00\x2f\x00\xca\x56\x7f\xfb\xfb\xee\xcf\xe0\x00\x20\x29\x89\x04\x29\xc9\x4e\xd2\x56\xec\xcc\x6e\x6c\x13\x87\x07\xc0\xc1\x79\xc3\x79\xf9\x9c\x0c\x1e\xee\xf9\xec\x73\xf2\x9a\x25\x20\x34\xa4\xc4\x48\x62\x66\x40\x4e\x73\x9a\xcc\x80\x5c\xcb\x89\x [...] }, "/crd/bases/camel.apache.org_integrations.yaml": &vfsgen۰CompressedFileInfo{ name: "camel.apache.org_integrations.yaml", @@ -512,9 +512,9 @@ var assets = func() http.FileSystem { "/samples/bases/camel_v1_integrationplatform.yaml": &vfsgen۰CompressedFileInfo{ name: "camel_v1_integrationplatform.yaml", modTime: time.Time{}, - uncompressedSize: 1058, + uncompressedSize: 1111, - compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xac\x53\xcd\x6e\xdb\x3c\x10\xbc\xf3\x29\x06\xd6\x25\x01\x1c\xfb\xfb\x7a\x74\x4f\x6a\x62\xa3\x42\x03\xb9\x88\x9c\x06\x39\xae\xa5\xb5\xb4\x08\x45\xaa\x24\x15\xc5\x6f\x5f\x50\x96\x1b\x07\xbd\x86\x37\x81\xcb\xf9\xd9\x19\x25\xb8\xf9\xbc\xa3\x12\xdc\x4b\xc9\xc6\x73\x85\x60\x11\x1a\x46\xda\x51\xd9\x30\x0a\x7b\x08\x03\x39\xc6\xc6\xf6\xa6\xa2\x20\xd6\xe0\x2a\x2d\x36\xd7\xe8\x4d\xc5\x0e\xd6\x30\xac\x43\x6b\x1d\xab\x04\xa5\x35\x [...] + compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xac\x53\x41\x6e\xe3\x38\x10\xbc\xf3\x15\x05\xeb\x92\x00\x8e\xbd\xbb\x47\xef\xc9\xeb\xd8\x58\x61\x02\x7b\x10\x39\x13\xe4\xd8\x16\xdb\x52\x23\x14\xa9\x21\xa9\x28\xfe\xfd\x80\xb2\x3c\x71\x30\xd7\xf0\x24\xa9\x9b\x5d\x55\x5d\xa5\x0c\x77\x5f\x77\x54\x86\x07\x29\xd9\x06\xd6\x88\x0e\xb1\x66\x2c\x5b\x2a\x6b\x46\xe1\x8e\xb1\x27\xcf\xd8\xb8\xce\x6a\x8a\xe2\x2c\x6e\x96\xc5\xe6\x16\x9d\xd5\xec\xe1\x2c\xc3\x79\x34\xce\xb3\xca\x50\x [...] }, "/samples/bases/camel_v1_kamelet.yaml": &vfsgen۰CompressedFileInfo{ name: "camel_v1_kamelet.yaml", diff --git a/pkg/trait/builder.go b/pkg/trait/builder.go index 8082e7658..ba30eb727 100644 --- a/pkg/trait/builder.go +++ b/pkg/trait/builder.go @@ -161,6 +161,19 @@ func (t *builderTrait) Apply(e *Environment) error { } } + if t.RequestCPU != "" { + e.BuildConfiguration.RequestCPU = t.RequestCPU + } + if t.RequestMemory != "" { + e.BuildConfiguration.RequestMemory = t.RequestMemory + } + if t.LimitCPU != "" { + e.BuildConfiguration.LimitCPU = t.LimitCPU + } + if t.LimitMemory != "" { + e.BuildConfiguration.LimitMemory = t.LimitMemory + } + return nil } diff --git a/pkg/trait/container.go b/pkg/trait/container.go index d19c9df7d..141b4f58e 100644 --- a/pkg/trait/container.go +++ b/pkg/trait/container.go @@ -25,7 +25,6 @@ import ( appsv1 "k8s.io/api/apps/v1" batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/utils/pointer" @@ -195,7 +194,7 @@ func (t *containerTrait) configureContainer(e *Environment) error { e.Resources.Add(props) } - t.configureResources(e, &container) + t.configureResources(&container) if pointer.BoolDeref(t.Expose, false) { t.configureService(e, &container) } @@ -303,50 +302,36 @@ func (t *containerTrait) configureService(e *Environment, container *corev1.Cont service.Labels["camel.apache.org/service.type"] = v1.ServiceTypeUser } -func (t *containerTrait) configureResources(_ *Environment, container *corev1.Container) { - // Requests - if container.Resources.Requests == nil { - container.Resources.Requests = make(corev1.ResourceList) +func (t *containerTrait) configureResources(container *corev1.Container) { + requestsList := container.Resources.Requests + limitsList := container.Resources.Limits + var err error + if requestsList == nil { + requestsList = make(corev1.ResourceList) } - - if t.RequestCPU != "" { - v, err := resource.ParseQuantity(t.RequestCPU) - if err != nil { - t.L.Error(err, "unable to parse quantity", "request-cpu", t.RequestCPU) - } else { - container.Resources.Requests[corev1.ResourceCPU] = v - } - } - if t.RequestMemory != "" { - v, err := resource.ParseQuantity(t.RequestMemory) - if err != nil { - t.L.Error(err, "unable to parse quantity", "request-memory", t.RequestMemory) - } else { - container.Resources.Requests[corev1.ResourceMemory] = v - } + if limitsList == nil { + limitsList = make(corev1.ResourceList) } - // Limits - if container.Resources.Limits == nil { - container.Resources.Limits = make(corev1.ResourceList) + requestsList, err = kubernetes.ConfigureResource(t.RequestCPU, requestsList, corev1.ResourceCPU) + if err != nil { + t.L.Error(err, "unable to parse quantity", "request-cpu", t.RequestCPU) } - - if t.LimitCPU != "" { - v, err := resource.ParseQuantity(t.LimitCPU) - if err != nil { - t.L.Error(err, "unable to parse quantity", "limit-cpu", t.LimitCPU) - } else { - container.Resources.Limits[corev1.ResourceCPU] = v - } + requestsList, err = kubernetes.ConfigureResource(t.RequestMemory, requestsList, corev1.ResourceMemory) + if err != nil { + t.L.Error(err, "unable to parse quantity", "request-memory", t.RequestMemory) } - if t.LimitMemory != "" { - v, err := resource.ParseQuantity(t.LimitMemory) - if err != nil { - t.L.Error(err, "unable to parse quantity", "limit-memory", t.LimitMemory) - } else { - container.Resources.Limits[corev1.ResourceMemory] = v - } + limitsList, err = kubernetes.ConfigureResource(t.LimitCPU, limitsList, corev1.ResourceCPU) + if err != nil { + t.L.Error(err, "unable to parse quantity", "limit-cpu", t.LimitCPU) + } + limitsList, err = kubernetes.ConfigureResource(t.LimitMemory, limitsList, corev1.ResourceMemory) + if err != nil { + t.L.Error(err, "unable to parse quantity", "limit-memory", t.LimitMemory) } + + container.Resources.Requests = requestsList + container.Resources.Limits = limitsList } func (t *containerTrait) configureCapabilities(e *Environment) { diff --git a/pkg/trait/quarkus.go b/pkg/trait/quarkus.go index f92a272c8..58b1ca33e 100644 --- a/pkg/trait/quarkus.go +++ b/pkg/trait/quarkus.go @@ -149,9 +149,10 @@ func (t *quarkusTrait) Configure(e *Environment) (bool, error) { func (t *quarkusTrait) Apply(e *Environment) error { if t.hasKitNativeType() { // Force the build to run in a separate Pod - t.L.Info("Quarkus Native requires a build pod strategy") + t.L.Info("This is a Quarkus native build: setting build configuration with build Pod strategy, 1 CPU core and 8 GiB memory. Make sure your cluster can handle it.") e.BuildConfiguration.Strategy = v1.BuildStrategyPod - // TODO we may provide a set of sensible resource default values for the Pod spun off + e.BuildConfiguration.RequestCPU = "1000m" + e.BuildConfiguration.RequestMemory = "8Gi" } if e.IntegrationInPhase(v1.IntegrationPhaseBuildingKit) { diff --git a/pkg/util/kubernetes/factory.go b/pkg/util/kubernetes/factory.go index 389378570..1915c76d9 100644 --- a/pkg/util/kubernetes/factory.go +++ b/pkg/util/kubernetes/factory.go @@ -179,3 +179,16 @@ func NewPersistentVolumeClaim(ns, name, storageClassName, capacityStorage string } return &pvc } + +// ConfigureResource will set a resource on the specified resource list or returns an error. +func ConfigureResource(resourceQty string, list corev1.ResourceList, name corev1.ResourceName) (corev1.ResourceList, error) { + if resourceQty != "" { + v, err := resource.ParseQuantity(resourceQty) + if err != nil { + return list, err + } + list[name] = v + } + + return list, nil +} diff --git a/pkg/util/kubernetes/factory_test.go b/pkg/util/kubernetes/factory_test.go index a92695f86..530c747fa 100644 --- a/pkg/util/kubernetes/factory_test.go +++ b/pkg/util/kubernetes/factory_test.go @@ -22,6 +22,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + corev1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" ) @@ -170,3 +171,18 @@ func TestMissingResourceRequirements(t *testing.T) { _, err := NewResourceRequirements(strings.Split(resReq, ",")) assert.NotNil(t, err) } + +func TestConfigureResources(t *testing.T) { + requestsList := make(corev1.ResourceList) + requestsList, err := ConfigureResource("500m", requestsList, corev1.ResourceCPU) + assert.Nil(t, err) + assert.Equal(t, "500m", requestsList.Cpu().String()) + requestsList, err = ConfigureResource("5Gi", requestsList, corev1.ResourceMemory) + assert.Nil(t, err) + assert.Equal(t, "5Gi", requestsList.Memory().String()) + requestsList, err = ConfigureResource("5ss", requestsList, corev1.ResourceCPU) + assert.NotNil(t, err) + // Assert previous values haven't changed + assert.Equal(t, "500m", requestsList.Cpu().String()) + assert.Equal(t, "5Gi", requestsList.Memory().String()) +} diff --git a/resources/traits.yaml b/resources/traits.yaml index 41c56e172..4c091900d 100755 --- a/resources/traits.yaml +++ b/resources/traits.yaml @@ -212,6 +212,22 @@ traits: - name: strategy type: string description: The strategy to use, either `pod` or `routine` (default routine) + - name: request-cpu + type: string + description: When using `pod` strategy, the minimum amount of CPU required by + the pod builder. + - name: request-memory + type: string + description: When using `pod` strategy, the minimum amount of memory required + by the pod builder. + - name: limit-cpu + type: string + description: When using `pod` strategy, the maximum amount of CPU required by + the pod builder. + - name: limit-memory + type: string + description: When using `pod` strategy, the maximum amount of memory required + by the pod builder. - name: camel platform: true profiles:
