This is an automated email from the ASF dual-hosted git repository. nferraro pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 9c07fc6a329f56dfff5bd34e40650bdb313f3140 Author: nicolaferraro <[email protected]> AuthorDate: Mon Oct 5 10:49:35 2020 +0200 chore(e2e): add reserved kamelet names --- pkg/apis/camel/v1alpha1/kamelet_types.go | 11 +++++++++ pkg/apis/camel/v1alpha1/kamelet_types_support.go | 4 ++++ pkg/controller/kamelet/common.go | 30 +++++++++++++++++------- pkg/trait/kamelets.go | 2 +- 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/pkg/apis/camel/v1alpha1/kamelet_types.go b/pkg/apis/camel/v1alpha1/kamelet_types.go index 22be293..7b356c1 100644 --- a/pkg/apis/camel/v1alpha1/kamelet_types.go +++ b/pkg/apis/camel/v1alpha1/kamelet_types.go @@ -27,6 +27,10 @@ const ( AnnotationIcon = "camel.apache.org/kamelet.icon" ) +var ( + reservedKameletNames = map[string]bool{"source": true, "sink": true} +) + // KameletSpec defines the desired state of Kamelet type KameletSpec struct { Definition JSONSchemaProps `json:"definition,omitempty"` @@ -89,6 +93,11 @@ const ( KameletConditionReady KameletConditionType = "Ready" ) +const ( + // KameletConditionIllegalName -- + KameletConditionIllegalName string = "IllegalName" +) + type KameletPhase string const ( @@ -99,6 +108,8 @@ const ( KameletPhaseNone KameletPhase = "" // KameletPhaseReady -- KameletPhaseReady KameletPhase = "Ready" + // KameletPhaseError -- + KameletPhaseError KameletPhase = "Error" ) // +genclient diff --git a/pkg/apis/camel/v1alpha1/kamelet_types_support.go b/pkg/apis/camel/v1alpha1/kamelet_types_support.go index 9a9fcfd..2aa2c85 100644 --- a/pkg/apis/camel/v1alpha1/kamelet_types_support.go +++ b/pkg/apis/camel/v1alpha1/kamelet_types_support.go @@ -136,3 +136,7 @@ func (in *KameletStatus) RemoveCondition(condType KameletConditionType) { in.Conditions = newConditions } + +func ValidKameletName(name string) bool { + return !reservedKameletNames[name] +} diff --git a/pkg/controller/kamelet/common.go b/pkg/controller/kamelet/common.go index d6bf99f..f0e9d97 100644 --- a/pkg/controller/kamelet/common.go +++ b/pkg/controller/kamelet/common.go @@ -12,16 +12,28 @@ import ( func updateStatus(kamelet *v1alpha1.Kamelet) (*v1alpha1.Kamelet, error) { target := kamelet.DeepCopy() - target.Status.Phase = v1alpha1.KameletPhaseReady - target.Status.SetCondition( - v1alpha1.KameletConditionReady, - corev1.ConditionTrue, - "", - "", - ) - if err := recomputeProperties(target); err != nil { - return nil, err + + if !v1alpha1.ValidKameletName(kamelet.Name) { + target.Status.Phase = v1alpha1.KameletPhaseError + target.Status.SetCondition( + v1alpha1.KameletConditionReady, + corev1.ConditionFalse, + v1alpha1.KameletConditionIllegalName, + fmt.Sprintf("Kamelet name %q is reserved", kamelet.Name), + ) + } else { + target.Status.Phase = v1alpha1.KameletPhaseReady + target.Status.SetCondition( + v1alpha1.KameletConditionReady, + corev1.ConditionTrue, + "", + "", + ) + if err := recomputeProperties(target); err != nil { + return nil, err + } } + return target, nil } diff --git a/pkg/trait/kamelets.go b/pkg/trait/kamelets.go index 1b3c9dc..a13dcc6 100644 --- a/pkg/trait/kamelets.go +++ b/pkg/trait/kamelets.go @@ -273,7 +273,7 @@ func (t *kameletsTrait) getKameletKeys() []string { if strings.Contains(i, "/") { i = strings.SplitN(i, "/", 2)[0] } - if i != "" { + if i != "" && v1alpha1.ValidKameletName(i) { util.StringSliceUniqueAdd(&answer, i) } }
