Skip to content

Commit

Permalink
feat(trait): enable custom tasks via builder
Browse files Browse the repository at this point in the history
  • Loading branch information
squakez committed May 18, 2023
1 parent ed3da9a commit 4c493a4
Show file tree
Hide file tree
Showing 20 changed files with 285 additions and 26 deletions.
6 changes: 6 additions & 0 deletions config/crd/bases/camel.apache.org_integrationkits.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ spec:
description: The strategy to use, either `pod` or `routine`
(default routine)
type: string
tasks:
description: A list of tasks to be executed (available only
when using `pod` strategy) with format <name>;<container-image>;<container-command>
items:
type: string
type: array
verbose:
description: Enable verbose logging on build components that
support it (e.g. Kaniko build pod).
Expand Down
12 changes: 12 additions & 0 deletions config/crd/bases/camel.apache.org_integrationplatforms.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,12 @@ spec:
description: The strategy to use, either `pod` or `routine`
(default routine)
type: string
tasks:
description: A list of tasks to be executed (available only
when using `pod` strategy) with format <name>;<container-image>;<container-command>
items:
type: string
type: array
verbose:
description: Enable verbose logging on build components that
support it (e.g. Kaniko build pod).
Expand Down Expand Up @@ -2653,6 +2659,12 @@ spec:
description: The strategy to use, either `pod` or `routine`
(default routine)
type: string
tasks:
description: A list of tasks to be executed (available only
when using `pod` strategy) with format <name>;<container-image>;<container-command>
items:
type: string
type: array
verbose:
description: Enable verbose logging on build components that
support it (e.g. Kaniko build pod).
Expand Down
6 changes: 6 additions & 0 deletions config/crd/bases/camel.apache.org_integrations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6212,6 +6212,12 @@ spec:
description: The strategy to use, either `pod` or `routine`
(default routine)
type: string
tasks:
description: A list of tasks to be executed (available only
when using `pod` strategy) with format <name>;<container-image>;<container-command>
items:
type: string
type: array
verbose:
description: Enable verbose logging on build components that
support it (e.g. Kaniko build pod).
Expand Down
6 changes: 6 additions & 0 deletions config/crd/bases/camel.apache.org_kameletbindings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6487,6 +6487,12 @@ spec:
description: The strategy to use, either `pod` or `routine`
(default routine)
type: string
tasks:
description: A list of tasks to be executed (available
only when using `pod` strategy) with format <name>;<container-image>;<container-command>
items:
type: string
type: array
verbose:
description: Enable verbose logging on build components
that support it (e.g. Kaniko build pod).
Expand Down
6 changes: 6 additions & 0 deletions config/crd/bases/camel.apache.org_pipes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6484,6 +6484,12 @@ spec:
description: The strategy to use, either `pod` or `routine`
(default routine)
type: string
tasks:
description: A list of tasks to be executed (available
only when using `pod` strategy) with format <name>;<container-image>;<container-command>
items:
type: string
type: array
verbose:
description: Enable verbose logging on build components
that support it (e.g. Kaniko build pod).
Expand Down
1 change: 1 addition & 0 deletions config/rbac/operator-role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ rules:
- ""
resources:
- pods/proxy
- pods/log
verbs:
- get
- apiGroups:
Expand Down
41 changes: 41 additions & 0 deletions docs/modules/ROOT/partials/apis/camel-k-crds.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5495,6 +5495,13 @@ string
When using `pod` strategy, the maximum amount of memory required by the pod builder.
|`tasks` +
[]string
|
A list of tasks to be executed (available only when using `pod` strategy) with format <name>;<container-image>;<container-command>
|===
Expand Down Expand Up @@ -7504,6 +7511,40 @@ The type of service to be used, either 'ClusterIP', 'NodePort' or 'LoadBalancer'
[#_camel_apache_org_v1_trait_Task]
=== Task
A Task is a generic operation run on the project
[cols="2,2a",options="header"]
|===
|Field
|Description
|`name` +
string
|
The name of the task to execute
|`image` +
string
|
The container image to use
|`command` +
string
|
The command to execute
|===
[#_camel_apache_org_v1_trait_TolerationTrait]
=== TolerationTrait
Expand Down
24 changes: 24 additions & 0 deletions e2e/common/traits/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,28 @@ func TestBuilderTrait(t *testing.T) {

Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
})

t.Run("Run custom pipeline task", func(t *testing.T) {
Expect(KamelRunWithID(operatorID, ns, "files/Java.java",
"--name", name,
"-t", "builder.tasks=custom1;alpine;tree",
"-t", "builder.tasks=custom2;alpine;cat maven/pom.xml",
).Execute()).To(Succeed())

Eventually(IntegrationPodPhase(ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning))
Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))

integrationKitName := IntegrationKit(ns, name)()
builderKitName := fmt.Sprintf("camel-k-%s-builder", integrationKitName)
Eventually(BuilderPod(ns, builderKitName), TestTimeoutShort).ShouldNot(BeNil())
Eventually(len(BuilderPod(ns, builderKitName)().Spec.InitContainers), TestTimeoutShort).Should(Equal(3))
Eventually(BuilderPod(ns, builderKitName)().Spec.InitContainers[0].Name, TestTimeoutShort).Should(Equal("builder"))
Eventually(BuilderPod(ns, builderKitName)().Spec.InitContainers[1].Name, TestTimeoutShort).Should(Equal("custom1"))
Eventually(BuilderPod(ns, builderKitName)().Spec.InitContainers[2].Name, TestTimeoutShort).Should(Equal("custom2"))
Eventually(Logs(ns, builderKitName, corev1.PodLogOptions{Container: "custom1"})).Should(ContainSubstring(`generated-bytecode.jar`))
Eventually(Logs(ns, builderKitName, corev1.PodLogOptions{Container: "custom2"})).Should(ContainSubstring(`<artifactId>camel-k-runtime-bom</artifactId>`))

Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
})
}
6 changes: 6 additions & 0 deletions helm/camel-k/crds/crd-integration-kit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ spec:
description: The strategy to use, either `pod` or `routine`
(default routine)
type: string
tasks:
description: A list of tasks to be executed (available only
when using `pod` strategy) with format <name>;<container-image>;<container-command>
items:
type: string
type: array
verbose:
description: Enable verbose logging on build components that
support it (e.g. Kaniko build pod).
Expand Down
12 changes: 12 additions & 0 deletions helm/camel-k/crds/crd-integration-platform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,12 @@ spec:
description: The strategy to use, either `pod` or `routine`
(default routine)
type: string
tasks:
description: A list of tasks to be executed (available only
when using `pod` strategy) with format <name>;<container-image>;<container-command>
items:
type: string
type: array
verbose:
description: Enable verbose logging on build components that
support it (e.g. Kaniko build pod).
Expand Down Expand Up @@ -2653,6 +2659,12 @@ spec:
description: The strategy to use, either `pod` or `routine`
(default routine)
type: string
tasks:
description: A list of tasks to be executed (available only
when using `pod` strategy) with format <name>;<container-image>;<container-command>
items:
type: string
type: array
verbose:
description: Enable verbose logging on build components that
support it (e.g. Kaniko build pod).
Expand Down
6 changes: 6 additions & 0 deletions helm/camel-k/crds/crd-integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6212,6 +6212,12 @@ spec:
description: The strategy to use, either `pod` or `routine`
(default routine)
type: string
tasks:
description: A list of tasks to be executed (available only
when using `pod` strategy) with format <name>;<container-image>;<container-command>
items:
type: string
type: array
verbose:
description: Enable verbose logging on build components that
support it (e.g. Kaniko build pod).
Expand Down
6 changes: 6 additions & 0 deletions helm/camel-k/crds/crd-kamelet-binding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6487,6 +6487,12 @@ spec:
description: The strategy to use, either `pod` or `routine`
(default routine)
type: string
tasks:
description: A list of tasks to be executed (available
only when using `pod` strategy) with format <name>;<container-image>;<container-command>
items:
type: string
type: array
verbose:
description: Enable verbose logging on build components
that support it (e.g. Kaniko build pod).
Expand Down
6 changes: 6 additions & 0 deletions helm/camel-k/crds/crd-pipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6484,6 +6484,12 @@ spec:
description: The strategy to use, either `pod` or `routine`
(default routine)
type: string
tasks:
description: A list of tasks to be executed (available
only when using `pod` strategy) with format <name>;<container-image>;<container-command>
items:
type: string
type: array
verbose:
description: Enable verbose logging on build components
that support it (e.g. Kaniko build pod).
Expand Down
12 changes: 12 additions & 0 deletions pkg/apis/camel/v1/trait/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,16 @@ type BuilderTrait struct {
LimitCPU string `property:"limit-cpu" json:"limitCPU,omitempty"`
// When using `pod` strategy, the maximum amount of memory required by the pod builder.
LimitMemory string `property:"limit-memory" json:"limitMemory,omitempty"`
// A list of tasks to be executed (available only when using `pod` strategy) with format <name>;<container-image>;<container-command>
Tasks []string `property:"tasks" json:"tasks,omitempty"`
}

