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

fix: Add option to disable Kaniko cache warming #922

Merged
merged 2 commits into from
Sep 30, 2019

Conversation

asifdxtreme
Copy link
Member

@asifdxtreme asifdxtreme commented Sep 3, 2019

Fixes: #907

This option will enable user to enable or disable the cache for building the images.

Release Note

Add the `kaniko-build-cache` option to disable Kaniko cache warming

@asifdxtreme
Copy link
Member Author

/cc @jamesnetherton @WillemJiang

@@ -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.cache, "cache", true, "To enable or disable the cache in building phase")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'cache' is perhaps a bit too vague as a flag name. Maybe align it with the other build related flags. E.g build-cache.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the review, I have updated it as per your suggestions

@@ -235,6 +237,12 @@ func (o *installCmdOptions) install(_ *cobra.Command, _ []string) error {
platform.Spec.Build.HTTPProxySecret = o.httpProxySecret
}

if o.cache {
platform.Spec.Build.Cache = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the if statement? Can we not simplify to platform.Spec.Build.Cache = o.cache?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the review, I have updated it as per your suggestions, I was trying to be defensive if someone passes non boolean values.

@@ -105,6 +105,7 @@ type IntegrationPlatformBuildSpec struct {
PersistentVolumeClaim string `json:"persistentVolumeClaim,omitempty"`
Maven MavenSpec `json:"maven,omitempty"`
HTTPProxySecret string `json:"httpProxySecret,omitempty"`
Cache bool `json:"bool,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I noticed when testing - the integrationplatform spec appears like:

  spec:
    build:
      baseImage: fabric8/s2i-java:3.0-java8
      bool: true

You'll need to tweak the field name to cache.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review, I have updated the code now

@asifdxtreme
Copy link
Member Author

Can someone re-trigger this build, seems like build failed because of network failure

@jamesnetherton
Copy link
Contributor

I think there are issues with git.apache.org so we may need to wait till they are fixed before the build is successful again.

We could maybe just merge this. I ran e2e tests locally + verified the change with minikube and it seemed ok.

@asifdxtreme
Copy link
Member Author

I think there are issues with git.apache.org so we may need to wait till they are fixed before the build is successful again.

We could maybe just merge this. I ran e2e tests locally + verified the change with minikube and it seemed ok.

Thanks a ton @jamesnetherton and @oscerd for reviewing and verifying the changes

@astefanutti
Copy link
Member

The build issue should be fixed with #926.

I would suggest the option and field are renamed more specifically to something like kanikoBuildCache.

@WillemJiang
Copy link
Member

The build issue should be fixed with #926.

I would suggest the option and field are renamed more specifically to something like kanikoBuildCache.

I agree, it makes the option more easy to understand.
@asifdxtreme Could you update the patch for it?

@asifdxtreme
Copy link
Member Author

The build issue should be fixed with #926.

I would suggest the option and field are renamed more specifically to something like kanikoBuildCache.

Thanks @astefanutti for the suggestion, I have updated the config name to kaniko-build-cache .

@@ -105,6 +105,7 @@ type IntegrationPlatformBuildSpec struct {
PersistentVolumeClaim string `json:"persistentVolumeClaim,omitempty"`
Maven MavenSpec `json:"maven,omitempty"`
HTTPProxySecret string `json:"httpProxySecret,omitempty"`
Cache bool `json:"cache,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please name the API field more specifically as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @astefanutti for the suggestion, I have updated it now

@@ -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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that it defaults to false when the platform is not created with the kamel CLI, e.g. with Operator Hub, while it defaults to true otherwise.

The KanikoBuildCache could be a *bool, whose value is defaulted to true during the platform initialisation phase if the pointer is nil.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, I didn't considered this scenario, I will update my code accordingly.

Copy link
Member Author

@asifdxtreme asifdxtreme Sep 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@astefanutti based on your input I thought to reverse the way we are dealing with this new variable, so now the kamel cli tool will take the value of skip-kaniko-build-cache whose value will be by default false. Now in the intialize we skip the cache warmer only if this value has been explicitly update as true (if platform.Namespace == platformutil.GetOperatorNamespace() && !platform.Spec.Build.SkipKanikoBuildCache {). Hope this will cover most of the scenarios of installation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some may find negative boolean variable a bad practice. I'm not sure Cobra handle boolean pointer so that it is possible to detect the option is not set and deal with a positive default. If it turns out it's possible, I think it'd be a better alternative.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@astefanutti I tried some options with Cobra but could'nt find a way to differentiate whether the value was not set or set to default values.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay, I'm looking at it right now and I'll get back to you on this today.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems possible to check whether an option has been explicitly provided with flag.Flag.Changed, e.g.:

func (o *installCmdOptions) install(cmd *cobra.Command, _ []string) error {
	flag := cmd.Flags().Lookup("kaniko-cache")
	if flag.Changed {
	// ...

Ideally, we would need spf13/pflag#214, e.g. for knative/client#346, but that's another issue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @astefanutti , I will look into this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @astefanutti Thanks again for the suggestion and help to fix this issue, as per your review suggestions I have updated the code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asifdxtreme thanks for your patience. That solves the CLI part. Then when the platform is created without the CLI, the cache needs to be enabled by default. That means turning the KanikoBuildCache field into a *bool and defaulting to true when its value is nil.

Copy link
Member

@astefanutti astefanutti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for your contribution and patience!

@astefanutti astefanutti merged commit 0ae900e into apache:master Sep 30, 2019
@asifdxtreme
Copy link
Member Author

Thanks a lot @astefanutti for helping to find the right solution for this PR and constantly reviewing and guiding me to get this PR merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add option to disable Kaniko cache warming
5 participants