This is an automated email from the ASF dual-hosted git repository.

astefanutti pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit f4928bf7c49c88f994d4ce73074ccc5582f41155
Author: Antonin Stefanutti <[email protected]>
AuthorDate: Wed Dec 18 11:35:07 2019 +0100

    chore(build): Isolate builder volume from Kaniko cache volume
---
 pkg/builder/kaniko/kaniko.go                       |  4 +--
 pkg/controller/integrationplatform/kaniko_cache.go | 14 ++++----
 pkg/trait/builder.go                               | 39 +++++++++++++---------
 3 files changed, 32 insertions(+), 25 deletions(-)

diff --git a/pkg/builder/kaniko/kaniko.go b/pkg/builder/kaniko/kaniko.go
index efc0291..b61638d 100644
--- a/pkg/builder/kaniko/kaniko.go
+++ b/pkg/builder/kaniko/kaniko.go
@@ -42,5 +42,5 @@ var KanikoSteps = []builder.Step{
        Steps.Publisher,
 }
 
-// BuildDir is the directory where to build artifacts (shared with the Kaniko 
pod)
-var BuildDir = "/workspace"
+// CacheDir is the cache directory for Kaniko builds (mounted into the Kaniko 
pod)
+const CacheDir = "/kaniko/cache"
diff --git a/pkg/controller/integrationplatform/kaniko_cache.go 
b/pkg/controller/integrationplatform/kaniko_cache.go
index 2d5674d..195090e 100644
--- a/pkg/controller/integrationplatform/kaniko_cache.go
+++ b/pkg/controller/integrationplatform/kaniko_cache.go
@@ -58,13 +58,13 @@ func createKanikoCacheWarmerPod(ctx context.Context, client 
client.Client, platf
                                        Name:  "warm-kaniko-cache",
                                        Image: 
fmt.Sprintf("gcr.io/kaniko-project/warmer:v%s", defaults.KanikoVersion),
                                        Args: []string{
-                                               "--cache-dir=/workspace/cache",
+                                               "--cache-dir=" + 
kaniko.CacheDir,
                                                "--image=" + 
platform.Status.Build.BaseImage,
                                        },
                                        VolumeMounts: []corev1.VolumeMount{
                                                {
-                                                       Name:      
"camel-k-builder",
-                                                       MountPath: 
kaniko.BuildDir,
+                                                       Name:      
"kaniko-cache",
+                                                       MountPath: 
kaniko.CacheDir,
                                                },
                                        },
                                },
