You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pc...@apache.org on 2022/03/01 14:34:50 UTC

[camel-k] 11/18: chore(api): maintain .kamelet.spec.flow

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 667367d7228069c0e197ea8bfee75ac07e1558b2
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Mon Jan 31 10:06:22 2022 +0100

    chore(api): maintain .kamelet.spec.flow
---
 docs/modules/ROOT/partials/apis/camel-k-crds.adoc  |  7 -------
 docs/modules/ROOT/partials/apis/kamelets-crds.adoc | 12 ++++++------
 pkg/apis/camel/v1alpha1/kamelet_types_support.go   | 10 ++++++++++
 pkg/kamelet/initialize.go                          |  9 +++++++++
 pkg/trait/kamelets.go                              |  3 ++-
 5 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc
index 8d146da..f636fe8 100644
--- a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc
+++ b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc
@@ -2023,13 +2023,6 @@ string
 
 
 
-|`kit` +
-string
-|
-
-
-Deprecated: use the IntegrationKit field
-
 |`integrationKit` +
 *https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#objectreference-v1-core[Kubernetes core/v1.ObjectReference]*
 |
diff --git a/docs/modules/ROOT/partials/apis/kamelets-crds.adoc b/docs/modules/ROOT/partials/apis/kamelets-crds.adoc
index 3ca5d90..c9599ec 100644
--- a/docs/modules/ROOT/partials/apis/kamelets-crds.adoc
+++ b/docs/modules/ROOT/partials/apis/kamelets-crds.adoc
@@ -1042,19 +1042,19 @@ KameletSpec defines the desired state of Kamelet
 
 
 
-|`template` +
-*xref:#_camel_apache_org_v1alpha1_Template[Template]*
+|`flow` +
+*xref:apis/camel-k.adoc#_camel_apache_org_v1_Flow[github.com/apache/camel-k/pkg/apis/camel/v1.Flow]*
 |
 
 
+Deprecated: use template
 
-
-|`flow` +
-*xref:apis/camel-k.adoc#_camel_apache_org_v1_Flow[github.com/apache/camel-k/pkg/apis/camel/v1.Flow]*
+|`template` +
+*xref:apis/camel-k.adoc#_camel_apache_org_v1_Template[github.com/apache/camel-k/pkg/apis/camel/v1.Template]*
 |
 
 
-Deprecated: use template
+
 
 |`authorization` +
 *xref:#_camel_apache_org_v1alpha1_AuthorizationSpec[AuthorizationSpec]*
diff --git a/pkg/apis/camel/v1alpha1/kamelet_types_support.go b/pkg/apis/camel/v1alpha1/kamelet_types_support.go
index 52635f2..e363204 100644
--- a/pkg/apis/camel/v1alpha1/kamelet_types_support.go
+++ b/pkg/apis/camel/v1alpha1/kamelet_types_support.go
@@ -192,6 +192,16 @@ func ValidKameletProperties(kamelet *Kamelet) bool {
 	return true
 }
 
+func ValidKameletTemplate(kamelet *Kamelet) bool {
+	if kamelet == nil {
+		return true
+	}
+	if kamelet.Spec.Template != nil && kamelet.Spec.Flow != nil {
+		return false
+	}
+	return true
+}
+
 // NewKamelet creates a new kamelet
 func NewKamelet(namespace string, name string) Kamelet {
 	return Kamelet{
diff --git a/pkg/kamelet/initialize.go b/pkg/kamelet/initialize.go
index cb0a93b..0ac666a 100644
--- a/pkg/kamelet/initialize.go
+++ b/pkg/kamelet/initialize.go
@@ -50,6 +50,15 @@ func Initialize(kamelet *v1alpha1.Kamelet) (*v1alpha1.Kamelet, error) {
 			fmt.Sprintf("Kamelet property %q is reserved and cannot be part of the schema", v1alpha1.KameletIDProperty),
 		)
 	}
+	if !v1alpha1.ValidKameletTemplate(kamelet) {
+		ok = false
+		target.Status.SetCondition(
+			v1alpha1.KameletConditionReady,
+			corev1.ConditionFalse,
+			v1alpha1.KameletConditionReasonInvalidTemplate,
+			`Kamelet can only specify one of "flow" or "template"`,
+		)
+	}
 
 	if !ok {
 		target.Status.Phase = v1alpha1.KameletPhaseError
diff --git a/pkg/trait/kamelets.go b/pkg/trait/kamelets.go
index fd9ada3..a5c1c93 100644
--- a/pkg/trait/kamelets.go
+++ b/pkg/trait/kamelets.go
@@ -254,7 +254,8 @@ func (t *kameletsTrait) configureApplicationProperties(e *Environment) error {
 func (t *kameletsTrait) addKameletAsSource(e *Environment, kamelet *v1alpha1.Kamelet) error {
 	sources := make([]v1.SourceSpec, 0)
 
-	if kamelet.Spec.Template != nil {
+	// nolint: staticcheck
+	if kamelet.Spec.Template != nil || kamelet.Spec.Flow != nil {
 		template := kamelet.Spec.Template
 		if template == nil {
 			// Backward compatibility with Kamelets using flow