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: enable full offline lint of all resource types #10059

Merged
merged 2 commits into from
Feb 13, 2023

Conversation

julienduchesne
Copy link
Contributor

@julienduchesne julienduchesne commented Nov 18, 2022

Currently, the offline linting only works for Workflow because other resources (WorkflowTemplate, ClusterWorkflowTemplate and CronWorkflow) can depend on references to other resources.
However, the “online” behavior that fetches refs from the server is also very limiting in a CI context where a user may modify both a "top-level" file and its dependencies at the same time. The dependencies are fetched from the server and the validation fails.

This PR extends the offline linter so that it uses the whole list of files passed as arguments in order to validate. If a ref needs to be resolved, the linter will search through the given files.
This is useful in a GitOps context where a user can pass the whole list of Argo files to the CI check.

Signed-off-by: Julien Duchesne julien.duchesne@grafana.com

  • Create the PR as draft .
  • Run make pre-commit -B to fix codegen and lint problems.
  • Sign-off your commits (otherwise the DCO check will fail).
  • Use a conventional commit message (otherwise the commit message check will fail).
  • "Fixes #" is in both the PR title (for release notes) and this description (to automatically link and close the issue).
  • Add unit or e2e tests. Say how you tested your changes. If you changed the UI, attach screenshots.
  • Github checks are green.
  • Once required tests have passed, mark your PR "Ready for review".

If changes were requested, and you've made them, dismiss the review to get it reviewed again.

