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

MultiArchitecture support #3309

Merged
merged 35 commits into from
Jun 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
899f8f0
restore core to upstream version
May 13, 2022
680fc7f
correct image and make file script
robertonav20 May 15, 2022
aaef9e4
update buildah image version for multi platform support
robertonav20 May 16, 2022
868d9aa
replace arch with platform
robertonav20 May 17, 2022
9610b54
add variant field and change the policy
May 17, 2022
82de032
add docker.io inside baseimage
May 17, 2022
883606f
obtain architecture value from PublishStrategyOptions
robertonav20 May 24, 2022
0d25484
replace name of buildah property
robertonav20 May 24, 2022
80b5fa6
correct buildah attribute
robertonav20 May 24, 2022
f0a2e7a
correct attribute name
May 26, 2022
b28dd3a
add Dockerfile.arch to support arm64
robertonav20 May 26, 2022
6b6a3b0
remove useless import
May 27, 2022
db4cfa1
execute goimports lint
May 27, 2022
4bfb4ad
Merge branch 'apache:main' into main
robertonav20 May 27, 2022
90a0fa6
correct docker file for buildx
May 27, 2022
83c7256
correct makefile command
May 31, 2022
9b9cc8d
fix platform initialize
May 31, 2022
ee084aa
improve readibility of bud command
May 31, 2022
9f55b65
remove useless containerd dependency
May 31, 2022
8b6d1c8
Fix makefile images-arch command
Jun 1, 2022
6b65f16
correct docker image name
Jun 1, 2022
cb94bb5
add default docker.io to baseimage because buildah required it
Jun 1, 2022
ae3509c
correct bud command
Jun 1, 2022
88029ed
Merge branch 'apache:main' into main
robertonav20 Jun 1, 2022
ddba5aa
correct bud command with platform
Jun 1, 2022
746ec58
add log to trace platform attribute
Jun 1, 2022
aed28da
Merge branch 'main' of https://github.com/robertonav20/camel-k into main
Jun 1, 2022
b7b37eb
add docs page to describe multi architecture use
robertonav20 Jun 2, 2022
8017221
add note
robertonav20 Jun 2, 2022
2d8239e
Generate CRD
Jun 3, 2022
69dd576
Merge branch 'apache:main' into main
robertonav20 Jun 8, 2022
b52c2a9
Merge branch 'apache:main' into main
robertonav20 Jun 16, 2022
b95f642
regenerate crd
Jun 18, 2022
b6c8d50
Merge remote-tracking branch 'refs/remotes/origin/main'
Jun 18, 2022
75f13c9
Merge branch 'apache:main' into main
robertonav20 Jun 20, 2022
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
47 changes: 47 additions & 0 deletions build/Dockerfile.arch
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM --platform=$BUILDPLATFORM ghcr.io/graalvm/graalvm-ce:ol8-java11-22.1.0

ARG MAVEN_VERSION="3.8.4"
ARG MAVEN_HOME="/usr/share/maven"
ARG SHA="a9b2d825eacf2e771ed5d6b0e01398589ac1bfa4171f36154d1b5787879605507802f699da6f7cfc80732a5282fd31b28e4cd6052338cbef0fa1358b48a5e3c8"
ARG BASE_URL="https://archive.apache.org/dist/maven/maven-3/${MAVEN_VERSION}/binaries"

USER 0

RUN mkdir -p ${MAVEN_HOME} \
&& curl -Lso /tmp/maven.tar.gz ${BASE_URL}/apache-maven-${MAVEN_VERSION}-bin.tar.gz \
&& echo "${SHA} /tmp/maven.tar.gz" | sha512sum -c - \
&& tar -xzC ${MAVEN_HOME} --strip-components=1 -f /tmp/maven.tar.gz \
&& rm -v /tmp/maven.tar.gz \
&& ln -s ${MAVEN_HOME}/bin/mvn /usr/bin/mvn \
&& rm ${MAVEN_HOME}/lib/maven-slf4j-provider*

ADD build/_maven_output /tmp/artifacts/m2
ADD build/_kamelets /kamelets
COPY build/_maven_overlay/ /usr/share/maven/lib/
ADD build/logback.xml /usr/share/maven/conf/

ENV MAVEN_OPTS="${MAVEN_OPTS} -Dlogback.configurationFile=/usr/share/maven/conf/logback.xml"

RUN chgrp -R 0 /tmp/artifacts/m2 \
&& chmod -R g=u /tmp/artifacts/m2 \
&& chgrp -R 0 /kamelets \
&& chmod -R g=u /kamelets

USER 1000

ADD build/_output/bin/kamel /usr/local/bin/kamel
3 changes: 3 additions & 0 deletions config/crd/bases/camel.apache.org_builds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ spec:
name:
description: name of the task
type: string
platform:
description: The platform of build image
type: string
registry:
description: where to publish the final image
properties:
Expand Down
81 changes: 81 additions & 0 deletions docs/modules/ROOT/pages/configuration/multi-architecture.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
[[multi-architecture-props]]
= Multi Architecture

