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

init: Add default config name #2668

Merged

Conversation

corneliusweig
Copy link
Contributor

As discussed in #2556 skaffold init could populate the metadata.name field in skaffold.yaml. This PR adds the logic to populate the field with the basename of the currect working dir. I thought about adding tests, but I decided against adding some, because the test-cases could only test the trivial happy path of the added function.

Also, I have added the config name to all examples. This may be a controversial change..
Even though this field is optional in Skaffold, I think it makes the yaml files easier to navigate, because every example skaffold.yaml states what example it is.

Close #2556

@codecov
Copy link

codecov bot commented Aug 16, 2019

Codecov Report

Merging #2668 into master will decrease coverage by 0.07%.
The diff coverage is 33.33%.

Impacted Files Coverage Δ
pkg/skaffold/initializer/init.go 57.45% <33.33%> (-1.69%) ⬇️

Copy link
Contributor

@balopat balopat left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

@balopat balopat added the kokoro:run runs the kokoro jobs on a PR label Aug 16, 2019
Copy link
Contributor

@balopat balopat left a comment

Choose a reason for hiding this comment

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

I wonder if the allowed filenames is a larger set than the allowed names in metadata.name? In which case should we escape the folder name?

@corneliusweig
Copy link
Contributor Author

@balopat That's a good point. At the moment, we don't have any restrictions for config names. But usual kubernetes resources have some constraints (from https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names):

By convention, the names of Kubernetes resources should be up to maximum length of 253 characters and consist of lower case alphanumeric characters, -, and ., but certain resources have more specific restrictions.

Even though we don't validate that right now, I think it's a good idea to follow this pattern. What do you think about dirname.toLower().replace("[^-.a-z]", "-").clampLength(253)?

@kokoro-team kokoro-team removed the kokoro:run runs the kokoro jobs on a PR label Aug 16, 2019
@nkubala nkubala added the kokoro:run runs the kokoro jobs on a PR label Aug 19, 2019
@kokoro-team kokoro-team removed the kokoro:run runs the kokoro jobs on a PR label Aug 19, 2019
@nkubala
Copy link
Contributor

nkubala commented Aug 22, 2019

@corneliusweig seems reasonable to me, better safe than sorry.

@nkubala
Copy link
Contributor

nkubala commented Sep 9, 2019

@corneliusweig bump 👍

Copy link
Contributor

@tejal29 tejal29 left a comment

Choose a reason for hiding this comment

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

I feel the changes in the integration/examples are independent of this.
Can you break this in 2 PR

  1. Added metadata.name in examples.
  2. Actually edits the init flow.

@@ -372,9 +374,15 @@ func generateSkaffoldConfig(k Initializer, buildConfigPairs []builderImagePair)
// if the user doesn't have any k8s yamls, generate one for each dockerfile
logrus.Info("generating skaffold config")

name, err := suggestConfigName()
if err != nil {
return nil, errors.Wrap(err, "generating default config name")
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be an error ? since its a optional field, we should log this as error and continue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I agree.

@corneliusweig
Copy link
Contributor Author

corneliusweig commented Sep 11, 2019

@tejal29 I'm wondering if it even was a good idea to add the field in our examples. So far, they have been quite minimal and this breaks with that rationale. Please let me know if you have the same doubts. If you think this is a good idea, I'll create the separate PR, but I'll drop the commit from here.

Defaults to the basename of the current workdir.

Signed-off-by: Cornelius Weig <[email protected]>
@tejal29
Copy link
Contributor

tejal29 commented Sep 17, 2019

@corneliusweig I actually don't think we need to edit our examples.
These changes LGTM!

@tejal29 tejal29 added the kokoro:run runs the kokoro jobs on a PR label Sep 17, 2019
@kokoro-team kokoro-team removed the kokoro:run runs the kokoro jobs on a PR label Sep 17, 2019
@tejal29 tejal29 merged commit 43ebbb4 into GoogleContainerTools:master Sep 18, 2019
@corneliusweig corneliusweig deleted the w/default-config-name branch September 18, 2019 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

init: Add default skaffold-config name?
6 participants