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

Refactor kaniko settings #3032

Merged
merged 1 commit into from
Mar 11, 2022
Merged

Refactor kaniko settings #3032

merged 1 commit into from
Mar 11, 2022

Conversation

mmelko
Copy link
Contributor

@mmelko mmelko commented Feb 23, 2022

Refactor kaniko settings by moving existing fields into map[string] field.
fix #3005

Release Note

fix(api): refactor kaniko settings

Copy link
Contributor

@squakez squakez left a comment

Choose a reason for hiding this comment

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

I think we should get rid of IsKanikoCacheEnabled() so we can really have no reference to any implementation detail. If you need to check if cache is enabled, you may just check the new map property.
You should format also running gofmt to have the changes formatted properly

@@ -169,8 +170,11 @@ func setPlatformDefaults(p *v1.IntegrationPlatform, verbose bool) error {
"-Dstyle.color=never",
}
}
if p.Status.Build.PersistentVolumeClaim == "" {
p.Status.Build.PersistentVolumeClaim = p.Name
//if p.Status.Build.PersistentVolumeClaim == "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

We can remove those comments to keep the source code more readable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok but I think that now with the map in place we have to have some additional logic to check if the key is present and then parsing the value. In this case IsKanikoCacheEnabled() helps because we don't need to do it everywhere.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can generalize that with IsOptionEnabled(key string) bool? the main goal is to hide any implementation detail from the API definition.

@mmelko mmelko force-pushed the main branch 2 times, most recently from 153f805 to b889082 Compare February 25, 2022 13:19
Copy link
Contributor

@squakez squakez left a comment

Choose a reason for hiding this comment

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

There are a few little improvements, but for the rest looks okay, thanks!

if b.KanikoBuildCache == nil {
// Cache is disabled by default
return false
// IsOptionEnabled tells if the KanikoCache is enabled on the integration platform build spec
Copy link
Contributor

Choose a reason for hiding this comment

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

Still reference to Kaniko. As it now is a general purpose we should change the comment as well

@@ -70,7 +70,11 @@ func (action *initializeAction) Handle(ctx context.Context, platform *v1.Integra
}

if platform.Status.Build.PublishStrategy == v1.IntegrationPlatformBuildPublishStrategyKaniko {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can comment this block with // nolint: staticcheck to avoid lint complains (due to the deprecation)

@@ -40,6 +40,11 @@ func createKanikoCacheWarmerPod(ctx context.Context, client client.Client, platf
// See:
// - https://kubernetes.io/docs/concepts/storage/persistent-volumes/#node-affinity
// - https://kubernetes.io/docs/concepts/storage/volumes/#local
pvcName := platform.Status.Build.PersistentVolumeClaim
Copy link
Contributor

Choose a reason for hiding this comment

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

nolint comments as above

@@ -169,8 +173,8 @@ func setPlatformDefaults(p *v1.IntegrationPlatform, verbose bool) error {
"-Dstyle.color=never",
}
}
if p.Status.Build.PersistentVolumeClaim == "" {
p.Status.Build.PersistentVolumeClaim = p.Name
if _, ok := p.Status.Build.PublishStrategyOptions["persistentVolumeClaim"]; !ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should not better use builder.KanikoPVCName constant?

@@ -189,15 +193,15 @@ func setPlatformDefaults(p *v1.IntegrationPlatform, verbose bool) error {
Duration: 5 * time.Minute,
}
}

if p.Status.Build.PublishStrategy == v1.IntegrationPlatformBuildPublishStrategyKaniko && p.Status.Build.KanikoBuildCache == nil {
_, cacheEnabled := p.Status.Build.PublishStrategyOptions["KanikoBuildCache"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Should not better use builder.KanikoBuildCacheEnabled constant?

@@ -113,6 +113,18 @@ func (t *builderTrait) Apply(e *Environment) error {
}})

case v1.IntegrationPlatformBuildPublishStrategyKaniko:
Copy link
Contributor

Choose a reason for hiding this comment

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

Nolint here

@mmelko
Copy link
Contributor Author

mmelko commented Feb 28, 2022

@squakez thanks for your feedback! I updated the PR accordingly

Copy link
Contributor

@squakez squakez left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@squakez squakez merged commit a79f832 into apache:main Mar 11, 2022
@squakez squakez mentioned this pull request May 24, 2022
5 tasks
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.

Kaniko settings refactoring
2 participants