Skip to content

Commit 43c41ef

Browse files
committed
feat(install): use a PVC to share artifacts among concurrent builds
Closes apache#3831
1 parent bb9efe1 commit 43c41ef

File tree

16 files changed

+121
-52
lines changed

16 files changed

+121
-52
lines changed

build/Dockerfile

+3-2
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ RUN ${MVNW_DIR}/mvnw --version | grep "Maven home:" | sed 's/Maven home: //' >>
4040
&& rm $(cat ${MVNW_DIR}default)/lib/maven-slf4j-provider*
4141
ENV MAVEN_OPTS="${MAVEN_OPTS} -Dlogback.configurationFile=${MAVEN_HOME}/conf/logback.xml"
4242

43-
ADD build/_maven_output /tmp/artifacts/m2
43+
ADD build/_maven_output /tmp/local/m2
4444
ADD build/_kamelets /kamelets
4545

46-
RUN chgrp -R 0 /tmp/artifacts/m2 \
46+
RUN mkdir -p /tmp/artifacts/m2 \
47+
&& chgrp -R 0 /tmp/artifacts/m2 \
4748
&& chmod -R g=u /tmp/artifacts/m2 \
4849
&& chgrp -R 0 /kamelets \
4950
&& chmod -R g=u /kamelets \

config/crd/bases/camel.apache.org_camelcatalogs.yaml

+4-3
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ spec:
404404
description: the actual state of the catalog
405405
properties:
406406
conditions:
407-
description: Conditions --
407+
description: a list of events happened for the CamelCatalog
408408
items:
409409
description: CamelCatalogCondition describes the state of a resource
410410
at a certain point.
@@ -437,15 +437,16 @@ spec:
437437
type: object
438438
type: array
439439
image:
440-
description: Image --
440+
description: the container image available for building an application
441+
with this catalog
441442
type: string
442443
observedGeneration:
443444
description: ObservedGeneration is the most recent generation observed
444445
for this Catalog.
445446
format: int64
446447
type: integer
447448
phase:
448-
description: Phase --
449+
description: the actual phase
449450
type: string
450451
type: object
451452
type: object

config/manager/kustomization.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ kind: Kustomization
2020

2121
resources:
2222
- operator-deployment.yaml
23+
- operator-storage.yaml
2324
- operator-service-account.yaml
2425

2526
patchesStrategicMerge:

config/manager/operator-deployment.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ spec:
4444
app.kubernetes.io/version: "2.0.0-SNAPSHOT"
4545
spec:
4646
serviceAccountName: camel-k-operator
47+
volumes:
48+
- name: camel-k-maven-repo
49+
persistentVolumeClaim:
50+
claimName: camel-k-maven-repo
4751
containers:
4852
- name: camel-k-operator
4953
image: docker.io/apache/camel-k:2.0.0-SNAPSHOT
@@ -78,3 +82,6 @@ spec:
7882
port: 8081
7983
initialDelaySeconds: 20
8084
periodSeconds: 10
85+
volumeMounts:
86+
- mountPath: "/tmp/artifacts/m2"
87+
name: camel-k-maven-repo

config/manager/operator-storage.yaml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# ---------------------------------------------------------------------------
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
# ---------------------------------------------------------------------------
17+
18+
kind: PersistentVolumeClaim
19+
apiVersion: v1
20+
metadata:
21+
name: camel-k-maven-repo
22+
spec:
23+
accessModes:
24+
- ReadWriteMany
25+
resources:
26+
requests:
27+
storage: 20Gi

docs/modules/ROOT/partials/apis/camel-k-crds.adoc