@julienduchesne julienduchesne changed the title Enable full offline lint of all resources (feat) enable full offline lint of all resources Nov 18, 2022
@julienduchesne julienduchesne changed the title (feat) enable full offline lint of all resources feat: enable full offline lint of all resources Nov 18, 2022
@julienduchesne julienduchesne force-pushed the julienduchesne/offline-scanner branch 2 times, most recently from 8973fe4 to 1c6f498 Compare November 18, 2022 13:41
@julienduchesne julienduchesne marked this pull request as ready for review November 18, 2022 23:39
pkg/apiclient/apiclient.go Show resolved Hide resolved
@julienduchesne julienduchesne force-pushed the julienduchesne/offline-scanner branch 2 times, most recently from b31c2ec to 3eec7a6 Compare November 21, 2022 15:43
@@ -35,6 +35,9 @@ func NewLintCommand() *cobra.Command {
cat manifests.yaml | argo lint --kinds=workflows,cronworkflows -`,
Run: func(cmd *cobra.Command, args []string) {
client.Offline = offline
if offline {
client.OfflineFiles = args
Copy link
Contributor

Choose a reason for hiding this comment

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

I like the idea that all the files form a "linting context", do you even OfflineFiles?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean?

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 your contextual lint should be the default. No need to enable any flag. I think we can always do what line 39 does. This is always better and more correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed the condition. It doesn't make sense indeed. The OfflineFiles are only used when the "offline client" is used

@julienduchesne julienduchesne changed the title feat: enable full offline lint of all resources feat: enable full offline lint of all resource types Nov 21, 2022
cmd/argo/commands/lint.go Outdated Show resolved Hide resolved
cmd/argo/commands/client/conn.go Show resolved Hide resolved
@stale
Copy link

stale bot commented Dec 31, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is a mentoring request, please provide an update here. Thank you for your contributions.

@stale stale bot added problem/stale This has not had a response in some time and removed problem/stale This has not had a response in some time labels Dec 31, 2022
@stale
Copy link

stale bot commented Jan 21, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is a mentoring request, please provide an update here. Thank you for your contributions.

@stale stale bot added problem/stale This has not had a response in some time and removed problem/stale This has not had a response in some time labels Jan 21, 2023
Currently, the offline linting only works for Workflow because other resources (`WorkflowTemplate`, `ClusterWorkflowTemplate` and `CronWorkflow`) can depend on references to other resources.
However, this behavior is very limiting in a CI context where a user may modify both a "top-level" file and its dependencies at the same time. The dependencies are fetched from the server and the validation fails.

This PR extends the offline linter so that it uses the whole list of files passed as arguments in order to validate.
This is useful in a GitOps context where a user can pass the whole list of Argo files to the CI check.

Signed-off-by: Julien Duchesne <julien.duchesne@grafana.com>
Signed-off-by: Julien Duchesne <julien.duchesne@grafana.com>
@julienduchesne
Copy link
Contributor Author

Hey @alexec. Any chance I could get another review of this? This would greatly improve performance, reliability and usefulness of the linter for us

Copy link
Contributor

@alexec alexec left a comment

Choose a reason for hiding this comment

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

I approve of these changes. @juliev0 do you want to review? If not, we can merge.

@juliev0
Copy link
Contributor

juliev0 commented Feb 12, 2023

I approve of these changes. @juliev0 do you want to review? If not, we can merge.

My feeling is that in the interest of moving more PRs along, if you find a PR you approve of, go ahead and merge it? (but if it's in an area of the code I've worked in, I'm definitely happy to review it first)

@alexec alexec added this pull request to the merge queue Feb 13, 2023
@alexec alexec removed this pull request from the merge queue due to a manual request Feb 13, 2023
@alexec alexec merged commit 43766ca into argoproj:master Feb 13, 2023
julienduchesne added a commit to julienduchesne/argo-workflows that referenced this pull request Feb 21, 2023
argoproj#10059 was tested in very specific cases it seems because a couple things are wrong:
- Linting directories does not work anymore
- Resolving references in a namespace which doesn't show up in the given args, panics

In this PR, I fix those issues but I also add functional tests that checks that all of these cases work from the cmd level
I did not add to the `argo/lint/lint_test.go` tests and instead put the tests earlier down the line because the current tests do not cover the creation and configuration of the offline client

Signed-off-by: Julien Duchesne <julien.duchesne@grafana.com>
julienduchesne added a commit to julienduchesne/argo-workflows that referenced this pull request Feb 21, 2023
argoproj#10059 was tested in very specific cases it seems because a couple things are wrong:
- Linting directories does not work anymore
- Resolving references in a namespace which doesn't show up in the given args, panics

In this PR, I fix those issues but I also add functional tests that checks that all of these cases work from the cmd level
I did not add to the `argo/lint/lint_test.go` tests and instead put the tests earlier down the line because the current tests do not cover the creation and configuration of the offline client

Signed-off-by: Julien Duchesne <julien.duchesne@grafana.com>
julienduchesne added a commit to julienduchesne/argo-workflows that referenced this pull request Feb 21, 2023
argoproj#10059 was tested in very specific cases it seems because a couple things are wrong:
- Linting directories does not work anymore
- Resolving references in a namespace which doesn't show up in the given args, panics

In this PR, I fix those issues but I also add functional tests that checks that all of these cases work from the cmd level
I did not add to the `argo/lint/lint_test.go` tests and instead put the tests earlier down the line because the current tests do not cover the creation and configuration of the offline client

Signed-off-by: Julien Duchesne <julien.duchesne@grafana.com>
julienduchesne added a commit to julienduchesne/argo-workflows that referenced this pull request Feb 21, 2023
argoproj#10059 was tested in very specific cases it seems because a couple things are wrong:
- Linting directories does not work anymore
- Resolving references in a namespace which doesn't show up in the given args, panics

In this PR, I fix those issues but I also add functional tests that checks that all of these cases work from the cmd level
I did not add to the `argo/lint/lint_test.go` tests and instead put the tests earlier down the line because the current tests do not cover the creation and configuration of the offline client

Signed-off-by: Julien Duchesne <julien.duchesne@grafana.com>
julienduchesne added a commit to julienduchesne/argo-workflows that referenced this pull request Feb 21, 2023
argoproj#10059 was tested in very specific cases it seems because a couple things are wrong:
- Linting directories does not work anymore
- Resolving references in a namespace which doesn't show up in the given args, panics

In this PR, I fix those issues but I also add functional tests that checks that all of these cases work from the cmd level
I did not add to the `argo/lint/lint_test.go` tests and instead put the tests earlier down the line because the current tests do not cover the creation and configuration of the offline client

Signed-off-by: Julien Duchesne <julien.duchesne@grafana.com>
julienduchesne added a commit to julienduchesne/argo-workflows that referenced this pull request Feb 22, 2023
argoproj#10059 was tested in very specific cases it seems because a couple things are wrong:
- Linting directories does not work anymore
- Resolving references in a namespace which doesn't show up in the given args, panics

In this PR, I fix those issues but I also add functional tests that checks that all of these cases work from the cmd level
I did not add to the `argo/lint/lint_test.go` tests and instead put the tests earlier down the line because the current tests do not cover the creation and configuration of the offline client

Signed-off-by: Julien Duchesne <julien.duchesne@grafana.com>
julienduchesne added a commit to julienduchesne/argo-workflows that referenced this pull request Feb 22, 2023
argoproj#10059 was tested in very specific cases it seems because a couple things are wrong:
- Linting directories does not work anymore
- Resolving references in a namespace which doesn't show up in the given args, panics

In this PR, I fix those issues but I also add functional tests that checks that all of these cases work from the cmd level
I did not add to the `argo/lint/lint_test.go` tests and instead put the tests earlier down the line because the current tests do not cover the creation and configuration of the offline client

Signed-off-by: Julien Duchesne <julien.duchesne@grafana.com>
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.

3 participants