-
Notifications
You must be signed in to change notification settings - Fork 345
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
Conversation
pkg/cmd/install.go
Outdated
@@ -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") |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
pkg/cmd/install.go
Outdated
@@ -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 |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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"` |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
Can someone re-trigger this build, seems like build failed because of network failure |
I think there are issues with 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 |
The build issue should be fixed with #926. I would suggest the option and field are renamed more specifically to something like |
I agree, it makes the option more easy to understand. |
Thanks @astefanutti for the suggestion, I have updated the config name to |
@@ -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"` |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
8b4a291
to
0a1f50f
Compare
There was a problem hiding this 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!
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. |
Fixes: #907
This option will enable user to enable or disable the cache for building the images.
Release Note