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

feat(#344): add sub helmfiles explicit selectors #567

Merged
merged 5 commits into from
May 5, 2019

Conversation

sgandon
Copy link
Contributor

@sgandon sgandon commented Apr 27, 2019

Fixes #344 by allowing explicit selectors to be specified for composed helmfiles using the following structure

helmfiles:
- helmfile.d/a*.yaml:
    selectors:
    - name=prometheus      
    - name!=zipkin      
- helmfile.d/b*.yaml
- helmfile.d/c*.yaml:
    selectors: {}

2 modes here :

  • legacy mode when no the env var EXPERIMENTAL is not set to true
    • no selector : inherit from the command line.
    • selector: is specified then it is used (an emty means no inheritance from command line and take everything).
  • experimental when the env var EXPERIMENTAL=true
    • no selector : nothing is inherited from the command line so use all releases.
    • selector: is specified then it is used (an emty means no inheritance from command line and take everything).

@sgandon
Copy link
Contributor Author

sgandon commented Apr 27, 2019

I forgot to update the readme, I'll do so soon

@davidovich
Copy link
Contributor

This seems good. I also like the EXPERIMENTAL flag, but having only one Boolean value feels like it has only one purpose. What about using an identifier like EXPERIMENTAL=selectors ? That way the env var can be used to introduce simultaneous experimental features, controlled by one flag (probably allowing coma separated identifiers).

@sgandon
Copy link
Contributor Author

sgandon commented Apr 28, 2019

Year that's a good idea.
I'll change it to a feature enablement flag.

@sgandon
Copy link
Contributor Author

sgandon commented Apr 28, 2019

in fact I like the idea of enabling all experimental feature at once, so I guess I'll provide both identifiers and a "true" value to enable them all.

@sgandon sgandon changed the title feat(#344): add sub helmfiles explicit selectors WIP - feat(#344): add sub helmfiles explicit selectors Apr 28, 2019
@sgandon sgandon force-pushed the sgandon/use_sub_helmfile_selectors branch from e142839 to 923f7da Compare April 29, 2019 23:02
@sgandon sgandon changed the title WIP - feat(#344): add sub helmfiles explicit selectors feat(#344): add sub helmfiles explicit selectors Apr 29, 2019
@sgandon
Copy link
Contributor Author

sgandon commented Apr 29, 2019

all done, waiting for review.

README.md Outdated
@@ -805,6 +826,12 @@ Once you download all required charts into your machine, you can run `helmfile c
It basically run only `helm upgrade --install` with your already-downloaded charts, hence no Internet connection is required.
See #155 for more information on this topic.

## Experimental features
Some experimental features may be available for testing in perspective of being (or not) included in a future release.
Those features are set using the environment variable `EXPERIMENTAL`. Here is the current experimental feature :
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice. As I read this though, I think that EXPERIMENTAL alone cries for name clashes. Can we prefix with HELMFILE_ to remove this potential clash?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

absolutly !

Copy link
Collaborator

@mumoshu mumoshu 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 your contribution!

Looks awesome overall, but if I can wish one thing, I would love the sub-helmfile path to be denoted by the dedicated path setting, rather than the dictionary key.

That would make it extra clear that you can have only one path per sub-helmfile.

helmfiles:
- path: helmfile.d/a*.yaml
  selectors:
  - name=prometheus      
  - name!=zipkin      
- helmfile.d/b*.yaml
- path: helmfile.d/c*.yaml
  selectors: {}

@sgandon
Copy link
Contributor Author

sgandon commented May 2, 2019

@mumoshu but if I do this (which would have been much easier for parsing) we will loose the backward compatibily that I did maintain with the current PR, or am I missing something ?

@sgandon
Copy link
Contributor Author

sgandon commented May 2, 2019

or do think this is not an issue to maintain backward compatiblity ?

@mumoshu
Copy link
Collaborator

mumoshu commented May 2, 2019

@sgandon I do want to keep backward-compatibility, and it looked possible as your implementation is handling it in https://github.com/roboll/helmfile/pull/567/files#diff-f6be34387a141f652301c16cf7a5e36cR1411

That being said, the type switch there wouldn't change.

In my example, the first and the third sub-helmfile should be handled with the map case, and the second case with the string case(backward compatibility):

helmfiles:
- path: helmfile.d/a*.yaml
  selectors:
  - name=prometheus      
  - name!=zipkin      
- helmfile.d/b*.yaml
- path: helmfile.d/c*.yaml
  selectors: {}

@sgandon
Copy link
Contributor Author

sgandon commented May 2, 2019

ha sorry I did not see this example, so yes we can have both :)
I'll do the change and fix the conflictings files.

@mumoshu mumoshu force-pushed the master branch 6 times, most recently from ce5356f to 59b254e Compare May 4, 2019 13:10
@sgandon sgandon force-pushed the sgandon/use_sub_helmfile_selectors branch from 5d54b18 to 8db0021 Compare May 4, 2019 21:07
@sgandon
Copy link
Contributor Author

sgandon commented May 4, 2019

@mumoshu could you help me out with the test failure on circle-ci please ? the command make test works fine on my machine.

@sgandon
Copy link
Contributor Author

sgandon commented May 4, 2019

I believe I found the issue, map range does not guaranty the order. I'll fix that.

switch selectors := value.(type) {
case string: //check the string is `inherits` else error
if selectors == InheritsYamlValue {
hf.Inherits = true
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can be a nit but I'd suggest using:

helmfiles:
- path: path/to/subhelmfile.yaml
  selectorsInherited: true

So that the implementation becomes a bit simpler without the overloading of selectors.

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'll do that

Inherits bool //do the sub helmfiles inherits from parent selectors
}

const InheritsYamlValue = "inherits"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: Can be SelectorsInherits so that it looks a bit more consistent with golang community's convention that uses Where + What for const names

Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be removed completely if we go this way https://github.com/roboll/helmfile/pull/567/files#r281003831

if err := extractSelectorContent(hf, v); err != nil {
return err
}
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you by any chance remove this implementation of "dict key as the path to a subhelmfile" in favor of path, so that the implementation becomes simpler, and there's fewer ways to achieve the same goal?

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'll do

Copy link
Collaborator

@mumoshu mumoshu left a comment

Choose a reason for hiding this comment

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

Added a few comments mostly about names and clean-ups, but this looks awesome at this point!

And I feel like merging early makes it easier to maintain the feature without less possibility to introduce another code conflict before merging.

Thanks a lot for your great work and the contribution @sgandon!

@mumoshu mumoshu merged commit 4581e00 into roboll:master May 5, 2019
@sgandon sgandon deleted the sgandon/use_sub_helmfile_selectors branch May 5, 2019 20:40
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.

Possible to set selector in parent helmfile?
3 participants