// A Task is a generic operation run on the project
type Task struct {
// The name of the task to execute
Name string `property:"name" json:"name,omitempty"`
// The container image to use
Image string `property:"image" json:"image,omitempty"`
// The command to execute
Command string `property:"command" json:"command,omitempty"`
}
20 changes: 20 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.

15 changes: 15 additions & 0 deletions pkg/controller/build/build_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ func newBuildPod(ctx context.Context, c ctrl.Reader, build *v1.Build) (*corev1.P
addBuildTaskToPod(build, task.S2i.Name, pod)
case task.Spectrum != nil:
addBuildTaskToPod(build, task.Spectrum.Name, pod)
case task.Custom != nil:
addCustomTaskToPod(build, task.Custom, pod)
}
}

Expand Down Expand Up @@ -528,6 +530,19 @@ func addKanikoTaskToPod(ctx context.Context, c ctrl.Reader, build *v1.Build, tas
return nil
}

func addCustomTaskToPod(build *v1.Build, task *v1.UserTask, pod *corev1.Pod) {
container := corev1.Container{
Name: task.Name,
Image: task.ContainerImage,
ImagePullPolicy: corev1.PullIfNotPresent,
Command: strings.Split(task.ContainerCommand, " "),
WorkingDir: filepath.Join(builderDir, build.Name),
Env: proxyFromEnvironment(),
}

addContainerToPod(build, container, pod)
}

func addContainerToPod(build *v1.Build, container corev1.Container, pod *corev1.Pod) {
if hasVolume(pod, builderVolume) {
container.VolumeMounts = append(container.VolumeMounts, corev1.VolumeMount{
Expand Down
Loading

0 comments on commit 4c493a4

Please sign in to comment.