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: allow cli to remove cluster by name (#8814) #8823

Merged
merged 1 commit into from
Mar 28, 2022

Conversation

danielhelfand
Copy link
Contributor

Closes #8814

This pull request adds the ability to remove cluster credentials by cluster name. Previously, you could only remove clusters using the cluster server.

Checklist:

  • Either (a) I've created an enhancement proposal and discussed it with the community, (b) this is a bug fix, or (c) this does not need to be in the release notes.
  • The title of the PR states what changed and the related issues number (used for the release note).
  • I've included "Closes [ISSUE #]" or "Fixes [ISSUE #]" in the description to automatically close the associated issue.
  • I've updated both the CLI and UI to expose my feature, or I plan to submit a second PR with them.
  • Does this PR require documentation updates?
  • I've updated documentation as required by this PR.
  • Optional. My organization is added to USERS.md.
  • I have signed off all my commits as required by DCO
  • I have written unit and/or e2e tests for my change. PRs without these are unlikely to be merged.
  • My build is green (troubleshooting builds).

@codecov
Copy link

codecov bot commented Mar 18, 2022

Codecov Report

Merging #8823 (7112618) into master (c59b8ea) will increase coverage by 0.02%.
The diff coverage is 20.00%.

@@            Coverage Diff             @@
##           master    #8823      +/-   ##
==========================================
+ Coverage   43.30%   43.32%   +0.02%     
==========================================
  Files         186      186              
  Lines       23359    23371      +12     
==========================================
+ Hits        10116    10126      +10     
+ Misses      11797    11796       -1     
- Partials     1446     1449       +3     
Impacted Files Coverage Δ
cmd/argocd/commands/cluster.go 5.66% <0.00%> (-0.03%) ⬇️
server/cluster/cluster.go 29.95% <26.66%> (+3.25%) ⬆️

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 c59b8ea...7112618. Read the comment docs.

@pasha-codefresh pasha-codefresh self-requested a review March 18, 2022 19:30
util/db/cluster.go Outdated Show resolved Hide resolved
server/cluster/cluster.go Outdated Show resolved Hide resolved
server/cluster/cluster.go Outdated Show resolved Hide resolved
server/cluster/cluster.go Outdated Show resolved Hide resolved
@danielhelfand danielhelfand force-pushed the cluster-rm-name branch 4 times, most recently from 769d0a2 to 9bbfd57 Compare March 19, 2022 01:57
@pasha-codefresh
Copy link
Member

@danielhelfand i will recheck it during tomorrow, thank you

@danielhelfand danielhelfand force-pushed the cluster-rm-name branch 3 times, most recently from dc9c1e5 to bcc976b Compare March 23, 2022 02:26
alexmt
alexmt previously requested changes Mar 23, 2022
Copy link
Collaborator

@alexmt alexmt left a comment

Choose a reason for hiding this comment

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

Thank you for the improvement @danielhelfand ! Deletion by name is definitely useful.

I think there is an easier way to achieve it without making too many backend changes. We can change existing DeleteCluster API as following:

// Delete deletes a cluster by name
func (s *Server) Delete(ctx context.Context, q *cluster.ClusterQuery) (*cluster.ClusterResponse, error) {
	c, err := s.getClusterWith403IfNotExist(ctx, q)
	if err != nil {
		return nil, err
	}

	if q.Name != "" {
		servers, err := s.db.GetClusterServersByName(ctx, q.Name)
		if err != nil {
			return nil, err
		}
		for _, server := range servers {
			if err := s.enf.EnforceErr(ctx.Value("claims"), rbacpolicy.ResourceClusters, rbacpolicy.ActionDelete, createRBACObject(c.Project, c.Server)); err != nil {
				return nil, err
			}
			err = s.db.DeleteCluster(ctx, server)
			if err != nil {
				return nil, err
			}
		}
	} else {
		if err := s.enf.EnforceErr(ctx.Value("claims"), rbacpolicy.ResourceClusters, rbacpolicy.ActionDelete, createRBACObject(c.Project, c.Server)); err != nil {
			return nil, err
		}
		err = s.db.DeleteCluster(ctx, q.Server)
		if err != nil {
			return nil, err
		}
	}

	return &cluster.ClusterResponse{}, nil
}

WDYT?

@danielhelfand danielhelfand force-pushed the cluster-rm-name branch 4 times, most recently from 957dcde to 7b3c2ca Compare March 23, 2022 18:43
@danielhelfand
Copy link
Contributor Author

danielhelfand commented Mar 23, 2022

I think there is an easier way to achieve it without making too many backend changes. We can change existing DeleteCluster API as following:

@alexmt Thanks for taking a look. I agree that your suggestion of mapping the name to the server is cleaner. Only other change I made in addition is moving the tests to the cluster package. Let me know if there's anything else I can change.

@danielhelfand danielhelfand force-pushed the cluster-rm-name branch 2 times, most recently from 4572b85 to 190175e Compare March 23, 2022 20:20
Copy link
Member

@crenshaw-dev crenshaw-dev left a comment

Choose a reason for hiding this comment

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

@danielhelfand in test/e2e/fixture/cluster/actions.go there's a test called TestClusterListDenied. Would you be willing to mimic that test to verify that delete permissions are being enforced for both cluster names and cluster URLs? I wish there were a place to do it in unit tests instead of e2e, but not seeing anything at a glance.

If you're busy, I wouldn't consider that a requirement for this PR. Just a nice-to-have. :-)

