Skip to content

Commit

Permalink
fix: Add option to disable Kaniko cache warming
Browse files Browse the repository at this point in the history
  • Loading branch information
asifdxtreme committed Sep 25, 2019
1 parent d52c19b commit dd43064
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions pkg/apis/camel/v1alpha1/integrationplatform_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ type IntegrationPlatformBuildSpec struct {
PersistentVolumeClaim string `json:"persistentVolumeClaim,omitempty"`
Maven MavenSpec `json:"maven,omitempty"`
HTTPProxySecret string `json:"httpProxySecret,omitempty"`
KanikoBuildCache bool `json:"kanikoBuildCache,omitempty"`
}

// IntegrationPlatformRegistrySpec --
Expand Down
3 changes: 2 additions & 1 deletion pkg/builder/kaniko/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"io/ioutil"
"path"
"strconv"
"time"

"github.com/apache/camel-k/pkg/builder"
Expand Down Expand Up @@ -79,7 +80,7 @@ func publisher(ctx *builder.Context) error {
"--dockerfile=Dockerfile",
"--context=" + contextDir,
"--destination=" + image,
"--cache",
"--cache=" + strconv.FormatBool(ctx.Build.Platform.Build.KanikoBuildCache),
"--cache-dir=/workspace/cache",
}

Expand Down
12 changes: 11 additions & 1 deletion pkg/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func newCmdInstall(rootCmdOptions *RootCmdOptions) *cobra.Command {
cmd.Flags().StringVar(&impl.buildStrategy, "build-strategy", "", "Set the build strategy")
cmd.Flags().StringVar(&impl.buildTimeout, "build-timeout", "", "Set how long the build process can last")
cmd.Flags().StringVar(&impl.traitProfile, "trait-profile", "", "The profile to use for traits")
cmd.Flags().BoolVar(&impl.kanikoBuildCache, "kaniko-build-cache", true, "To enable or disable the Kaniko Cache in building phase")
cmd.Flags().StringVar(&impl.httpProxySecret, "http-proxy-secret", "", "Configure the source of the secret holding HTTP proxy server details "+
"(HTTP_PROXY|HTTPS_PROXY|NO_PROXY)")

Expand Down Expand Up @@ -102,6 +103,7 @@ type installCmdOptions struct {
skipClusterSetup bool
exampleSetup bool
global bool
kanikoBuildCache bool
outputFormat string
camelVersion string
runtimeVersion string
Expand All @@ -120,7 +122,7 @@ type installCmdOptions struct {
}

// nolint: gocyclo
func (o *installCmdOptions) install(_ *cobra.Command, _ []string) error {
func (o *installCmdOptions) install(cobraCmd *cobra.Command, _ []string) error {
var collection *kubernetes.Collection
if o.outputFormat != "" {
collection = kubernetes.NewCollection()
Expand Down Expand Up @@ -235,6 +237,14 @@ func (o *installCmdOptions) install(_ *cobra.Command, _ []string) error {
platform.Spec.Build.HTTPProxySecret = o.httpProxySecret
}

kanikoBuildCacheFlag := cobraCmd.Flags().Lookup("kaniko-build-cache")

if kanikoBuildCacheFlag.Changed {
platform.Spec.Build.KanikoBuildCache = o.kanikoBuildCache
} else {
platform.Spec.Build.KanikoBuildCache = true
}

platform.Spec.Resources.Kits = o.kits

err = install.RuntimeObjectOrCollect(o.Context, c, namespace, collection, platform)
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/integrationplatform/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (action *initializeAction) Handle(ctx context.Context, platform *v1alpha1.I
}

// Check if the operator is running in the same namespace before starting the cache warmer
if platform.Namespace == platformutil.GetOperatorNamespace() {
if platform.Namespace == platformutil.GetOperatorNamespace() && platform.Spec.Build.KanikoBuildCache {
// Create the Kaniko warmer pod that caches the base image into the Camel K builder volume
action.L.Info("Create Kaniko cache warmer pod")
err = createKanikoCacheWarmerPod(ctx, action.client, platform)
Expand Down

0 comments on commit dd43064

Please sign in to comment.