Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.3.x] Various trait works #5404

Merged
merged 4 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion addons/keda/keda.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,12 @@ func (t *kedaTrait) Configure(e *trait.Environment) (bool, *trait.TraitCondition
if e.Integration == nil || !pointer.BoolDeref(t.Enabled, false) {
return false, nil, nil
}
if e.CamelCatalog == nil {
return false, trait.NewIntegrationConditionPlatformDisabledCatalogMissing(), nil
}
if !e.IntegrationInPhase(camelv1.IntegrationPhaseInitialization) && !e.IntegrationInRunningPhases() {
return false, nil, nil
}

if t.Auto == nil || *t.Auto {
if err := t.populateTriggersFromKamelets(e); err != nil {
return false, nil, err
Expand Down
3 changes: 3 additions & 0 deletions addons/master/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ func (t *masterTrait) Configure(e *trait.Environment) (bool, *trait.TraitConditi
if !pointer.BoolDeref(t.Enabled, true) {
return false, trait.NewIntegrationConditionUserDisabled(masterComponent), nil
}
if e.CamelCatalog == nil {
return false, trait.NewIntegrationConditionPlatformDisabledCatalogMissing(), nil
}
if !e.IntegrationInPhase(v1.IntegrationPhaseInitialization, v1.IntegrationPhaseBuildingKit) && !e.IntegrationInRunningPhases() {
return false, nil, nil
}
Expand Down
3 changes: 3 additions & 0 deletions addons/resume/resume.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ func (r *resumeTrait) Configure(environment *trait.Environment) (bool, *trait.Tr
if !pointer.BoolDeref(r.Enabled, false) {
return false, nil, nil
}
if environment.CamelCatalog == nil {
return false, trait.NewIntegrationConditionPlatformDisabledCatalogMissing(), nil
}
if !environment.IntegrationInPhase(v1.IntegrationPhaseInitialization) && !environment.IntegrationInRunningPhases() {
return false, nil, nil
}
Expand Down
4 changes: 3 additions & 1 deletion addons/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ func (t *telemetryTrait) Configure(e *trait.Environment) (bool, *trait.TraitCond
if e.Integration == nil || !pointer.BoolDeref(t.Enabled, false) {
return false, nil, nil
}

if e.CamelCatalog == nil {
return false, trait.NewIntegrationConditionPlatformDisabledCatalogMissing(), nil
}
var condition *trait.TraitCondition
if pointer.BoolDeref(t.Auto, true) {
if t.Endpoint == "" {
Expand Down
42 changes: 19 additions & 23 deletions addons/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ func (t *tracingTrait) Configure(e *trait.Environment) (bool, *trait.TraitCondit
if e.Integration == nil || !pointer.BoolDeref(t.Enabled, false) {
return false, nil, nil
}
if e.CamelCatalog == nil {
return false, trait.NewIntegrationConditionPlatformDisabledCatalogMissing(), nil
}

if pointer.BoolDeref(t.Auto, true) {
if t.Endpoint == "" {
Expand Down Expand Up @@ -125,30 +128,23 @@ func (t *tracingTrait) Configure(e *trait.Environment) (bool, *trait.TraitCondit
func (t *tracingTrait) Apply(e *trait.Environment) error {
util.StringSliceUniqueAdd(&e.Integration.Status.Capabilities, v1.CapabilityTracing)

if e.CamelCatalog != nil {
provider := e.CamelCatalog.CamelCatalogSpec.Runtime.Provider
properties := tracingProperties[provider]

if appPropEnabled := properties[propEnabled]; appPropEnabled != "" {
e.ApplicationProperties[appPropEnabled] = "true"
}

if appPropEndpoint := properties[propEndpoint]; appPropEndpoint != "" && t.Endpoint != "" {
e.ApplicationProperties[appPropEndpoint] = t.Endpoint
}

if appPropServiceName := properties[propServiceName]; appPropServiceName != "" && t.ServiceName != "" {
e.ApplicationProperties[appPropServiceName] = t.ServiceName
}

if appPropSamplerType := properties[propSamplerType]; appPropSamplerType != "" && t.SamplerType != nil {
e.ApplicationProperties[appPropSamplerType] = *t.SamplerType
}

if appPropSamplerParam := properties[propSamplerParam]; appPropSamplerParam != "" && t.SamplerParam != nil {
e.ApplicationProperties[appPropSamplerParam] = *t.SamplerParam
}
provider := e.CamelCatalog.CamelCatalogSpec.Runtime.Provider
properties := tracingProperties[provider]

if appPropEnabled := properties[propEnabled]; appPropEnabled != "" {
e.ApplicationProperties[appPropEnabled] = "true"
}
if appPropEndpoint := properties[propEndpoint]; appPropEndpoint != "" && t.Endpoint != "" {
e.ApplicationProperties[appPropEndpoint] = t.Endpoint
}
if appPropServiceName := properties[propServiceName]; appPropServiceName != "" && t.ServiceName != "" {
e.ApplicationProperties[appPropServiceName] = t.ServiceName
}
if appPropSamplerType := properties[propSamplerType]; appPropSamplerType != "" && t.SamplerType != nil {
e.ApplicationProperties[appPropSamplerType] = *t.SamplerType
}
if appPropSamplerParam := properties[propSamplerParam]; appPropSamplerParam != "" && t.SamplerParam != nil {
e.ApplicationProperties[appPropSamplerParam] = *t.SamplerParam
}

return nil
Expand Down
9 changes: 7 additions & 2 deletions docs/modules/ROOT/partials/apis/camel-k-crds.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6523,6 +6523,13 @@ string

The main container image

|`imageWasKit` +
bool
|


A flag to mark the image used is coming from an IntegrationKit created externally.

|`imagePullPolicy` +
*https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.27/#pullpolicy-v1-core[Kubernetes core/v1.PullPolicy]*
|
Expand Down Expand Up @@ -7195,8 +7202,6 @@ The JVM trait is used to configure the JVM that runs the Integration. This trait
(bound to a container image) built by Camel K operator. If the system detects the usage of a different container image (ie, built externally), then, the
trait is disabled by the platform.

WARNING: you can still enable the trait explicitly even when it is disabled by the platform but you should be aware that some configurations could fail.


[cols="2,2a",options="header"]
|===
Expand Down
4 changes: 4 additions & 0 deletions docs/modules/traits/pages/container.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ The following configuration options are available:
| string
| The main container image

| container.image-was-kit
| bool
| A flag to mark the image used is coming from an IntegrationKit created externally.

| container.image-pull-policy
| PullPolicy
| The pull policy: Always\|Never\|IfNotPresent
Expand Down
2 changes: 0 additions & 2 deletions docs/modules/traits/pages/jvm.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ The JVM trait is used to configure the JVM that runs the Integration. This trait
(bound to a container image) built by Camel K operator. If the system detects the usage of a different container image (ie, built externally), then, the
trait is disabled by the platform.

WARNING: you can still enable the trait explicitly even when it is disabled by the platform but you should be aware that some configurations could fail.


This trait is available in the following profiles: **Kubernetes, Knative, OpenShift**.

Expand Down
2 changes: 1 addition & 1 deletion e2e/advanced/operator_id_filtering_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestOperatorIDFiltering(t *testing.T) {
// Save resources by deleting "moving" integration
g.Expect(Kamel(t, ctx, "delete", "moving", "-n", ns).Execute()).To(Succeed())

g.Expect(KamelRunWithID(t, ctx, "operator-x", ns, "files/yaml.yaml", "--name", "pre-built", "--force", "-t", fmt.Sprintf("container.image=%s", image), "-t", "jvm.enabled=true").Execute()).To(Succeed())
g.Expect(KamelRunWithID(t, ctx, "operator-x", ns, "files/yaml.yaml", "--name", "pre-built", "--force", "-t", fmt.Sprintf("container.image=%s", image), "-t", "container.image-was-kit=true").Execute()).To(Succeed())
g.Consistently(IntegrationPhase(t, ctx, ns, "pre-built"), 10*time.Second).Should(BeEmpty())
g.Expect(AssignIntegrationToOperator(t, ctx, ns, "pre-built", operator2)).To(Succeed())
g.Eventually(IntegrationPhase(t, ctx, ns, "pre-built"), TestTimeoutShort).Should(Equal(v1.IntegrationPhaseRunning))
Expand Down
2 changes: 1 addition & 1 deletion e2e/install/cli/global_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func TestRunGlobalInstall(t *testing.T) {
}
g.Expect(TestClient(t).Create(ctx, &externalKit)).Should(BeNil())

g.Expect(KamelRun(t, ctx, ns5, "files/Java.java", "--name", "ext", "--kit", "external", "-t", "jvm.enabled=true").Execute()).To(Succeed())
g.Expect(KamelRun(t, ctx, ns5, "files/Java.java", "--name", "ext", "--kit", "external").Execute()).To(Succeed())
g.Eventually(IntegrationPodPhase(t, ctx, ns5, "ext"), TestTimeoutLong).Should(Equal(corev1.PodRunning))
g.Eventually(IntegrationLogs(t, ctx, ns5, "ext"), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
g.Expect(IntegrationKit(t, ctx, ns5, "ext")()).Should(Equal("external"))
Expand Down
8 changes: 8 additions & 0 deletions helm/camel-k/crds/crd-integration-platform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,10 @@ spec:
- Never
- IfNotPresent
type: string
imageWasKit:
description: A flag to mark the image used is coming from
an IntegrationKit created externally.
type: boolean
limitCPU:
description: The maximum amount of CPU required.
type: string
Expand Down Expand Up @@ -2603,6 +2607,10 @@ spec:
- Never
- IfNotPresent
type: string
imageWasKit:
description: A flag to mark the image used is coming from
an IntegrationKit created externally.
type: boolean
limitCPU:
description: The maximum amount of CPU required.
type: string
Expand Down
8 changes: 8 additions & 0 deletions helm/camel-k/crds/crd-integration-profile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,10 @@ spec:
- Never
- IfNotPresent
type: string
imageWasKit:
description: A flag to mark the image used is coming from
an IntegrationKit created externally.
type: boolean
limitCPU:
description: The maximum amount of CPU required.
type: string
Expand Down Expand Up @@ -2363,6 +2367,10 @@ spec:
- Never
- IfNotPresent
type: string
imageWasKit:
description: A flag to mark the image used is coming from
an IntegrationKit created externally.
type: boolean
limitCPU:
description: The maximum amount of CPU required.
type: string
Expand Down
4 changes: 4 additions & 0 deletions helm/camel-k/crds/crd-integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6597,6 +6597,10 @@ spec:
- Never
- IfNotPresent
type: string
imageWasKit:
description: A flag to mark the image used is coming from
an IntegrationKit created externally.
type: boolean
limitCPU:
description: The maximum amount of CPU required.
type: string
Expand Down
4 changes: 4 additions & 0 deletions helm/camel-k/crds/crd-kamelet-binding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6882,6 +6882,10 @@ spec:
- Never
- IfNotPresent
type: string
imageWasKit:
description: A flag to mark the image used is coming from
an IntegrationKit created externally.
type: boolean
limitCPU:
description: The maximum amount of CPU required.
type: string
Expand Down
4 changes: 4 additions & 0 deletions helm/camel-k/crds/crd-pipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6880,6 +6880,10 @@ spec:
- Never
- IfNotPresent
type: string
imageWasKit:
description: A flag to mark the image used is coming from
an IntegrationKit created externally.
type: boolean
limitCPU:
description: The maximum amount of CPU required.
type: string
Expand Down
8 changes: 5 additions & 3 deletions pkg/apis/camel/v1/integrationkit_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,14 @@ const (
// IntegrationKitTypeLabel labels the kit type.
IntegrationKitTypeLabel = "camel.apache.org/kit.type"

// IntegrationKitTypePlatform identifies a kit created by the platform.
// IntegrationKitTypePlatform identifies a Kit created by the platform.
IntegrationKitTypePlatform = "platform"
// IntegrationKitTypeUser identifies a kit created by the user.
// IntegrationKitTypeUser identifies a Kit created by the user.
IntegrationKitTypeUser = "user"
// IntegrationKitTypeExternal identifies a kit created by any third party.
// IntegrationKitTypeExternal identifies a Kit created by any third party.
IntegrationKitTypeExternal = "external"
// IntegrationKitTypeSynthetic identifies a synthetic Kit (generated for any container image for which the operator cannot make any assumption).
IntegrationKitTypeSynthetic = "synthetic"

// IntegrationKitLayoutLabel labels the kit layout.
IntegrationKitLayoutLabel = "camel.apache.org/kit.layout"
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/camel/v1/integrationkit_types_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ func (in *IntegrationKit) IsExternal() bool {
return in.Labels[IntegrationKitTypeLabel] == IntegrationKitTypeExternal
}

// IsSynthetic returns true for synthetic IntegrationKits.
func (in *IntegrationKit) IsSynthetic() bool {
return in.Labels[IntegrationKitTypeLabel] == IntegrationKitTypeSynthetic
}

// HasCapability returns true if the Kit is enabled with such a capability.
func (in *IntegrationKit) HasCapability(capability string) bool {
for _, cap := range in.Spec.Capabilities {
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/camel/v1/trait/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ type ContainerTrait struct {
Name string `property:"name" json:"name,omitempty"`
// The main container image
Image string `property:"image" json:"image,omitempty"`
// A flag to mark the image used is coming from an IntegrationKit created externally.
ImageWasKit *bool `property:"image-was-kit" json:"imageWasKit,omitempty"`
// The pull policy: Always|Never|IfNotPresent
// +kubebuilder:validation:Enum=Always;Never;IfNotPresent
ImagePullPolicy corev1.PullPolicy `property:"image-pull-policy" json:"imagePullPolicy,omitempty"`
Expand Down
2 changes: 0 additions & 2 deletions pkg/apis/camel/v1/trait/jvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ package trait
// (bound to a container image) built by Camel K operator. If the system detects the usage of a different container image (ie, built externally), then, the
// trait is disabled by the platform.
//
// WARNING: you can still enable the trait explicitly even when it is disabled by the platform but you should be aware that some configurations could fail.
//
// +camel-k:trait=jvm.
type JVMTrait struct {
Trait `property:",squash" json:",inline"`
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/camel/v1/trait/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 4 additions & 12 deletions pkg/cmd/promote.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,12 +469,8 @@ func (o *promoteCmdOptions) editIntegration(it *v1.Integration) *v1.Integration
dst.Spec.Traits.Container = &traitv1.ContainerTrait{}
}
dst.Spec.Traits.Container.Image = contImage
if dst.Spec.Traits.JVM == nil {
dst.Spec.Traits.JVM = &traitv1.JVMTrait{}
}
if dst.Spec.Traits.JVM.Enabled == nil {
dst.Spec.Traits.JVM.Enabled = pointer.Bool(true)
}
dst.Spec.Traits.Container.ImageWasKit = pointer.Bool(true)

return &dst
}

Expand Down Expand Up @@ -520,12 +516,8 @@ func (o *promoteCmdOptions) editPipe(kb *v1.Pipe, it *v1.Integration) *v1.Pipe {
dst.Spec.Integration.Traits.Container = &traitv1.ContainerTrait{}
}
dst.Spec.Integration.Traits.Container.Image = contImage
if dst.Spec.Integration.Traits.JVM == nil {
dst.Spec.Integration.Traits.JVM = &traitv1.JVMTrait{}
}
if dst.Spec.Integration.Traits.JVM.Enabled == nil {
dst.Spec.Integration.Traits.JVM.Enabled = pointer.Bool(true)
}
dst.Spec.Integration.Traits.Container.ImageWasKit = pointer.Bool(true)

if dst.Spec.Source.Ref != nil {
dst.Spec.Source.Ref.Namespace = o.To
}
Expand Down
18 changes: 6 additions & 12 deletions pkg/cmd/promote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ spec:
traits:
container:
image: my-special-image
jvm:
enabled: true
imageWasKit: true
status: {}
`, output)
}
Expand Down Expand Up @@ -144,8 +143,7 @@ spec:
traits:
container:
image: my-special-image
jvm:
enabled: true
imageWasKit: true
sink: {}
source: {}
status: {}
Expand Down Expand Up @@ -202,8 +200,7 @@ spec:
traits:
container:
image: my-special-image
jvm:
enabled: true
imageWasKit: true
status: {}
`, output)
}
Expand Down Expand Up @@ -248,8 +245,7 @@ spec:
traits:
container:
image: my-special-image
jvm:
enabled: true
imageWasKit: true
sink: {}
source: {}
status: {}
Expand Down Expand Up @@ -325,8 +321,7 @@ spec:
traits:
container:
image: my-special-image
jvm:
enabled: true
imageWasKit: true
status: {}
`, output)
// Verify also when the operator Id is set in the integration
Expand All @@ -349,8 +344,7 @@ spec:
traits:
container:
image: my-special-image
jvm:
enabled: true
imageWasKit: true
status: {}
`, output)
}
2 changes: 1 addition & 1 deletion pkg/controller/integrationkit/integrationkit_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func (r *reconcileIntegrationKit) Reconcile(ctx context.Context, request reconci

if target.Status.Phase == v1.IntegrationKitPhaseNone || target.Status.Phase == v1.IntegrationKitPhaseWaitingForPlatform {
rlog.Debug("Preparing to shift integration kit phase")
if target.IsExternal() {
if target.IsExternal() || target.IsSynthetic() {
target.Status.Phase = v1.IntegrationKitPhaseInitialization
return r.update(ctx, &instance, target)
}
Expand Down
Loading
Loading