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 2023/10/24 16:22:31 UTC
[camel-k] 02/02: doc(trait): TraitCondition explaination
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 31ad01a29e34e4822abb5080b3c0840a010cab4e
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Tue Oct 24 13:22:30 2023 +0200
doc(trait): TraitCondition explaination
---
addons/master/master.go | 8 +++-----
docs/modules/ROOT/pages/architecture/traits.adoc | 4 ++--
pkg/trait/trait_condition_types.go | 13 -------------
3 files changed, 5 insertions(+), 20 deletions(-)
diff --git a/addons/master/master.go b/addons/master/master.go
index c60733341..e2002e806 100644
--- a/addons/master/master.go
+++ b/addons/master/master.go
@@ -91,10 +91,6 @@ func (t *masterTrait) Configure(e *trait.Environment) (bool, *trait.TraitConditi
if !e.IntegrationInPhase(v1.IntegrationPhaseInitialization) && !e.IntegrationInRunningPhases() {
return false, nil, nil
}
- if !pointer.BoolDeref(t.Enabled, false) {
- return false, trait.NewIntegrationConditionUserDisabled(), nil
- }
-
if pointer.BoolDeref(t.Auto, true) {
// Check if the master component has been used
sources, err := kubernetes.ResolveIntegrationSources(e.Ctx, t.Client, e.Integration, e.Resources)
@@ -115,7 +111,9 @@ func (t *masterTrait) Configure(e *trait.Environment) (bool, *trait.TraitConditi
}
}
}
-
+ if !pointer.BoolDeref(t.Enabled, false) {
+ return false, trait.NewIntegrationConditionUserDisabled(), nil
+ }
if t.IncludeDelegateDependencies == nil || *t.IncludeDelegateDependencies {
t.delegateDependencies = findAdditionalDependencies(e, meta)
}
diff --git a/docs/modules/ROOT/pages/architecture/traits.adoc b/docs/modules/ROOT/pages/architecture/traits.adoc
index 3457b3b4e..fc56b1192 100644
--- a/docs/modules/ROOT/pages/architecture/traits.adoc
+++ b/docs/modules/ROOT/pages/architecture/traits.adoc
@@ -40,7 +40,7 @@ type Trait interface {
Identifiable
client.Injectable
InjectContext(context.Context)
- Configure(environment *Environment) (bool, error)
+ Configure(environment *Environment) (bool, TraitCondition, error)
Apply(environment *Environment) error
InfluencesKit() bool
InfluencesBuild(this, prev map[string]interface{}) bool
@@ -51,7 +51,7 @@ type Trait interface {
}
----
-Each trait will implement this interface. The most important methods that will be invoked by the xref:architecture/operator.adoc[Operator] are `Configure()` and `Apply()`. Basically, the `Configure()` method will set those inputs aforementioned (each trait has its own). The method is in charge to verify also the correctness of those expected parameters, where it makes sense (i.e., a well expected `Kubernetes` resource name).
+Each trait will implement this interface. The most important methods that will be invoked by the xref:architecture/operator.adoc[Operator] are `Configure()` and `Apply()`. Basically, the `Configure()` method will set those inputs aforementioned (each trait has its own). The method is in charge to verify also the correctness of those expected parameters, where it makes sense (i.e., a well expected `Kubernetes` resource name). The function can return a `TraitCondition` object containing an [...]
Once configured, the `Apply()` method will be called along the build or initialization phase in order to do the business logic expected for it. The `environment` variable will give you all the below resources you will need to perform your operation (ie, the `Integration` or any Kubernetes resource attached to it). You can have a deeper look at the `https://github.com/apache/camel-k/blob/main/pkg/trait/trait_types.go#L188[Environment]` struct.
diff --git a/pkg/trait/trait_condition_types.go b/pkg/trait/trait_condition_types.go
index 9b35647c9..6acf12dcf 100644
--- a/pkg/trait/trait_condition_types.go
+++ b/pkg/trait/trait_condition_types.go
@@ -54,23 +54,10 @@ func NewIntegrationConditionUserDisabled() *TraitCondition {
return NewIntegrationCondition(v1.IntegrationConditionTraitInfo, corev1.ConditionTrue, traitConfigurationMessage, userDisabledMessage)
}
-func newIntegrationConditionPlatformDisabled() *TraitCondition {
- return NewIntegrationCondition(v1.IntegrationConditionTraitInfo, corev1.ConditionTrue, traitConfigurationMessage, platformDisabledMessage)
-}
-
func newIntegrationConditionPlatformDisabledWithReason(reason string) *TraitCondition {
return NewIntegrationCondition(v1.IntegrationConditionTraitInfo, corev1.ConditionTrue, traitConfigurationMessage, fmt.Sprintf("%s: %s", platformDisabledMessage, reason))
}
-func newIntegrationKitCondition(ikct v1.IntegrationKitConditionType, cs corev1.ConditionStatus, message, reason string) *TraitCondition {
- return &TraitCondition{
- integrationKitConditionType: ikct,
- conditionStatus: cs,
- message: message,
- reason: reason,
- }
-}
-
func (tc *TraitCondition) integrationCondition() (v1.IntegrationConditionType, corev1.ConditionStatus, string, string) {
return tc.integrationConditionType, tc.conditionStatus, tc.message, tc.reason
}