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

Add remove-members helper tool implemented in go #2575

Closed
wants to merge 15 commits into from

Conversation

daemon1024
Copy link

@daemon1024 daemon1024 commented Mar 15, 2021

Fixes #2052

This tool is implementation of the bash script in go with a few changes like using flags instead of environment variables

This currently resides in the hacks folder which I believe is not the right place, let me know where I should move this to and if it deserves it's own package

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 15, 2021
@k8s-ci-robot
Copy link
Contributor

Welcome @daemon1024!

It looks like this is your first PR to kubernetes/org 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/org has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Contributor

Hi @daemon1024. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. area/github-management Issues or PRs related to GitHub Management subproject labels Mar 15, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: daemon1024
To complete the pull request process, please assign spiffxp after the PR has been reviewed.
You can assign the PR to them by writing /assign @spiffxp in a comment when ready.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 15, 2021
@palnabarun
Copy link
Member

/cc

Copy link
Member

@nikhita nikhita left a comment

Choose a reason for hiding this comment

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

@daemon1024 thanks for creating the PR for this!

Left some suggestions, but looks great overall! 🎉

Can you also add a test for this?

hack/remove-members.go Outdated Show resolved Hide resolved
hack/remove-members.go Outdated Show resolved Hide resolved
hack/remove-members.go Outdated Show resolved Hide resolved
hack/remove-members.go Outdated Show resolved Hide resolved

//readMemberList reads the list of members to be removed from the given filepath
func readMemberList(path string) ([]string, error) {
file, err := os.Open(path)
Copy link
Member

Choose a reason for hiding this comment

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

@mrbobbytables is the inactive member list a yaml file? how is that generated?

Copy link
Member

Choose a reason for hiding this comment

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

It's been a text file with 1 member per line. The list is generated from this sheet after some manual vetting: https://docs.google.com/spreadsheets/d/1jqxMOo9f1EG72i4sGE7g6RlNPvQ4_qfOx9K-UM4YsLw/edit

Copy link
Member

Choose a reason for hiding this comment

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

Thanks! One more follow up question - how does one generate this sheet?

Want to remove you as a single point of failure :)

Copy link
Member

Choose a reason for hiding this comment

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

The big stuff to regen it are in the notes tab in the sheet 👍 I thought it was owned/under the sig contribex shared dir, but it looks like I'm the only owner atm. I'll move it over in a bit.

hack/remove-members.go Outdated Show resolved Hide resolved
for _, member := range memberList {
var orgs, teams []string
count := 0
fmt.Print(member)
Copy link
Member

Choose a reason for hiding this comment

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

would be better to log here and a more descriptive log message

Copy link
Author

@daemon1024 daemon1024 Mar 16, 2021

Choose a reason for hiding this comment

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

Should I change all instances of fmt to log?

Currently the output looks like

~/P/o/hack (remove-members-tool|…) ❯❯❯  go run remove-members.go -path=../config/kubernetes members.txt
nikhita
 Orgs: [kubernetes]
 Teams: [sig-contributor-experience sig-release]
 Number of occurences: 3

Commit Command: "commit -m Remove nikhita from the kubernetes org -m Remove nikhita from sig-contributor-experience, sig-release teams"

daemon1024
 Orgs: []
 Teams: []
 Number of occurences: 0

P.s. I don't really want to remove you 😝 just for showing the output 😹

Copy link
Member

Choose a reason for hiding this comment

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

I think fmt is also ok, but would be good to use a more descriptive message :)


re := regexp.MustCompile(`(\s+)?- ` + member + `(.*)?`)

if re.Match(content) {
Copy link
Member

Choose a reason for hiding this comment

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

we can probably count how many times member occurs in the path and return the count. This will ensure that count is accurate.

Copy link
Author

Choose a reason for hiding this comment

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

Do you mean to count the number of matches in the said file?

Copy link
Member

Choose a reason for hiding this comment

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

Do you mean to count the number of matches in the said file?

Yeah :)

Copy link
Member

Choose a reason for hiding this comment

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