+3-3
Original file line numberDiff line numberDiff line change
@@ -947,21 +947,21 @@ ObservedGeneration is the most recent generation observed for this Catalog.
947947
|
948948
949949
950-
Phase --
950+
the actual phase
951951
952952
|`conditions` +
953953
*xref:#_camel_apache_org_v1_CamelCatalogCondition[[\]CamelCatalogCondition]*
954954
|
955955
956956
957-
Conditions --
957+
a list of events happened for the CamelCatalog
958958
959959
|`image` +
960960
string
961961
|
962962
963963
964-
Image --
964+
the container image available for building an application with this catalog
965965
966966
967967
|===

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ require (
2424
github.com/onsi/gomega v1.27.2
2525
github.com/openshift/api v3.9.1-0.20190927182313-d4a64ec2cbd8+incompatible
2626
github.com/operator-framework/api v0.13.0
27+
github.com/otiai10/copy v1.9.0
2728
github.com/pkg/errors v0.9.1
2829
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.60.0
2930
github.com/prometheus/client_golang v1.14.0

go.sum

+4
Original file line numberDiff line numberDiff line change
@@ -988,10 +988,14 @@ github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFSt
988988
github.com/operator-framework/api v0.13.0 h1:V1vUluRwajSBdDPCnzgTWDnn5LYxLk66VPVGMw3B7Uc=
989989
github.com/operator-framework/api v0.13.0/go.mod h1:FTiYGm11fZQ3cSX+EQHc/UWoGZAwkGfyeHU+wMJ8jmA=
990990
github.com/otiai10/copy v1.2.0/go.mod h1:rrF5dJ5F0t/EWSYODDu4j9/vEeYHMkc8jt0zJChqQWw=
991+
github.com/otiai10/copy v1.9.0 h1:7KFNiCgZ91Ru4qW4CWPf/7jqtxLagGRmIxWldPP9VY4=
992+
github.com/otiai10/copy v1.9.0/go.mod h1:hsfX19wcn0UWIHUQ3/4fHuehhk2UyArQ9dVFAn3FczI=
991993
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
992994
github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs=
993995
github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo=
994996
github.com/otiai10/mint v1.3.1/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc=
997+
github.com/otiai10/mint v1.4.0 h1:umwcf7gbpEwf7WFzqmWwSv0CzbeMsae2u9ZvpP8j2q4=
998+
github.com/otiai10/mint v1.4.0/go.mod h1:gifjb2MYOoULtKLqUAEILUG/9KONW6f7YsJ6vQLTlFI=
995999
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
9961000
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
9971001
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=

helm/camel-k/crds/crd-camel-catalog.yaml

+4-3
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ spec:
404404
description: the actual state of the catalog
405405
properties:
406406
conditions:
407-
description: Conditions --
407+
description: a list of events happened for the CamelCatalog
408408
items:
409409
description: CamelCatalogCondition describes the state of a resource
410410
at a certain point.
@@ -437,15 +437,16 @@ spec:
437437
type: object
438438
type: array
439439
image:
440-
description: Image --
440+
description: the container image available for building an application
441+
with this catalog
441442
type: string
442443
observedGeneration:
443444
description: ObservedGeneration is the most recent generation observed
444445
for this Catalog.
445446
format: int64
446447
type: integer
447448
phase:
448-
description: Phase --
449+
description: the actual phase
449450
type: string
450451
type: object
451452
type: object

pkg/cmd/dump.go

+21-6
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,21 @@ func dumpNamespace(ctx context.Context, c client.Client, ns string, out io.Write
8989
if err != nil {
9090
return err
9191
}
92+
93+
its, err := camelClient.CamelV1().Integrations(ns).List(ctx, metav1.ListOptions{})
94+
if err != nil {
95+
return err
96+
}
97+
fmt.Fprintf(out, "Found %d integrations:\n", len(its.Items))
98+
for _, integration := range its.Items {
99+
ref := integration
100+
pdata, err := kubernetes.ToYAML(&ref)
101+
if err != nil {
102+
return err
103+
}
104+
fmt.Fprintf(out, "---\n%s\n---\n", string(pdata))
105+
}
106+
92107
pls, err := camelClient.CamelV1().IntegrationPlatforms(ns).List(ctx, metav1.ListOptions{})
93108
if err != nil {
94109
return err
@@ -103,18 +118,18 @@ func dumpNamespace(ctx context.Context, c client.Client, ns string, out io.Write
103118
fmt.Fprintf(out, "---\n%s\n---\n", string(pdata))
104119
}
105120

106-
its, err := camelClient.CamelV1().Integrations(ns).List(ctx, metav1.ListOptions{})
121+
cat, err := camelClient.CamelV1().CamelCatalogs(ns).List(ctx, metav1.ListOptions{})
107122
if err != nil {
108123
return err
109124
}
110-
fmt.Fprintf(out, "Found %d integrations:\n", len(its.Items))
111-
for _, integration := range its.Items {
112-
ref := integration
113-
pdata, err := kubernetes.ToYAML(&ref)
125+
fmt.Fprintf(out, "Found %d catalogs:\n", len(pls.Items))
126+
for _, c := range cat.Items {
127+
ref := c
128+
cdata, err := kubernetes.ToYAML(&ref)
114129
if err != nil {
115130
return err
116131
}
117-
fmt.Fprintf(out, "---\n%s\n---\n", string(pdata))
132+
fmt.Fprintf(out, "---\n%s\n---\n", string(cdata))
118133
}
119134

120135
iks, err := camelClient.CamelV1().IntegrationKits(ns).List(ctx, metav1.ListOptions{})

pkg/controller/build/build_pod.go

+31-22
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ limitations under the License.
1818
package build
1919

2020
import (
21-
"bufio"
2221
"context"
2322
"fmt"
24-
"io"
2523
"os"
2624
"path/filepath"
2725
"strconv"
@@ -39,7 +37,6 @@ import (
3937
"github.com/apache/camel-k/pkg/platform"
4038
"github.com/apache/camel-k/pkg/util/defaults"
4139
"github.com/apache/camel-k/pkg/util/kubernetes"
42-
"github.com/apache/camel-k/pkg/util/log"
4340
)
4441

4542
const (
@@ -204,14 +201,29 @@ func buildPodName(build *v1.Build) string {
204201
}
205202

206203
func addBuildTaskToPod(build *v1.Build, taskName string, pod *corev1.Pod) {
207-
if !hasBuilderVolume(pod) {
208-
// Add the EmptyDir volume used to share the build state across tasks
209-
pod.Spec.Volumes = append(pod.Spec.Volumes, corev1.Volume{
210-
Name: builderVolume,
211-
VolumeSource: corev1.VolumeSource{
212-
EmptyDir: &corev1.EmptyDirVolumeSource{},
204+
if !hasVolume(pod, builderVolume) {
205+
pod.Spec.Volumes = append(pod.Spec.Volumes,
206+
// EmptyDir volume used to share the build state across tasks
207+
corev1.Volume{
208+
Name: builderVolume,
209+
VolumeSource: corev1.VolumeSource{
210+
EmptyDir: &corev1.EmptyDirVolumeSource{},
211+
},
213212
},
214-
})
213+
)
214+
}
215+
if !hasVolume(pod, "camel-k-maven-repo") {
216+
pod.Spec.Volumes = append(pod.Spec.Volumes,
217+
// Maven repo volume
218+
corev1.Volume{
219+
Name: "camel-k-maven-repo",
220+
VolumeSource: corev1.VolumeSource{
221+
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
222+
ClaimName: "camel-k-maven-repo",
223+
},
224+
},
225+
},
226+
)
215227
}
216228

217229
container := corev1.Container{
@@ -235,15 +247,6 @@ func addBuildTaskToPod(build *v1.Build, taskName string, pod *corev1.Pod) {
235247
addContainerToPod(build, container, pod)
236248
}
237249

238-
func readSpectrumLogs(newStdOut io.Reader) {
239-
scanner := bufio.NewScanner(newStdOut)
240-
241-
for scanner.Scan() {
242-
line := scanner.Text()
243-
log.Infof(line)
244-
}
245-
}
246-
247250
func addBuildahTaskToPod(ctx context.Context, c ctrl.Reader, build *v1.Build, task *v1.BuildahTask, pod *corev1.Pod) error {
248251
var bud []string
249252

@@ -473,19 +476,25 @@ func addKanikoTaskToPod(ctx context.Context, c ctrl.Reader, build *v1.Build, tas
473476
}
474477

475478
func addContainerToPod(build *v1.Build, container corev1.Container, pod *corev1.Pod) {
476-
if hasBuilderVolume(pod) {
479+
if hasVolume(pod, builderVolume) {
477480
container.VolumeMounts = append(container.VolumeMounts, corev1.VolumeMount{
478481
Name: builderVolume,
479482
MountPath: filepath.Join(builderDir, build.Name),
480483
})
481484
}
485+
if hasVolume(pod, "camel-k-maven-repo") {
486+
container.VolumeMounts = append(container.VolumeMounts, corev1.VolumeMount{
487+
Name: "camel-k-maven-repo",
488+
MountPath: "/tmp/artifacts/m2",
489+
})
490+
}
482491

483492
pod.Spec.InitContainers = append(pod.Spec.InitContainers, container)
484493
}
485494

486-
func hasBuilderVolume(pod *corev1.Pod) bool {
495+
func hasVolume(pod *corev1.Pod, name string) bool {
487496
for _, volume := range pod.Spec.Volumes {
488-
if volume.Name == builderVolume {
497+
if volume.Name == name {
489498
return true
490499
}
491500
}

pkg/install/common.go

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ func ObjectOrCollect(ctx context.Context, c client.Client, namespace string, col
110110
if err := c.Create(ctx, obj); err != nil && !errors.IsAlreadyExists(err) {
111111
return err
112112
}
113+
return nil
113114
}
114115

115116
if force {

pkg/install/operator.go

+1
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ func installKubernetesRoles(ctx context.Context, c client.Client, namespace stri
456456

457457
func installOperator(ctx context.Context, c client.Client, namespace string, customizer ResourceCustomizer, collection *kubernetes.Collection, force bool) error {
458458
return ResourcesOrCollect(ctx, c, namespace, collection, force, customizer,
459+
"/manager/operator-storage.yaml",
459460
"/manager/operator-deployment.yaml",
460461
)
461462
}

pkg/install/optional.go

+6
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,16 @@ import (
2424
"github.com/apache/camel-k/pkg/client"
2525
"github.com/apache/camel-k/pkg/util/defaults"
2626
logutil "github.com/apache/camel-k/pkg/util/log"
27+
cp "github.com/otiai10/copy"
2728
)
2829

2930
// OperatorStartupOptionalTools tries to install optional tools at operator startup and warns if something goes wrong.
3031
func OperatorStartupOptionalTools(ctx context.Context, c client.Client, namespace string, operatorNamespace string, log logutil.Logger) {
32+
// Try to copy any local runtime dependency to maven repository
33+
if err := cp.Copy("/tmp/local/m2", "/tmp/artifacts/m2"); err != nil {
34+
log.Info("Could not copy local runtime dependencies due to", err.Error())
35+
}
36+
3137
// Try to register the OpenShift CLI Download link if possible
3238
if err := OpenShiftConsoleDownloadLink(ctx, c); err != nil {
3339
log.Info("Cannot install OpenShift CLI download link: skipping.")

pkg/platform/defaults.go

+3-10
Original file line numberDiff line numberDiff line change
@@ -69,24 +69,17 @@ func ConfigureDefaults(ctx context.Context, c client.Client, p *v1.IntegrationPl
6969
}
7070

7171
if p.Status.Build.PublishStrategy == "" {
72-
log.Debugf("Integration Platform [%s]: setting publishing strategy", p.Namespace)
7372
if p.Status.Cluster == v1.IntegrationPlatformClusterOpenShift {
7473
p.Status.Build.PublishStrategy = v1.IntegrationPlatformBuildPublishStrategyS2I
7574
} else {
7675
p.Status.Build.PublishStrategy = v1.IntegrationPlatformBuildPublishStrategySpectrum
7776
}
77+
log.Debugf("Integration Platform [%s]: setting publishing strategy %s", p.Namespace, p.Status.Build.PublishStrategy)
7878
}
7979

8080
if p.Status.Build.BuildStrategy == "" {
81-
log.Debugf("Integration Platform [%s]: setting build strategy", p.Namespace)
82-
// Use the fastest strategy that they support (routine when possible)
83-
if p.Status.Build.PublishStrategy == v1.IntegrationPlatformBuildPublishStrategyS2I ||
84-
p.Status.Build.PublishStrategy == v1.IntegrationPlatformBuildPublishStrategySpectrum {
85-
p.Status.Build.BuildStrategy = v1.BuildStrategyRoutine
86-
} else {
87-
// The build output has to be shared via a volume
88-
p.Status.Build.BuildStrategy = v1.BuildStrategyPod
89-
}
81+
p.Status.Build.BuildStrategy = v1.BuildStrategyPod
82+
log.Debugf("Integration Platform [%s]: setting build strategy %s", p.Namespace, p.Status.Build.BuildStrategy)
9083
}
9184

9285
err := setPlatformDefaults(p, verbose)

pkg/trait/builder.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,12 @@ func (t *builderTrait) Apply(e *Environment) error {
151151

152152
if t.Strategy != "" {
153153
t.L.Infof("User defined build strategy %s", t.Strategy)
154-
if t.Strategy == string(v1.BuildStrategyPod) {
154+
switch t.Strategy {
155+
case string(v1.BuildStrategyPod):
155156
e.BuildStrategy = v1.BuildStrategyPod
156-
} else if t.Strategy == string(v1.BuildStrategyRoutine) {
157+
case string(v1.BuildStrategyRoutine):
157158
e.BuildStrategy = v1.BuildStrategyRoutine
158-
} else {
159+
default:
159160
return fmt.Errorf("Must specify either pod or routine build strategy, unknown %s", t.Strategy)
160161
}
161162
}

0 commit comments

Comments
 (0)