Skip to content

Commit

Permalink
fix(trait): synthetic Kit
Browse files Browse the repository at this point in the history
While working on apache#5378 I realized the concept of external Kit is used widely also for the concept of what is a Synthetic Kit.

An external Kit is a kit coming from a build from the operator, whilst a synthetic Kit is not coming from an operator.
  • Loading branch information
squakez committed Apr 23, 2024
1 parent 1b1091a commit a5c2ce7
Show file tree
Hide file tree
Showing 27 changed files with 104 additions and 66 deletions.
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 @@ -6529,6 +6529,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.28/#pullpolicy-v1-core[Kubernetes core/v1.PullPolicy]*
|
Expand Down Expand Up @@ -7201,8 +7208,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 @@ -704,6 +704,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 @@ -2609,6 +2613,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 @@ -581,6 +581,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 @@ -2369,6 +2373,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 @@ -6638,6 +6638,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 @@ -6920,6 +6920,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 @@ -6918,6 +6918,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
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,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 @@ -2609,6 +2613,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
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,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 @@ -2369,6 +2373,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
Original file line number Diff line number Diff line change
Expand Up @@ -6638,6 +6638,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
Original file line number Diff line number Diff line change
Expand Up @@ -6920,6 +6920,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 pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6918,6 +6918,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
5 changes: 4 additions & 1 deletion pkg/trait/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,15 @@ func (t *containerTrait) configureImageIntegrationKit(e *Environment) error {
// Add some information for post-processing, this may need to be refactored
// to a proper data structure
kit.Labels = map[string]string{
v1.IntegrationKitTypeLabel: v1.IntegrationKitTypeExternal,
v1.IntegrationKitTypeLabel: v1.IntegrationKitTypeSynthetic,
kubernetes.CamelCreatorLabelKind: v1.IntegrationKind,
kubernetes.CamelCreatorLabelName: e.Integration.Name,
kubernetes.CamelCreatorLabelNamespace: e.Integration.Namespace,
kubernetes.CamelCreatorLabelVersion: e.Integration.ResourceVersion,
}
if pointer.BoolDeref(t.ImageWasKit, false) {
kit.Labels[v1.IntegrationKitTypeLabel] = v1.IntegrationKitTypeExternal
}

if v, ok := e.Integration.Annotations[v1.PlatformSelectorAnnotation]; ok {
v1.SetAnnotation(&kit.ObjectMeta, v1.PlatformSelectorAnnotation, v)
Expand Down
Loading

0 comments on commit a5c2ce7

Please sign in to comment.