-
Notifications
You must be signed in to change notification settings - Fork 8
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
Support multiple environment folders and add subcommands #112
Conversation
I'll take a look and give this one a good try. |
My findings with scenario two (
gave me a PR where dev-a is not the same as that branch it's PRing from (I figured it would be, I'm PRing from dev-a to dev-b right?). If we compare those two branches (dev-a and the generated one), they're not the same and there are conflicts. Justin then mentioned:
Over to @JustinKuli I think (he's mentioned spotting something). |
Good catch @a-roberts. I think all "new" branches created by the ServiceManager were based off the default branch in the repository. So although it was copying the files from "dev-a", and creating the PR onto "dev-b", the temporary branch was actually created off of "master". Bad PR: https://github.com/JustinKuli/gitops-example-dev/pull/18 Good PR (with the most recent commit): https://github.com/JustinKuli/gitops-example-dev/pull/19 |
Pulled in the latest code to try things this morning, confirmed the first example (promote between envs) is still good. Scenario two (promote between envs, same repo)
unless I refork/pull in the latest change from Justin's repo (our error reporting isn't great and that's not specific to this PR). After doing that and promoting again I get https://github.com/a-roberts/gitops-example-dev/pull/1. The commit message isn't great ( I'll update this comment once I've tried scenarios three and four. Update: scenario three's PR looks correct to start with. https://github.com/a-roberts/gitops-example-staging/pull/3/files there are three files here: what's in master for dev, the example.yaml (in dev), and a test.yaml. Command used:
But, I then made a change in dev (https://github.com/a-roberts/gitops-example-dev/blob/master/environments/dev/services/service-a/base/config/310-service.yaml) and did the promote command again and this file wasn't used in the new PR https://github.com/a-roberts/gitops-example-staging/pull/4/files and I expected it to be (because that's now in dev). @JustinKuli so here's another one I think should be looked at. Update: ah Justin pointed out that my change was to service-a, not promote-demo. Scenario four (using
so in the first case I'm using staging and the second I'm using dev, but the same env folder ( |
Adam, Justin, this is good work so far, thank you both. I asked Adam whether he thought some extra code coverage would be useful here. He wrote,
So do please expand the unit tests to cover all the errors found so far. @bigkevmcd and I have been talking about mixed environments - e.g. option-1 for dev and staging, option-3 for prod. In that case, you’d have to reference ‘prod’ from the pipelines.yaml in the ‘main’ gitops repo, which is think is a fair price to pay. This introduces ‘promotion between repo types’ scenarios I don't think we've considered up to now. We need to be able to promote from an environment in an option 1 repo, to an option-3, for example. Please ensure we have a test for this! |
My assessment of scenario three was wrong actually - becuse my change was done to service-a and not promote-demo. Justin pointed this out over Slack. So, I made a new promote-demo file https://github.com/a-roberts/gitops-example-dev/tree/master/environments/dev/services/promote-demo/base/config Promoted again (same command), new file picked up perfectly (https://github.com/a-roberts/gitops-example-staging/pull/6). Looks like it's just four that's a problem. |
Improving the commit messages would be really helpful. In the general case I feel like the commit message would need to specify everything that was passed in for the "from" and "to" Locations (URL, branch, env folder). That feels too verbose in simpler cases though, what if the subcommands can populate the commit message more specifically with just the piece that they are working with? So that |
Yeah, I think that'd be fine, the repo name is redundant if it's within the same repo really |
Ok, two updates here @a-roberts @mnuttall. Commit messages first. Promote now has more helpful default PR and commit messages, including the branch, repository, and environment folder (when an environment folder is given). The subcommands will use their own default messages, which have more limited information, so
One important thing to note with the change: the commit message, PR title, and PR body are now all the same. Previously the PR title was slightly different than the PR body / commit. Other change: tests. After struggling with mocking git repositories with multiple branches and environment folders, I gave up and switched to using real example repositories. I prevent PRs and commits from actually being made, so all changes still just exist locally. My example Linking to my own GitHub doesn't feel right, so we might consider adding these branches to an existing example repository here. Needing to pull these repositories for real (as opposed to mocking them) adds a bit of time to the tests: the promotion tests were taking around 10-12 seconds for me. But since the tests are using real git folders, I feel a bit more confident that everything is working. |
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.
Code changes look great, there are only nits that I've found, big +1 on the new commit message format. Plan to try this one out as soon as I can and go from there.
Tested again this morning and I'm a big fan of the new commit message style. So I did each of the options both with commit message overrides and without and observed the staged files in the PRs. 1: perfect. Promote environment dev to staging, correct file staged.
You can see the results at https://github.com/a-roberts/gitops-example-dev/pulls and all look great to me. I'll sift through the code (impl & tests) next to see if there's anything odd, otherwise I'm really happy with the improvements and looking forward to cutting a release. Great work @JustinKuli 😄 |
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.
Only minor comments/questions from me
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.
Lgtm, let's hand this to @mnuttall for the final nod or nay 😄
teams_branch_a_env = EnvLocation{exampleAlternativeRepo, "team-envs", "team-a"} | ||
) | ||
|
||
func TestRepoPromotionPath(t *testing.T) { |
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.
This is exactly what I was asking for, thank you :)
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.
LGTM, great piece of work @JustinKuli thank you!
Users will have the ability to specify every facet of the source and destination environments: repo URL, branch name, and environment folder. New tests check for various combinations of those options. Some minor changes were made to some repository implementation details, so that it can checkout specific branches (rather than just the default) and so that calling Clone() multiple times does not result in an error. Implements #92
These new sub-commands simplify the interface when promoting between branches in a repository, between environments in a repository, or between two "simple" repositories. The previous behavior is preserved if no sub-command is given: the user can specify any combination of repository, branch and environment folder (even a local repo). For #92
Main discussion in #92.
Added functional
--from-env
and--to-env
flags on the usual promote command, and added new subcommands to simplify the experience when promoting along the "usual" paths:services promote env <--from> <--to> <--repo> <--service>
services promote branch <--from> <--to> <--repo> <--service>
services promote repo <--from> <--to> <--service>
There was a bit of refactoring to try to prevent repetition in the new subcommands and keep things organized.
I found that I needed to re-bind the flags at the beginning of each "Action" function, otherwise only some subcommands would have the flags set correctly. I think it is something to do with the order that the
init
functions are executed in. The solution here was based on this comment: spf13/cobra#299 (comment)To test this, you'll need multiple repositories set up for multiple branches and environment folders. I have examples you can clone as needed:
These examples should demonstrate the usage (in addition to what's in the README):