Skip to content

Commit

Permalink
Refactor kaniko settings
Browse files Browse the repository at this point in the history
fix #3005
  • Loading branch information
mmelko committed Feb 25, 2022
1 parent 6606292 commit b889082
Show file tree
Hide file tree
Showing 16 changed files with 171 additions and 66 deletions.
12 changes: 12 additions & 0 deletions config/crd/bases/camel.apache.org_integrationplatforms.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ spec:
description: IntegrationPlatformBuildSpec contains platform related
build information
properties:
PublishStrategyOptions:
additionalProperties:
type: string
type: object
baseImage:
type: string
buildStrategy:
Expand All @@ -77,6 +81,7 @@ spec:
- pod
type: string
kanikoBuildCache:
description: 'Deprecated: Use PublishStrategyOptions instead'
type: boolean
maven:
description: MavenSpec --
Expand Down Expand Up @@ -184,6 +189,7 @@ spec:
type: string
type: object
persistentVolumeClaim:
description: 'Deprecated: Use PublishStrategyOptions instead'
type: string
publishStrategy:
description: IntegrationPlatformBuildPublishStrategy enumerates
Expand Down Expand Up @@ -275,6 +281,10 @@ spec:
description: IntegrationPlatformBuildSpec contains platform related
build information
properties:
PublishStrategyOptions:
additionalProperties:
type: string
type: object
baseImage:
type: string
buildStrategy:
Expand All @@ -284,6 +294,7 @@ spec:
- pod
type: string
kanikoBuildCache:
description: 'Deprecated: Use PublishStrategyOptions instead'
type: boolean
maven:
description: MavenSpec --
Expand Down Expand Up @@ -391,6 +402,7 @@ spec:
type: string
type: object
persistentVolumeClaim:
description: 'Deprecated: Use PublishStrategyOptions instead'
type: string
publishStrategy:
description: IntegrationPlatformBuildPublishStrategy enumerates
Expand Down
36 changes: 11 additions & 25 deletions docs/modules/ROOT/partials/apis/camel-k-crds.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1582,7 +1582,7 @@ string
|
Deprecated: Use PublishStrategyOptions instead
|`maven` +
*xref:#_camel_apache_org_v1_MavenSpec[MavenSpec]*
Expand All @@ -1596,6 +1596,13 @@ bool
|
Deprecated: Use PublishStrategyOptions instead
|`PublishStrategyOptions` +
map[string]string
|
Expand Down Expand Up @@ -1960,9 +1967,9 @@ Deprecated: use the IntegrationKit field
Deprecated:
Use camel trait (camel.properties) to manage properties
Use container trait (container.configs) to manage configs
Use container trait (container.resources) to manage resources
Use container trait (container.volumes) to manage volumes
Use container trait (mount.configs) to manage configs
Use container trait (mount.resources) to manage resources
Use container trait (mount.volumes) to manage volumes
|`repositories` +
[]string
Expand Down Expand Up @@ -2530,7 +2537,6 @@ string
*Appears on:*
* <<#_camel_apache_org_v1_Flow, Flow>>
* <<#_camel_apache_org_v1_Template, Template>>
* <<#_camel_apache_org_v1_TraitConfiguration, TraitConfiguration>>
RawMessage is a raw encoded JSON value.
Expand Down Expand Up @@ -3002,26 +3008,6 @@ Task --
|===
[#_camel_apache_org_v1_Template]
=== Template
Template is an unstructured object representing a Kamelet template in YAML/JSON DSL
[cols="2,2a",options="header"]
|===
|Field
|Description
|`RawMessage` +
*xref:#_camel_apache_org_v1_RawMessage[RawMessage]*
|(Members of `RawMessage` are embedded into this type.)
|===
[#_camel_apache_org_v1_TraitConfiguration]
Expand Down
40 changes: 35 additions & 5 deletions docs/modules/ROOT/partials/apis/kamelets-crds.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ BeanProperties represent an unstructured object properties to be set on a bean
|Description
|`RawMessage` +
*xref:apis/camel-k.adoc#_camel_apache_org_v1_RawMessage[github.com/apache/camel-k/pkg/apis/camel/v1.RawMessage]*
*xref:#_camel_apache_org_v1alpha1_RawMessage[RawMessage]*
|
Expand Down Expand Up @@ -182,7 +182,7 @@ EndpointProperties is a key/value struct represented as JSON raw to allow numeri
|Description
|`RawMessage` +
*xref:apis/camel-k.adoc#_camel_apache_org_v1_RawMessage[github.com/apache/camel-k/pkg/apis/camel/v1.RawMessage]*
*xref:#_camel_apache_org_v1alpha1_RawMessage[RawMessage]*
|(Members of `RawMessage` are embedded into this type.)
Expand Down Expand Up @@ -266,7 +266,7 @@ ErrorHandlerParameters represent an unstructured object for error handler parame
|Description
|`RawMessage` +
*xref:apis/camel-k.adoc#_camel_apache_org_v1_RawMessage[github.com/apache/camel-k/pkg/apis/camel/v1.RawMessage]*
*xref:#_camel_apache_org_v1alpha1_RawMessage[RawMessage]*
|
Expand Down Expand Up @@ -317,7 +317,7 @@ ErrorHandlerSpec represents an unstructured object for an error handler
|Description
|`RawMessage` +
*xref:apis/camel-k.adoc#_camel_apache_org_v1_RawMessage[github.com/apache/camel-k/pkg/apis/camel/v1.RawMessage]*
*xref:#_camel_apache_org_v1alpha1_RawMessage[RawMessage]*
|
Expand Down Expand Up @@ -1043,7 +1043,7 @@ KameletSpec defines the desired state of Kamelet
|`template` +
*xref:apis/camel-k.adoc#_camel_apache_org_v1_Template[github.com/apache/camel-k/pkg/apis/camel/v1.Template]*
*xref:#_camel_apache_org_v1alpha1_Template[Template]*
|
Expand Down Expand Up @@ -1123,8 +1123,38 @@ KameletStatus defines the observed state of Kamelet
*Appears on:*
* <<#_camel_apache_org_v1alpha1_BeanProperties, BeanProperties>>
* <<#_camel_apache_org_v1alpha1_EndpointProperties, EndpointProperties>>
* <<#_camel_apache_org_v1alpha1_ErrorHandlerParameters, ErrorHandlerParameters>>
* <<#_camel_apache_org_v1alpha1_ErrorHandlerSpec, ErrorHandlerSpec>>
* <<#_camel_apache_org_v1alpha1_JSON, JSON>>
* <<#_camel_apache_org_v1alpha1_Template, Template>>
RawMessage is a raw encoded JSON value.
It implements Marshaler and Unmarshaler and can
be used to delay JSON decoding or precompute a JSON encoding.
[#_camel_apache_org_v1alpha1_Template]
=== Template
*Appears on:*
* <<#_camel_apache_org_v1alpha1_KameletSpec, KameletSpec>>
Template is an unstructured object representing a Kamelet template in YAML/JSON DSL
[cols="2,2a",options="header"]
|===
|Field
|Description
|`RawMessage` +
*xref:#_camel_apache_org_v1alpha1_RawMessage[RawMessage]*
|(Members of `RawMessage` are embedded into this type.)
|===
12 changes: 12 additions & 0 deletions helm/camel-k/crds/crd-integration-platform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ spec:
description: IntegrationPlatformBuildSpec contains platform related
build information
properties:
PublishStrategyOptions:
additionalProperties:
type: string
type: object
baseImage:
type: string
buildStrategy:
Expand All @@ -77,6 +81,7 @@ spec:
- pod
type: string
kanikoBuildCache:
description: 'Deprecated: Use PublishStrategyOptions instead'
type: boolean
maven:
description: MavenSpec --
Expand Down Expand Up @@ -184,6 +189,7 @@ spec:
type: string
type: object
persistentVolumeClaim:
description: 'Deprecated: Use PublishStrategyOptions instead'
type: string
publishStrategy:
description: IntegrationPlatformBuildPublishStrategy enumerates
Expand Down Expand Up @@ -275,6 +281,10 @@ spec:
description: IntegrationPlatformBuildSpec contains platform related
build information
properties:
PublishStrategyOptions:
additionalProperties:
type: string
type: object
baseImage:
type: string
buildStrategy:
Expand All @@ -284,6 +294,7 @@ spec:
- pod
type: string
kanikoBuildCache:
description: 'Deprecated: Use PublishStrategyOptions instead'
type: boolean
maven:
description: MavenSpec --
Expand Down Expand Up @@ -391,6 +402,7 @@ spec:
type: string
type: object
persistentVolumeClaim:
description: 'Deprecated: Use PublishStrategyOptions instead'
type: string
publishStrategy:
description: IntegrationPlatformBuildPublishStrategy enumerates
Expand Down
23 changes: 13 additions & 10 deletions pkg/apis/camel/v1/integrationplatform_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,19 @@ var AllTraitProfiles = []TraitProfile{TraitProfileKubernetes, TraitProfileKnativ

// IntegrationPlatformBuildSpec contains platform related build information
type IntegrationPlatformBuildSpec struct {
BuildStrategy BuildStrategy `json:"buildStrategy,omitempty"`
PublishStrategy IntegrationPlatformBuildPublishStrategy `json:"publishStrategy,omitempty"`
RuntimeVersion string `json:"runtimeVersion,omitempty"`
RuntimeProvider RuntimeProvider `json:"runtimeProvider,omitempty"`
BaseImage string `json:"baseImage,omitempty"`
Registry RegistrySpec `json:"registry,omitempty"`
Timeout *metav1.Duration `json:"timeout,omitempty"`
PersistentVolumeClaim string `json:"persistentVolumeClaim,omitempty"`
Maven MavenSpec `json:"maven,omitempty"`
KanikoBuildCache *bool `json:"kanikoBuildCache,omitempty"`
BuildStrategy BuildStrategy `json:"buildStrategy,omitempty"`
PublishStrategy IntegrationPlatformBuildPublishStrategy `json:"publishStrategy,omitempty"`
RuntimeVersion string `json:"runtimeVersion,omitempty"`
RuntimeProvider RuntimeProvider `json:"runtimeProvider,omitempty"`
BaseImage string `json:"baseImage,omitempty"`
Registry RegistrySpec `json:"registry,omitempty"`
Timeout *metav1.Duration `json:"timeout,omitempty"`
// Deprecated: Use PublishStrategyOptions instead
PersistentVolumeClaim string `json:"persistentVolumeClaim,omitempty"`
Maven MavenSpec `json:"maven,omitempty"`
// Deprecated: Use PublishStrategyOptions instead
KanikoBuildCache *bool `json:"kanikoBuildCache,omitempty"`
PublishStrategyOptions map[string]string `json:"PublishStrategyOptions,omitempty"`
}

// IntegrationPlatformKameletSpec --
Expand Down
17 changes: 11 additions & 6 deletions pkg/apis/camel/v1/integrationplatform_types_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
package v1

import (
"strconv"
"strings"

corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -178,13 +179,17 @@ func (in *IntegrationPlatformStatus) RemoveCondition(condType IntegrationPlatfor
in.Conditions = newConditions
}

// IsKanikoCacheEnabled tells if the KanikoCache is enabled on the integration platform build spec
func (b IntegrationPlatformBuildSpec) IsKanikoCacheEnabled() bool {
if b.KanikoBuildCache == nil {
// Cache is disabled by default
return false
// IsOptionEnabled tells if the KanikoCache is enabled on the integration platform build spec
func (b IntegrationPlatformBuildSpec) IsOptionEnabled(option string) bool {
//Key defined in builder/kaniko.go
if enabled, ok := b.PublishStrategyOptions[option]; ok {
res, err := strconv.ParseBool(enabled)
if err != nil {
return false
}
return res
}
return *b.KanikoBuildCache
return false
}

// GetTimeout returns the specified duration or a default one
Expand Down
14 changes: 14 additions & 0 deletions pkg/apis/camel/v1/zz_generated.deepcopy.go

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

2 changes: 2 additions & 0 deletions pkg/builder/kaniko.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ package builder

// KanikoCacheDir is the cache directory for Kaniko builds (mounted into the Kaniko pod).
const KanikoCacheDir = "/kaniko/cache"
const KanikoPVCName = "KanikoPersistentVolumeClaim"
const KanikoBuildCacheEnabled = "KanikoBuildCacheEnabled"
4 changes: 3 additions & 1 deletion pkg/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"os"
"regexp"
"strconv"
"strings"
"time"

Expand All @@ -39,6 +40,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime/pkg/client"

v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/builder"
"github.com/apache/camel-k/pkg/client"
"github.com/apache/camel-k/pkg/install"
"github.com/apache/camel-k/pkg/util"
Expand Down Expand Up @@ -443,7 +445,7 @@ func (o *installCmdOptions) install(cobraCmd *cobra.Command, _ []string) error {

kanikoBuildCacheFlag := cobraCmd.Flags().Lookup("kaniko-build-cache")
if kanikoBuildCacheFlag.Changed {
platform.Spec.Build.KanikoBuildCache = &o.KanikoBuildCache
platform.Spec.Build.PublishStrategyOptions[builder.KanikoBuildCacheEnabled] = strconv.FormatBool(o.KanikoBuildCache)
}

// Always create a platform in the namespace where the operator is located
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/trait_help_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build common
// +build common

/*
Expand Down
Loading

0 comments on commit b889082

Please sign in to comment.