To use kamel inside other architecture like arm64 you must build it and use Buildah as builder strategy.

NOTE: For now only arm64 is supported as other architectures

[[multi-architecture-build]]
== Build and Publish Kamel

As first step it's necessary to build kamel project `https://github.com/apache/camel-k` manually and push image to own docker repository.

I suggest to create a free docker image repository with `docker-hub` or `ghcr`.

[source,shell]
.script/Makefile
----
make build images-arch images-push
----

NOTE: The base image of kamel operator is graalvm because multi architecture quarkus-mandrel image not published yet

[[multi-architecture-install]]
== Install Kamel

Proceed with installation of kamel inside kubernetes cluster with the below command

[source,shell]
----
./kamel install --build-publish-strategy=Buildah --registry YOUR_REGISTRY --registry-auth-username YOUR_USERNAME --registry-auth-password YOUR_PASSWORD
----

[[multi-architecture-use]]
== Use kamel

Build and run an integration

[source,groovy]
.hello.groovy
----
from('timer:tick?period=3000')
.setBody().constant('Hello world from Camel K')
.to('log:info')
----

Send the groovy file to kamel operator to build, publish and run it
[source,shell]
----
kamel run hello.groovy
----

[[multi-architecture-configure-optional]]
== Optional Buildah Configuration

If you want change the default architecture of buildah build strategy, you must edit integration platform manually.

[source,shell]
----
kubectl edit ip
----

This command will open the editor with the yaml of `IntegrationPlatform`, to change the architecture you can fill inside `spec.build.PublishStrategyOptions` as below
[source,yaml]
----
spec:
build:
PublishStrategyOptions:
BuildahPlatform: linux/arm/v8
----

After few seconds the yaml will be updated and that field is imported inside status

[source,yaml]
----
status:
build:
PublishStrategyOptions:
BuildahPlatform: linux/arm/v8
----

NOTE: It's important to know buidah supports only amd64 and arm64
40 changes: 37 additions & 3 deletions docs/modules/ROOT/partials/apis/camel-k-crds.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,13 @@ BuildStatus defines the observed state of Build
|Field
|Description

|`observedGeneration` +
int64
|


ObservedGeneration is the most recent generation observed for this Build.

|`phase` +
*xref:#_camel_apache_org_v1_BuildPhase[BuildPhase]*
|
Expand Down Expand Up @@ -546,6 +553,13 @@ BuildahTask is used to configure Buildah



|`platform` +
string
|


The platform of build image

|`verbose` +
bool
|
Expand Down Expand Up @@ -1425,6 +1439,13 @@ IntegrationKitStatus defines the observed state of IntegrationKit
|Field
|Description

|`observedGeneration` +
int64
|


ObservedGeneration is the most recent generation observed for this IntegrationKit.

|`phase` +
*xref:#_camel_apache_org_v1_IntegrationKitPhase[IntegrationKitPhase]*
|
Expand Down Expand Up @@ -1861,6 +1882,13 @@ IntegrationPlatformStatus defines the observed state of IntegrationPlatform



|`observedGeneration` +
int64
|


ObservedGeneration is the most recent generation observed for this IntegrationPlatform.

|`phase` +
*xref:#_camel_apache_org_v1_IntegrationPlatformPhase[IntegrationPlatformPhase]*
|
Expand Down Expand Up @@ -2014,6 +2042,13 @@ IntegrationStatus defines the observed state of Integration
|Field
|Description

|`observedGeneration` +
int64
|


ObservedGeneration is the most recent generation observed for this Integration.

|`phase` +
*xref:#_camel_apache_org_v1_IntegrationPhase[IntegrationPhase]*
|
Expand Down Expand Up @@ -2477,9 +2512,8 @@ NodeSelector

TopologySpreadConstraints


|`securityContext` +
*https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#podsecuritycontext-v1-core[[\]Kubernetes core/v1.PodSecurityContext]*
*https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#podsecuritycontext-v1-core[Kubernetes core/v1.PodSecurityContext]*
|


Expand Down Expand Up @@ -3196,4 +3230,4 @@ Selects a key of a ConfigMap.
Selects a key of a secret.


|===
|===
14 changes: 14 additions & 0 deletions docs/modules/ROOT/partials/apis/kamelets-crds.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,13 @@ KameletBindingStatus specify the status of a binding
|Field
|Description

|`observedGeneration` +
int64
|


ObservedGeneration is the most recent generation observed for this KameletBinding.

|`phase` +
*xref:#_camel_apache_org_v1alpha1_KameletBindingPhase[KameletBindingPhase]*
|
Expand Down Expand Up @@ -1096,6 +1103,13 @@ KameletStatus defines the observed state of Kamelet
|Field
|Description