@@ -76,11 +76,11 @@ func createKanikoCacheWarmerPod(ctx context.Context, client 
client.Client, platf
                                        Image:           "busybox",
                                        ImagePullPolicy: 
corev1.PullIfNotPresent,
                                        Command:         []string{"/bin/sh", 
"-c"},
-                                       Args:            []string{"mkdir -p 
/workspace/cache && chmod -R a+rwx /workspace"},
+                                       Args:            []string{"mkdir -p " + 
kaniko.CacheDir + "&& chmod -R a+rwx " + kaniko.CacheDir},
                                        VolumeMounts: []corev1.VolumeMount{
                                                {
-                                                       Name:      
"camel-k-builder",
-                                                       MountPath: 
kaniko.BuildDir,
+                                                       Name:      
"kaniko-cache",
+                                                       MountPath: 
kaniko.CacheDir,
                                                },
                                        },
                                },
@@ -88,7 +88,7 @@ func createKanikoCacheWarmerPod(ctx context.Context, client 
client.Client, platf
                        RestartPolicy: corev1.RestartPolicyOnFailure,
                        Volumes: []corev1.Volume{
                                {
-                                       Name: "camel-k-builder",
+                                       Name: "kaniko-cache",
                                        VolumeSource: corev1.VolumeSource{
                                                PersistentVolumeClaim: 
&corev1.PersistentVolumeClaimVolumeSource{
                                                        ClaimName: 
platform.Status.Build.PersistentVolumeClaim,
diff --git a/pkg/trait/builder.go b/pkg/trait/builder.go
index a81f841..e008c8f 100644
--- a/pkg/trait/builder.go
+++ b/pkg/trait/builder.go
@@ -37,6 +37,8 @@ import (
        "github.com/apache/camel-k/pkg/util/defaults"
 )
 
+const builderDir = "/builder"
+
 // The builder trait is internally used to determine the best strategy to
 // build and configure IntegrationKits.
 //
@@ -68,10 +70,19 @@ func (t *builderTrait) Apply(e *Environment) error {
                if err != nil {
                        return err
                }
-               mount := corev1.VolumeMount{Name: "camel-k-builder", MountPath: 
kaniko.BuildDir}
+
+               mount := corev1.VolumeMount{Name: "camel-k-builder", MountPath: 
builderDir}
                builderTask.VolumeMounts = append(builderTask.VolumeMounts, 
mount)
                kanikoTask.VolumeMounts = append(kanikoTask.VolumeMounts, mount)
 
+               // Use an emptyDir volume to coordinate the Camel Maven build 
and the Kaniko image build
+               builderTask.Volumes = append(builderTask.Volumes, corev1.Volume{
+                       Name: "camel-k-builder",
+                       VolumeSource: corev1.VolumeSource{
+                               EmptyDir: &corev1.EmptyDirVolumeSource{},
+                       },
+               })
+
                if e.Platform.Status.Build.IsKanikoCacheEnabled() {
                        // Co-locate with the Kaniko warmer pod for sharing the 
host path volume as the current
                        // persistent volume claim uses the default storage 
class which is likely relying
@@ -113,22 +124,18 @@ func (t *builderTrait) Apply(e *Environment) error {
                                        },
                                },
                        }
-                       // Use the PVC used to warm the Kaniko cache to 
coordinate the Camel Maven build and the Kaniko image build
-                       builderTask.Volumes = append(builderTask.Volumes, 
corev1.Volume{
-                               Name: "camel-k-builder",
+                       // Mount the PV used to warm the Kaniko cache into the 
Kaniko image build
+                       kanikoTask.Volumes = append(kanikoTask.Volumes, 
corev1.Volume{
+                               Name: "kaniko-cache",
                                VolumeSource: corev1.VolumeSource{
                                        PersistentVolumeClaim: 
&corev1.PersistentVolumeClaimVolumeSource{
                                                ClaimName: 
e.Platform.Status.Build.PersistentVolumeClaim,
                                        },
                                },
                        })
-               } else {
-                       // Use an emptyDir volume to coordinate the Camel Maven 
build and the Kaniko image build
-                       builderTask.Volumes = append(builderTask.Volumes, 
corev1.Volume{
-                               Name: "camel-k-builder",
-                               VolumeSource: corev1.VolumeSource{
-                                       EmptyDir: 
&corev1.EmptyDirVolumeSource{},
-                               },
+                       kanikoTask.VolumeMounts = 
append(kanikoTask.VolumeMounts, corev1.VolumeMount{
+                               Name:      "kaniko-cache",
+                               MountPath: kaniko.CacheDir,
                        })
                }
 
@@ -158,8 +165,8 @@ func (t *builderTrait) builderTask(e *Environment) 
*v1alpha1.BuilderTask {
                CamelVersion:    e.CamelCatalog.Version,
                RuntimeVersion:  e.CamelCatalog.RuntimeVersion,
                RuntimeProvider: e.CamelCatalog.RuntimeProvider,
-               //Sources:               e.Integration.Spec.Sources,
-               //Resources:     e.Integration.Spec.Resources,
+               //Sources:         e.Integration.Spec.Sources,
+               //Resources:       e.Integration.Spec.Resources,
                Dependencies: e.IntegrationKit.Spec.Dependencies,
                //TODO: sort steps for easier read
                Steps:      builder.StepIDsFor(builder.DefaultSteps...),
@@ -172,7 +179,7 @@ func (t *builderTrait) builderTask(e *Environment) 
*v1alpha1.BuilderTask {
                task.Steps = append(task.Steps, 
builder.StepIDsFor(s2i.S2iSteps...)...)
        } else if platform.SupportsKanikoPublishStrategy(e.Platform) {
                task.Steps = append(task.Steps, 
builder.StepIDsFor(kaniko.KanikoSteps...)...)
-               task.BuildDir = path.Join(kaniko.BuildDir, 
e.IntegrationKit.Name)
+               task.BuildDir = path.Join(builderDir, e.IntegrationKit.Name)
        }
 
        quarkus := e.Catalog.GetTrait("quarkus").(*quarkusTrait)
@@ -197,10 +204,10 @@ func (t *builderTrait) kanikoTask(e *Environment) 
(*v1alpha1.KanikoTask, error)
        env := make([]corev1.EnvVar, 0)
        baseArgs := []string{
                "--dockerfile=Dockerfile",
-               "--context=" + path.Join(kaniko.BuildDir, 
e.IntegrationKit.Name, "package", "context"),
+               "--context=" + path.Join(builderDir, e.IntegrationKit.Name, 
"package", "context"),
                "--destination=" + image,
                "--cache=" + 
strconv.FormatBool(e.Platform.Status.Build.IsKanikoCacheEnabled()),
-               "--cache-dir=" + path.Join(kaniko.BuildDir, "cache"),
+               "--cache-dir=" + kaniko.CacheDir,
        }
 
        args := make([]string, 0, len(baseArgs))

Reply via email to