-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Always use the default workspace directory when building commands context #1620
Always use the default workspace directory when building commands context #1620
Conversation
fa6c02d
to
9989ebe
Compare
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.
PR looks good overall, good job catching the issue!
Would be good to add some tests around the change. Mainly to make sure that the project context is not losing the workspace when it is passed into DefaultProjectCommandRunner
@msarvar thanks for the comment.
Initially I was also concerned about this as I thought that changing the I have looked at the existing tests for inspiration but I could not come up with an easy way to test the scenario you suggest in a reasonable time. Do you have any more specific suggestions about how to create some tests? As a general comment I think the project would benefit from more comprehensive tests that simulate:
But this goes a bit beyond the scope of this PR. |
@giuli007 what you say makes sense, and it is a bit tricky to test it in a meaningful way. I'm ok with merging this as is, PR needs to pass the checks through, can you take a look and try to the status check? |
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.
thanks for fixing the issue!
@giuli007 I think the PR needs to be rebased, and that should fix the failing status check. |
…text When pre_workflow_hooks is being used to generate atlantis.yaml and projects are set with specific workspaces different than "default", a different directory is created for each project-workspace pair, but all those that are not on the "default" workspace will not have an atlantis.yaml file at their root. This change ensures that when atlantis is building the projects commands for either: - a project-specific plan, triggered via (atlantis plan -d foo -w bar) - a project-specific apply, triggered vi (atlantis apply -d foo -w bar) - or applies for all the plans it can find (atlantis apply) it uses the default workspace to find the atlantis.yaml config.
9989ebe
to
ad22408
Compare
@msarvar thank you taking the time to review and approve. A rebase fixed the issue so it should be good to go |
…text (#1620) When pre_workflow_hooks is being used to generate atlantis.yaml and projects are set with specific workspaces different than "default", a different directory is created for each project-workspace pair, but all those that are not on the "default" workspace will not have an atlantis.yaml file at their root. This change ensures that when atlantis is building the projects commands for either: - a project-specific plan, triggered via (atlantis plan -d foo -w bar) - a project-specific apply, triggered vi (atlantis apply -d foo -w bar) - or applies for all the plans it can find (atlantis apply) it uses the default workspace to find the atlantis.yaml config. Co-authored-by: giuli007 <[email protected]>
Fixes #1612
When
pre_workflow_hooks
is being used to generateatlantis.yaml
and projects are set with specific workspaces different thandefault
, a different directory is created for each project-workspace pair, but all those that are not on thedefault
workspace will not have anatlantis.yaml
file at their root.As described in some details in #1612 (comment) this can lead to situations where atlantis tries to build commands without finding the
atlantis.yaml
even though it has correctly being generated in thedefault
workspace.The most obvious error is
when trying to
atlantis apply
.But there are also more subtle errors with
atlantis plan -d <projectdir> -w <workspacename>
oratlantis apply -d <projectdir> -w <workspacename>
where they don't throw errors but implicitly use the DefaultProjCfg which is not what the end user would expect.Note that this is a bit inconsistent because when autoplan,
atlantis plan
oratlantis apply -p
are used it all seem to work fine.I believe the issue lies in what
repoDir
parameter is passed to buildProjectCommandCtxFrom a bit of digging the invocations which cause issues are:
atlantis plan
andatlantis apply
with-d
and-w
parameters pass the non-default-workspace directories tobuildProjectCommandCtx
which fails to find andatlantis.yaml
and produces aDefaultProjCfg
insteadatlantis apply
uses PendingPlanFinder.Find to find directories with existing plans and pass them tobuildProjectCommandCtx
; since they don't have anatlantis.yaml
but atlantis can sometimes read the project name from the filename then this error is triggeredOn the contrary the following scenarios don't cause the issues mentioned above:
buildPlanAllCommands
(foratlantis plan
and autoplan) does not use the above function and always builds all commands using the default workspace and therefore doesn't cause any issueatlantis plan -p
andatlantis apply -p
invoke thebuildProjectPlanCommand
andbuildProjectApplyCommand
which both default to use the default workspace and thus pass a directory withatlantis.yaml
tobuildProjectCommandCtx
and also don't cause any issueThis change ensures that when atlantis is building the projects commands for either:
it uses the default workspace to find the atlantis.yaml config.
First time I dig into the Atlantis codebase so please let me know if the reasoning above makes sense.