|`observedGeneration` +
int64
|


ObservedGeneration is the most recent generation observed for this Kamelet.

|`phase` +
*xref:#_camel_apache_org_v1alpha1_KameletPhase[KameletPhase]*
|
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ github.com/containerd/containerd v1.5.0-beta.1/go.mod h1:5HfvG1V2FsKesEGQ17k5/T7
github.com/containerd/containerd v1.5.0-beta.3/go.mod h1:/wr9AVtEM7x9c+n0+stptlo/uBBoBORwEx6ardVcmKU=
github.com/containerd/containerd v1.5.0-beta.4/go.mod h1:GmdgZd2zA2GYIBZ0w09ZvgqEq8EfBp/m3lcVZIvPHhI=
github.com/containerd/containerd v1.5.0-rc.0/go.mod h1:V/IXoMqNGgBlabz3tHD2TWDoTJseu1FGOKuoA4nNb2s=
github.com/containerd/containerd v1.5.8 h1:NmkCC1/QxyZFBny8JogwLpOy2f+VEbO/f6bV2Mqtwuw=
github.com/containerd/containerd v1.5.8/go.mod h1:YdFSv5bTFLpG2HIYmfqDpSYYTDX+mc5qtSuYx1YUb/s=
github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
github.com/containerd/continuity v0.0.0-20190815185530-f2a389ac0a02/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
Expand Down
3 changes: 3 additions & 0 deletions helm/camel-k/crds/crd-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ spec:
name:
description: name of the task
type: string
platform:
description: The platform of build image
type: string
registry:
description: where to publish the final image
properties:
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/camel/v1/build_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ type PublishTask struct {
type BuildahTask struct {
BaseTask `json:",inline"`
PublishTask `json:",inline"`
// The platform of build image
Platform string `json:"platform,omitempty"`
// log more information
Verbose *bool `json:"verbose,omitempty"`
}
Expand Down
20 changes: 20 additions & 0 deletions pkg/builder/buildah.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package builder

const BuildahPlatform = "BuildahPlatform"
18 changes: 15 additions & 3 deletions pkg/controller/build/build_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
corev1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

ctrl "sigs.k8s.io/controller-runtime/pkg/client"

v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
Expand Down Expand Up @@ -239,16 +238,29 @@ func addBuildTaskToPod(build *v1.Build, taskName string, pod *corev1.Pod) {
}

func addBuildahTaskToPod(ctx context.Context, c ctrl.Reader, build *v1.Build, task *v1.BuildahTask, pod *corev1.Pod) error {
bud := []string{
var bud []string

bud = []string{
"buildah",
"bud",
"--storage-driver=vfs",
}

if task.Platform != "" {
robertonav20 marked this conversation as resolved.
Show resolved Hide resolved
bud = append(bud, []string{
"--platform",
task.Platform,
}...)
}

bud = append(bud, []string{
"--pull-always",
"-f",
"Dockerfile",
"-t",
task.Image,
".",
}
}...)

push := []string{
"buildah",
Expand Down
11 changes: 11 additions & 0 deletions pkg/trait/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,17 @@ func (t *builderTrait) Apply(e *Environment) error {
}})

case v1.IntegrationPlatformBuildPublishStrategyBuildah:
var platform string
var found bool
if platform, found = e.Platform.Status.Build.PublishStrategyOptions[builder.BuildahPlatform]; !found {
platform = ""
t.L.Infof("Attribute platform for buildah not found, default from host will be used!")
} else {
t.L.Infof("User defined %s platform, will be used from buildah!", platform)
}

e.BuildTasks = append(e.BuildTasks, v1.Task{Buildah: &v1.BuildahTask{
Platform: platform,
BaseTask: v1.BaseTask{
Name: "buildah",
},
Expand Down Expand Up @@ -151,6 +161,7 @@ func (t *builderTrait) builderTask(e *Environment) (*v1.BuilderTask, error) {
for _, repo := range e.IntegrationKit.Spec.Repositories {
maven.Repositories = append(maven.Repositories, mvn.NewRepository(repo))
}

task := &v1.BuilderTask{
BaseTask: v1.BaseTask{
Name: "builder",
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ const (
DefaultRuntimeVersion = "1.13.0"

// BuildahVersion --
BuildahVersion = "1.14.0"
BuildahVersion = "1.23.3"

// KanikoVersion --
KanikoVersion = "0.17.1"

// baseImage --
baseImage = "adoptopenjdk/openjdk11:slim"
baseImage = "docker.io/adoptopenjdk/openjdk11:slim"
robertonav20 marked this conversation as resolved.
Show resolved Hide resolved

// LocalRepository --
LocalRepository = "/tmp/artifacts/m2"
Expand Down
Loading