-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
769d0a2
to
9bbfd57
Compare
@danielhelfand i will recheck it during tomorrow, thank you |
dc9c1e5
to
bcc976b
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.
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?
957dcde
to
7b3c2ca
Compare
@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. |
4572b85
to
190175e
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.
@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. :-)
out of date
Bleh I thought dismissing reviews would let me request a new review. @alexmt tagging works too I guess :-) |
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.
Requesting changes to wait for Alex to have another look.
This pr is by no means urgent, so happy to look into an additional test. Thanks for the suggestion @crenshaw-dev. |
190175e
to
a1bbd30
Compare
a1bbd30
to
2ac33fd
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.
LGTM. Thank you @danielhelfand!
Let me know please if you want to add test, suggested by @crenshaw-dev or PR can be merged now.
@alexmt The test was added. Feel free to merge. |
Could not merge because PR @crenshaw-dev requested changes. @crenshaw-dev could you approve please ? |
Im sorry for last minute request, could we please move this part to function and reuse it,
it can be internal function I think, not sure that it will be reused outside |
bce80ac
to
d8ae6bb
Compare
@pasha-codefresh Done. |
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. |
You have force pushed changes from this commit bce80ac you need to fix it :( |
5513eb1
to
2d28eef
Compare
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. |
@danielhelfand this is a broken process, not really related to your PR. Long term fix is here: #8864 . |
Thank you @danielhelfand, looks good for me |
Signed-off-by: Daniel Helfand <helfand.4@gmail.com>
2d28eef
to
7112618
Compare
Just rebased around fix on master. Feel free to merge once CI passes. Thanks for all the help everyone! |
Signed-off-by: Daniel Helfand <helfand.4@gmail.com> Signed-off-by: wojtekidd <wojtek.cichon@protonmail.com>
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: