Skip to content

Commit

Permalink
doc(trait): TraitCondition explaination
Browse files Browse the repository at this point in the history
  • Loading branch information
squakez committed Oct 24, 2023
1 parent 93a78e6 commit 31ad01a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 20 deletions.
8 changes: 3 additions & 5 deletions addons/master/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions docs/modules/ROOT/pages/architecture/traits.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 any informative or warning condition to be attached to the resulting Integration (for instance, traits forcefully altered by the platform, or deprecation notices).

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.

Expand Down
13 changes: 0 additions & 13 deletions pkg/trait/trait_condition_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 31ad01a

Please sign in to comment.