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

✨ Add support for regexp in profile activation kubeContext #2065

Merged

Conversation

charlyx
Copy link
Contributor

@charlyx charlyx commented May 3, 2019

Hi 👋

This PR adds support for regexp in profile activation via kubeContext as specified in #1677
I tried to avoid breaking any existing behaviour.

Thanks for your review 🙏

PS: thanks @pyaillet for his help 😄

@codecov-io
Copy link

codecov-io commented May 3, 2019

Codecov Report

Merging #2065 into master will increase coverage by 0.18%.
The diff coverage is 66.66%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #2065      +/-   ##
=========================================
+ Coverage   56.12%   56.3%   +0.18%     
=========================================
  Files         180     180              
  Lines        7753    7801      +48     
=========================================
+ Hits         4351    4392      +41     
- Misses       2986    2991       +5     
- Partials      416     418       +2
Impacted Files Coverage Δ
pkg/skaffold/schema/profiles.go 86.2% <66.66%> (-1.48%) ⬇️
pkg/skaffold/sync/sync.go 70.32% <0%> (-4.06%) ⬇️
pkg/skaffold/schema/validation/validation.go 96.87% <0%> (-3.13%) ⬇️
pkg/skaffold/build/custom/dependencies.go 75% <0%> (-2.78%) ⬇️
pkg/skaffold/deploy/kustomize.go 77.01% <0%> (-0.9%) ⬇️
pkg/skaffold/util/tar.go 35.71% <0%> (-0.44%) ⬇️
pkg/skaffold/runner/labeller.go 100% <0%> (ø) ⬆️
pkg/skaffold/deploy/labels.go 16.04% <0%> (ø) ⬆️
pkg/skaffold/deploy/helm.go 62.55% <0%> (+0.15%) ⬆️
pkg/skaffold/deploy/kubectl.go 69.33% <0%> (+0.41%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 25f1b66...f0782e7. Read the comment docs.

@balopat balopat added the kokoro:run runs the kokoro jobs on a PR label May 10, 2019
@kokoro-team kokoro-team removed the kokoro:run runs the kokoro jobs on a PR label May 10, 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.

Thanks for opening this - it's a good start!
Added some comments around ! prefix + clearer error messaging.
Also it would be great to update the docs page for profiles https://skaffold.dev/docs/how-tos/profiles/

pkg/skaffold/schema/profiles.go Outdated Show resolved Hide resolved
@@ -124,7 +125,13 @@ func satisfies(expected, actual string) bool {
if strings.HasPrefix(expected, "!") {
return actual != expected[1:]
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should support the ! prefix for regular expressions too, e.g.:

!dev-.* should activate on all that don't match it

matcher, err := re.Compile(expected)

if err != nil {
logrus.Infof("profile activation criteria '%s' is not a valid regexp, falling back to string", expected)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
logrus.Infof("profile activation criteria '%s' is not a valid regexp, falling back to string", expected)
logrus.Infof("profile activation criteria '%s' is not a valid regexp, falling back to string: %v", expected, err)

@@ -377,8 +377,10 @@ func TestActivatedProfiles(t *testing.T) {
{Name: "activated", Activation: []latest.Activation{{KubeContext: "prod-context"}}},
{Name: "not-activated", Activation: []latest.Activation{{KubeContext: "dev-context"}}},
{Name: "also-activated", Activation: []latest.Activation{{KubeContext: "!dev-context"}}},
{Name: "activated-regexp", Activation: []latest.Activation{{KubeContext: "prod-.*"}}},
{Name: "not-activated-regexp", Activation: []latest.Activation{{KubeContext: "dev-.*"}}},
Copy link
Contributor

Choose a reason for hiding this comment

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

we should cover the !(regex) and invalid regex cases too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I create another profile so I can test those cases more easily?

For instance, in order to test the invalid regex I would need a profile that matches when comparing strings, I guess. Also, is there any character limitation for the profile? I couldn't find any in create_context.go

Regarding the !regexp I'm not sure how to test it... Shall we assume that if the regexp is valid we're testing the regexp matching and not the string comparison so I can make a simple test?

Copy link
Contributor

Choose a reason for hiding this comment

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

Feel free to add as many profiles as needed. Also, simple tests are better!

@dgageot
Copy link
Contributor

dgageot commented Jun 6, 2019

Hi @charlyx! Do you need help to finish this PR?

@charlyx
Copy link
Contributor Author

charlyx commented Jun 7, 2019

Hi @dgageot 👋

Thanks for asking!
Actually, I asked a question a few weeks ago: #2065 (comment)

@dgageot
Copy link
Contributor

dgageot commented Jul 2, 2019

Hi @charlyx, I'd like to see this PR merge. Anything I can do?

@dgageot
Copy link
Contributor

dgageot commented Jul 5, 2019

@charlyx I'm going to merge this PR and add the tests

@dgageot dgageot dismissed balopat’s stale review July 5, 2019 10:13

I'm going to add the tests for that PR in a separate PR

@dgageot dgageot merged commit d60d141 into GoogleContainerTools:master Jul 5, 2019
@charlyx
Copy link
Contributor Author

charlyx commented Jul 5, 2019 via email

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.

6 participants