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 aa6294f17a7d5c877fa5a1a07972e081f8b4d7e3 Author: Pasquale Congiusti <[email protected]> AuthorDate: Mon Dec 27 15:29:30 2021 +0100 chore(trait): resource validation --- docs/modules/traits/pages/container.adoc | 4 ++-- pkg/apis/camel/v1/integration_types.go | 2 +- pkg/trait/container.go | 22 ++++++++++++++++++++-- resources/traits.yaml | 13 ++++++------- 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/docs/modules/traits/pages/container.adoc b/docs/modules/traits/pages/container.adoc index 49d373b..0d608e4 100755 --- a/docs/modules/traits/pages/container.adoc +++ b/docs/modules/traits/pages/container.adoc @@ -83,11 +83,11 @@ The following configuration options are available: | container.configs | []string -| A list of configuration pointing to configmap/secret. Syntax: [configmap\|secret\|file]:name[key], where name represents the local file path or the configmap/secret name and key optionally represents the configmap/secret key to be filtered +| A list of configuration pointing to configmap/secret. Syntax: [configmap\|secret]:name[key], where name represents the resource name and key optionally represents the resource key to be filtered | container.resources | []string -| A list of resources pointing to configmap/secret. Syntax: [configmap\|secret\|file]:name[/key][@path], where name represents the local file path or the configmap/secret name, key optionally represents the configmap/secret key to be filtered and path represents the destination path +| A list of resources pointing to configmap/secret. Syntax: [configmap\|secret]:name[/key][@path], where name represents the resource name, key optionally represents the resource key to be filtered and path represents the destination path | container.volumes | []string diff --git a/pkg/apis/camel/v1/integration_types.go b/pkg/apis/camel/v1/integration_types.go index 9f9686a..3abe342 100644 --- a/pkg/apis/camel/v1/integration_types.go +++ b/pkg/apis/camel/v1/integration_types.go @@ -33,7 +33,7 @@ type IntegrationSpec struct { // Deprecated: // Use container trait (container.resources) to manage resources // Use openapi trait (openapi.configmaps) to manage OpenAPIs specifications - Resources []ResourceSpec `json:"resources,deprecatedInFavorOf,omitempty,deprecated"` + Resources []ResourceSpec `json:"resources,omitempty"` // Deprecated: use the IntegrationKit field Kit string `json:"kit,omitempty"` IntegrationKit *corev1.ObjectReference `json:"integrationKit,omitempty"` diff --git a/pkg/trait/container.go b/pkg/trait/container.go index 4a8ca1e..0abf914 100644 --- a/pkg/trait/container.go +++ b/pkg/trait/container.go @@ -20,6 +20,7 @@ package trait import ( "fmt" "path" + "strings" appsv1 "k8s.io/api/apps/v1" "k8s.io/api/batch/v1beta1" @@ -82,9 +83,9 @@ type containerTrait struct { Image string `property:"image" json:"image,omitempty"` // The pull policy: Always|Never|IfNotPresent ImagePullPolicy corev1.PullPolicy `property:"image-pull-policy" json:"imagePullPolicy,omitempty"` - // A list of configuration pointing to configmap/secret. Syntax: [configmap|secret|file]:name[key], where name represents the local file path or the configmap/secret name and key optionally represents the configmap/secret key to be filtered + // A list of configuration pointing to configmap/secret. Syntax: [configmap|secret]:name[key], where name represents the resource name and key optionally represents the resource key to be filtered Configs []string `property:"configs" json:"configs,omitempty"` - // A list of resources pointing to configmap/secret. Syntax: [configmap|secret|file]:name[/key][@path], where name represents the local file path or the configmap/secret name, key optionally represents the configmap/secret key to be filtered and path represents the destination path + // A list of resources pointing to configmap/secret. Syntax: [configmap|secret]:name[/key][@path], where name represents the resource name, key optionally represents the resource key to be filtered and path represents the destination path Resources []string `property:"resources" json:"resources,omitempty"` // A list of Persistent Volume Claims to be mounted. Syntax: [pvcname:/container/path] Volumes []string `property:"volumes" json:"volumes,omitempty"` @@ -167,6 +168,23 @@ func (t *containerTrait) Configure(e *Environment) (bool, error) { return false, fmt.Errorf("unsupported pull policy %s", t.ImagePullPolicy) } + // Validate resources and pvcs + for _, c := range t.Configs { + if !strings.HasPrefix(c, "configmap:") && !strings.HasPrefix(c, "secret:") { + return false, fmt.Errorf("unsupported config %s, must be a configmap or secret resource", c) + } + } + for _, r := range t.Resources { + if !strings.HasPrefix(r, "configmap:") && !strings.HasPrefix(r, "secret:") { + return false, fmt.Errorf("unsupported resource %s, must be a configmap or secret resource", r) + } + } + for _, r := range t.Volumes { + if !strings.HasPrefix(r, "pvc:") { + return false, fmt.Errorf("unsupported volume %s, must be a pvc", r) + } + } + return true, nil } diff --git a/resources/traits.yaml b/resources/traits.yaml index 8dec019..d3ec499 100755 --- a/resources/traits.yaml +++ b/resources/traits.yaml @@ -134,15 +134,14 @@ traits: description: 'The pull policy: Always|Never|IfNotPresent' - name: configs type: '[]string' - description: 'A list of configuration pointing to configmap/secret. Syntax: [configmap|secret|file]:name[key], - where name represents the local file path or the configmap/secret name and key - optionally represents the configmap/secret key to be filtered' + description: 'A list of configuration pointing to configmap/secret. Syntax: [configmap|secret]:name[key], + where name represents the resource name and key optionally represents the resource + key to be filtered' - name: resources type: '[]string' - description: 'A list of resources pointing to configmap/secret. Syntax: [configmap|secret|file]:name[/key][@path], - where name represents the local file path or the configmap/secret name, key - optionally represents the configmap/secret key to be filtered and path represents - the destination path' + description: 'A list of resources pointing to configmap/secret. Syntax: [configmap|secret]:name[/key][@path], + where name represents the resource name, key optionally represents the resource + key to be filtered and path represents the destination path' - name: volumes type: '[]string' description: 'A list of Persistent Volume Claims to be mounted. Syntax: [pvcname:/container/path]'