Not a blocker for this, but potentially something in the future. We can marshal/unmarshal yaml while leaving the comments (go-yaml/yaml#132). This would also let us get team names directly.

Copy link
Member

Choose a reason for hiding this comment

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

@mrbobbytables -- I had a dig at this earlier by parsing the org files using k8s.io/test-infra/prow/config/org.Config, but there seemed to be something off there.

The processed org config when written back to disk had a lot of diff compared to the original file.

We can possibly dig deeper into it later.

Copy link
Member

Choose a reason for hiding this comment

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

It's been a bit since I looked at it , but potentially whitespace =/ since yaml supports some fuzzy inclusion:

foo:
  - bar

is the same as:

foo:
- bar

Theres what people have written (both formats) and what go will want to format it as.

Copy link
Member

Choose a reason for hiding this comment

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

That as well. we may want to bite the bullet with a big initial diff as the subsequent updates should be deterministic .

One other thing was, in order to process comments, the structs in k8s.io/test-infra/prow/config/org.Config should have fields with yaml.Node as field type and then have post-processing helper method. I had taken a step back because of that complexity.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, what I'd probably do at that point is get away from editing by hand, and then have an add-member function or have a make command that ensures proper formatting before commit. Out of scope for this one though^^;;;

Copy link
Member

Choose a reason for hiding this comment

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

@mrbobbytables -- that's (adding members) what I was trying to automate. 😉

But, yes. Let's talk about this in a separate thread.

Copy link
Author

Choose a reason for hiding this comment

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

Adding to whitespaces and comments related changes, The substantial amount of diff is also created due to the difference in order of the yaml properties.
I was trying to parse the yaml files and removing members in a more structured way, I also faced this.

diff --git a/config/kubernetes-incubator/org.yaml b/config/kubernetes-incubator/org.yaml
index baf4ca76..e2da8a87 100644
--- a/config/kubernetes-incubator/org.yaml
+++ b/config/kubernetes-incubator/org.yaml
@@ -1,10 +1,3 @@
-name: Kubernetes Incubator
-description: Kubernetes Incubator
-default_repository_permission: read
-has_organization_projects: true
-has_repository_projects: true
-members_can_create_repositories: false
-billing_email: [email protected]
 admins:
 - cblecker
 - fejta
@@ -15,3 +8,10 @@ admins:
 - nikhita
 - spiffxp
 - thelinuxfoundation
+billing_email: [email protected]
+default_repository_permission: read
+description: Kubernetes Incubator
+has_organization_projects: true
+has_repository_projects: true
+members_can_create_repositories: false
+name: Kubernetes Incubator

It seems to be sorting the fields.

I currently implemented this using kubernetes-sigs/yaml.

@nikhita
Copy link
Member

nikhita commented Mar 16, 2021

/uncc @idvoretskyi
/cc @mrbobbytables @cblecker

@k8s-ci-robot k8s-ci-robot requested review from cblecker and mrbobbytables and removed request for idvoretskyi March 16, 2021 07:51
@daemon1024
Copy link
Author

Can you also add a test for this?

Would it be fine to add some test .yaml files cause it wouldn't be right to perform tests on the actual files. Or should we work with TempFile


func main() {
flag.StringVar(&configPath, "path", ".", "Path to config directory/subdirectory")
flag.BoolVar(&dryrun, "dryrun", true, "Enable Dryrun or not. This flag controls whether the changes are simulated or live. If the changes are simulated it will only print the removal details and the commit message")
Copy link
Member

Choose a reason for hiding this comment

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

@mrbobbytables for feedback on the help text

Copy link
Member

Choose a reason for hiding this comment

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

It could probably be simplified down to something like: Simulates changes to be applied and prints removal details

flag.Parse()

flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: remove-members [flags] <file-containing-members-list>\n")
Copy link
Member

Choose a reason for hiding this comment

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

would be good to list out the flags here. http://courses.cms.caltech.edu/cs11/material/general/usage.html has some details on the format

Copy link
Author

Choose a reason for hiding this comment

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

Usage: remove-members [-dryrun] [-path] member-file (file-containing-members-list)

Is this fine?

@nikhita
Copy link
Member

nikhita commented Mar 16, 2021

Would it be fine to add some test .yaml files cause it wouldn't be right to perform tests on the actual files. Or should we work with TempFile

It would be fine to add test yaml files 👍

hack/remove-members.go Outdated Show resolved Hide resolved
Comment on lines 48 to 61
func readMemberList(path string) ([]string, error) {
file, err := os.Open(path)
if err != nil {
return nil, err
}
defer file.Close()

var members []string
scanner := bufio.NewScanner(file)
for scanner.Scan() {
members = append(members, scanner.Text())
}
return members, scanner.Err()
}
Copy link
Member

Choose a reason for hiding this comment

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

How about simplifying this using ioutil.ReadFile as used in removeMemberFromFile?

Note: ioutil.ReadFile has been deprecated in Go 1.16 although it shouldn't be a blocker since this repository still uses Go 1.13.

hack/remove-members.go Outdated Show resolved Hide resolved
* use pflags
* use iouyil instead of bufio for reading member list
* preserve filemode after removals
@daemon1024
Copy link
Author

daemon1024 commented Mar 17, 2021

Should I move this to a new directory? ( helpers/remove-members maybe? )

Since I added an external package it seems to adding it to the go.mod at the root, I haven't committed it yet cause I am not sure if this a part of that or should I initiate a separate go.mod for this.

@k8s-ci-robot
Copy link
Contributor

@daemon1024: The following tests failed, say /retest to rerun all failed tests:

Test name Commit Details Rerun command
pull-org-test-all 686abd3 link /test pull-org-test-all
pull-org-verify-all 686abd3 link /test pull-org-verify-all

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jun 23, 2021
//removeMembers walks through the config directory and removes the occurences of the given member name
func removeMembers(memberList []string, o options) error {
for _, member := range memberList {
var orgs, teams []string
Copy link

@shamsher31 shamsher31 Jul 9, 2021

Choose a reason for hiding this comment

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

This will redeclare orgs and teams with each iteration, better to move it outside of for loop.


matches := re.FindAllIndex(content, -1)

//Making Sure count from parsed config and regex matches are same
Copy link

@shamsher31 shamsher31 Jul 9, 2021

Choose a reason for hiding this comment

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

Suggested change
//Making Sure count from parsed config and regex matches are same
// Making sure count from parsed config and regex matches are the same

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Aug 8, 2021
@mrbobbytables
Copy link
Member

/remove-lifecycle rotten

@k8s-ci-robot k8s-ci-robot removed the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label Aug 8, 2021
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Nov 6, 2021
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Dec 6, 2021
@mrbobbytables
Copy link
Member

/remove-lifecycle rotten

/cc @palnabarun
was this going to be integrated into your helper?

@k8s-ci-robot k8s-ci-robot removed the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label Dec 6, 2021
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Mar 6, 2022
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Apr 5, 2022
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue or PR with /reopen
  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close

@k8s-ci-robot
Copy link
Contributor

@k8s-triage-robot: Closed this PR.

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue or PR with /reopen
  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/github-management Issues or PRs related to GitHub Management subproject cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create tool for removing org members
9 participants