@crenshaw-dev crenshaw-dev dismissed stale reviews from alexmt and pasha-codefresh March 25, 2022 17:59

out of date

@crenshaw-dev
Copy link
Member

Bleh I thought dismissing reviews would let me request a new review. @alexmt tagging works too I guess :-)

Copy link
Member

@crenshaw-dev crenshaw-dev left a comment

Choose a reason for hiding this comment

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

Requesting changes to wait for Alex to have another look.

@danielhelfand
Copy link
Contributor Author

@danielhelfand in test/e2e/fixture/cluster/actions.go there's a test called TestClusterListDenied. Would you be willing to mimic that test to verify that delete permissions are being enforced for both cluster names and cluster URLs? I wish there were a place to do it in unit tests instead of e2e, but not seeing anything at a glance.

If you're busy, I wouldn't consider that a requirement for this PR. Just a nice-to-have. :-)

This pr is by no means urgent, so happy to look into an additional test. Thanks for the suggestion @crenshaw-dev.

Copy link
Collaborator

@alexmt alexmt left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you @danielhelfand!

Let me know please if you want to add test, suggested by @crenshaw-dev or PR can be merged now.

@danielhelfand
Copy link
Contributor Author

@alexmt The test was added. Feel free to merge.

@alexmt
Copy link
Collaborator

alexmt commented Mar 28, 2022

Could not merge because PR @crenshaw-dev requested changes. @crenshaw-dev could you approve please ?

@pasha-codefresh
Copy link
Member

pasha-codefresh commented Mar 28, 2022

Im sorry for last minute request, could we please move this part to function and reuse it,

if err := s.enf.EnforceErr(ctx.Value("claims"), rbacpolicy.ResourceClusters, 
              rbacpolicy.ActionDelete,createRBACObject(c.Project, c.Server)); err != nil {
     return nil, err
}
err = s.db.DeleteCluster(ctx, server)
if err != nil {
     return nil, err
}

it can be internal function I think, not sure that it will be reused outside

@danielhelfand danielhelfand force-pushed the cluster-rm-name branch 3 times, most recently from bce80ac to d8ae6bb Compare March 28, 2022 16:07
@danielhelfand
Copy link
Contributor Author

Im sorry for last minute request, could we please move this part to function and reuse it,

@pasha-codefresh Done.

@danielhelfand
Copy link
Contributor Author

Not sure why, but it looks like there were some generated changes added to the manifests. Not exactly sure why as they do not look relevant to my changes.

@pasha-codefresh
Copy link
Member

You have force pushed changes from this commit bce80ac

you need to fix it :(

@danielhelfand danielhelfand force-pushed the cluster-rm-name branch 2 times, most recently from 5513eb1 to 2d28eef Compare March 28, 2022 17:08
@danielhelfand
Copy link
Contributor Author

The manifests on the master branch look like they were not generated so the build seems broken. I think I'll open a separate pr for that and try to rebase around it instead of adding here.

@alexmt
Copy link
Collaborator

alexmt commented Mar 28, 2022

@danielhelfand this is a broken process, not really related to your PR. Long term fix is here: #8864 .

@pasha-codefresh
Copy link
Member

Thank you @danielhelfand, looks good for me

Signed-off-by: Daniel Helfand <helfand.4@gmail.com>
@danielhelfand
Copy link
Contributor Author

Just rebased around fix on master. Feel free to merge once CI passes. Thanks for all the help everyone!

@alexmt alexmt merged commit f21336c into argoproj:master Mar 28, 2022
wojtekidd pushed a commit to wojtekidd/argo-cd that referenced this pull request Apr 25, 2022
Signed-off-by: Daniel Helfand <helfand.4@gmail.com>
Signed-off-by: wojtekidd <wojtek.cichon@protonmail.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.

cli: Use cluster name with argocd cluster rm
4 participants