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: add PreservedBranches config for branchcleaner to preserve branches #23735

Merged

Conversation

Colstuwjx
Copy link
Contributor

Fixed #23732.

@k8s-ci-robot
Copy link
Contributor

Welcome @Colstuwjx!

It looks like this is your first PR to kubernetes/test-infra 🎉. 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/test-infra 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 @Colstuwjx. 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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. area/prow Issues or PRs related to prow area/prow/plugins Issues or PRs related to prow's plugins for the hook component sig/testing Categorizes an issue or PR as relevant to SIG Testing. labels Sep 24, 2021
Copy link
Member

@petr-muller petr-muller left a comment

Choose a reason for hiding this comment

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

/ok-to-test

One concern is that the PR implements a global set of branches, but branch names are per-repo entities, so I think this config should allow per-repo (and possibly per-org) configuration.

prow/plugins/config.go Outdated Show resolved Hide resolved
prow/plugins/config.go Outdated Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Sep 27, 2021
@Colstuwjx
Copy link
Contributor Author

One concern is that the PR implements a global set of branches, but branch names are per-repo entities, so I think this config should allow per-repo (and possibly per-org) configuration.

OK, I'll change it.

@Colstuwjx
Copy link
Contributor Author

One concern is that the PR implements a global set of branches, but branch names are per-repo entities, so I think this config should allow per-repo (and possibly per-org) configuration.

I've change to map[string][]string, and it allows per-repo or per-org configuration.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 8, 2021
@Colstuwjx
Copy link
Contributor Author

@petr-muller Could you help me clarify the CI issue, I don't know how to fix the bazel issue...

@petr-muller
Copy link
Member

Looks like a bunch of generated content needs to be updated:

https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/test-infra/23735/pull-test-infra-bazel/1446405683212718080#1:build-log.txt%3A6633

ERROR: bazel rules out of date. Fix with:
  bazel run @io_k8s_repo_infra//hack:update-bazel 

https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/test-infra/23735/pull-test-infra-bazel/1446405683212718080#1:build-log.txt%3A6856

ERROR: modules changed. Fix with:
  bazel run @io_k8s_repo_infra//hack:update-deps 

https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/test-infra/23735/pull-test-infra-bazel/1446405683212718080#1:build-log.txt%3A6879

         If this is expected, re-run the tests with the UPDATE env var set to update the fixture:
        	UPDATE=true go test ./prow/plugins/... -run TestGenYamlDocs 

@Colstuwjx
Copy link
Contributor Author

Looks like a bunch of generated content needs to be updated:

Yes, I've been tried to fix it, but it seems doesn't work:

(testinfradev) ➜  test-infra git:(prow-branchcleaner-protect-branches) ./hack/update-bazel.sh
INFO: Repository py_deps instantiated at:
  no stack (--record_rule_instantiation_callstack not enabled)
Repository rule pip_import defined at:
  /private/var/tmp/_bazel_user/eb2106dd05673888d179bfdf510c291b/external/rules_python/python/pip.bzl:44:29: in <toplevel>
ERROR: An error occurred during the fetch of repository 'py_deps':
   pip_import failed:  (Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/private/var/tmp/_bazel_user/eb2106dd05673888d179bfdf510c291b/external/rules_python/tools/piptool.par/__main__.py", line 66, in <module>
  File "/private/var/tmp/_bazel_user/eb2106dd05673888d179bfdf510c291b/external/rules_python/tools/piptool.par/__main__.py", line 45, in extract_packages
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 1286, in set_extraction_path
    "Can't change extraction path, files already extracted"
ValueError: Can't change extraction path, files already extracted
)
ERROR: no such package '@py_deps//': pip_import failed:  (Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/private/var/tmp/_bazel_user/eb2106dd05673888d179bfdf510c291b/external/rules_python/tools/piptool.par/__main__.py", line 66, in <module>
  File "/private/var/tmp/_bazel_user/eb2106dd05673888d179bfdf510c291b/external/rules_python/tools/piptool.par/__main__.py", line 45, in extract_packages
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 1286, in set_extraction_path
    "Can't change extraction path, files already extracted"
ValueError: Can't change extraction path, files already extracted
)
INFO: Elapsed time: 18.586s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded)
FAILED: Build did NOT complete successfully (0 packages loaded)

@Colstuwjx Colstuwjx changed the title feat: add ProtectedBranches config for branchcleaner to protect branches feat: add PreservedBranches config for branchcleaner to preserve branches Oct 12, 2021
@Colstuwjx
Copy link
Contributor Author

Update: I've been installed python27 on macOS, and alias it with alias python="/usr/local/bin/python2", now it throws an new error:

INFO: Analyzed target @io_k8s_repo_infra//hack:update-bazel (1 packages loaded, 348 targets configured).
INFO: Found 1 target...
ERROR: /private/var/tmp/_bazel_user/eb2106dd05673888d179bfdf510c291b/external/com_google_protobuf/BUILD:120:11: C++ compilation of rule '@com_google_protobuf//:protobuf_lite' failed (Exit 1) cc_wrapper.sh failed: error executing command external/local_config_cc/cc_wrapper.sh -U_FORTIFY_SOURCE -fstack-protector -Wall -Wthread-safety -Wself-assign -fcolor-diagnostics -fno-omit-frame-pointer -g0 -O2 '-D_FORTIFY_SOURCE=1' -DNDEBUG ... (remaining 33 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
external/com_google_protobuf/src/google/protobuf/any_lite.cc:56:14: error: non-constexpr declaration of 'AnyMetadata' follows constexpr declaration
AnyMetadata::AnyMetadata(UrlType* type_url, ValueType* value)
             ^
/usr/local/include/google/protobuf/any.h:63:13: note: previous declaration is here
  constexpr AnyMetadata(UrlType* type_url, ValueType* value)
            ^
external/com_google_protobuf/src/google/protobuf/any_lite.cc:59:19: error: return type of out-of-line definition of 'google::protobuf::internal::AnyMetadata::InternalPackFrom' differs from that in the declaration
void AnyMetadata::InternalPackFrom(const MessageLite& message,
~~~~              ^
/usr/local/include/google/protobuf/any.h:111:8: note: previous declaration is here
  bool InternalPackFrom(const MessageLite& message,
  ~~~~ ^
external/com_google_protobuf/src/google/protobuf/any_lite.cc:62:14: error: no member named 'SetNoArena' in 'google::protobuf::internal::ArenaStringPtr'
  type_url_->SetNoArena(&::google::protobuf::internal::GetEmptyString(),
  ~~~~~~~~~  ^
external/com_google_protobuf/src/google/protobuf/any_lite.cc:64:37: error: no member named 'MutableNoArena' in 'google::protobuf::internal::ArenaStringPtr'
  message.SerializeToString(value_->MutableNoArena(
                            ~~~~~~  ^
external/com_google_protobuf/src/google/protobuf/any_lite.cc:73:43: error: no member named 'GetNoArena' in 'google::protobuf::internal::ArenaStringPtr'
  return message->ParseFromString(value_->GetNoArena());
                                  ~~~~~~  ^
external/com_google_protobuf/src/google/protobuf/any_lite.cc:91:15: error: no member named 'GetNoArena' in 'google::protobuf::internal::ArenaStringPtr'
  return ptr->GetNoArena();
         ~~~  ^
6 errors generated.
Target @io_k8s_repo_infra//hack:update-bazel failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 2.858s, Critical Path: 2.54s
INFO: 0 processes.
FAILED: Build did NOT complete successfully
FAILED: Build did NOT complete successfully

I have no idea about how to fix this issue..

@Colstuwjx
Copy link
Contributor Author

Hi @petr-muller

Thanks for your reminder, I've met issue protobuf 5376 and I've fixed it.

Now it's ready for review, PTAL!

Copy link
Member

@petr-muller petr-muller left a comment

Choose a reason for hiding this comment

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

Last thing, then I think this looks good!

prow/plugins/config.go Outdated Show resolved Hide resolved
@Colstuwjx
Copy link
Contributor Author

@petr-muller Updated! PTAL!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 14, 2021
@Colstuwjx
Copy link
Contributor Author

/cc @cjwagner @stevekuznetsov Could you help me review this PR? Many thanks!!!

Copy link
Member

@cjwagner cjwagner left a comment

Choose a reason for hiding this comment

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

Looks good to me, but please also update the PluginHelp information for the plugin now that it is configurable.

Comment on lines 1812 to 1818
if _, existsRepo := b.PreservedBranches[fullRepoName]; existsRepo {
for _, pb := range b.PreservedBranches[fullRepoName] {
if branch == pb {
return true
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

nit: Go makes it safe to iterate over nil slices. So both of the repo check and the org check can drop the outer conditional.

Suggested change
if _, existsRepo := b.PreservedBranches[fullRepoName]; existsRepo {
for _, pb := range b.PreservedBranches[fullRepoName] {
if branch == pb {
return true
}
}
}
for _, pb := range b.PreservedBranches[fullRepoName] {
if branch == pb {
return true
}
}

@@ -41,26 +41,31 @@ func helpProvider(config *plugins.Configuration, _ []config.OrgRepo) (*pluginhel
}
Copy link
Member

Choose a reason for hiding this comment

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

Please also update the helpProvider to include include Config now that this plugin has configurable behavior. e.g.
and consider adding the YAML config snippet like this:

yamlSnippet, err := plugins.CommentMap.GenYaml(&plugins.Configuration{
Retitle: plugins.Retitle{
AllowClosedIssues: true,
},
})
if err != nil {
logrus.WithError(err).Warnf("cannot generate comments for %s plugin", pluginName)
}

Full details about PluginHelp.

Copy link
Contributor Author

@Colstuwjx Colstuwjx Oct 19, 2021

Choose a reason for hiding this comment

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

Thanks for explanation. I've been tried to change the plugin helper content, but I found the prow/plugins/plugin-config-documented.yaml didn't change.

What's more, I have two confusions after you clarified the plugin help:

  1. BranchCleaner is a passive plugin and don't give comment command, rather than lgtm or retitle, and I'm confused about how it could be configured, there are two styles of configuration formats:
# format 1
triggers:
  - repos:
      - org_a
  - repos:
      - org_a/repo_a1
    only_org_members: true

# format 2
plugins:
  org_a:
    plugins:
      - approve # Allow OWNERS to /approve

We can see, format 1 is static config, and it could set different config options for each org/repo set. And format 2 is a list of plugins, and each org/repo has a list of configured plugins with their config options. In format 2, it seems a little-bit redundant if we set map[repo]config inside the list, e.g.

plugins:
  org_a:
    plugins:
      - branch_cleaner:
           preserved_branches:
             "org_a": ["master"]
             "org_a/repo_a1": ["master"]

The nested configuration looks so bad, right? I'm wondering if we need to change the config.BranchCleaner config struct, and turn to use format 1. I'm also confused about these two formats, which one is suitable to BranchCleaner such plugin, why?

  1. As I mentioned, I've been tried UPDATE=true go test ./prow/plugins/... -run TestGenYamlDocs and the yaml content didn't change. So what's the process to update and plugin helper and its document yaml ? Besides the annotations you given, I can't find any document about this process :(

Could you help me clarify these confusions?
Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

I've been tried to change the plugin helper content, but I found the prow/plugins/plugin-config-documented.yaml didn't change.

It is not expected to, that file is generated based on an empty plugins.Configuration struct and doesn't involve PluginHelp.
PluginHelp information is displayed via Prow's front end. Try clicking on the "Details" button for the "Approve" plugin card on this page to see an example of the configuration section and the example snippet section. https://prow.k8s.io/plugins?repo=kubernetes%2Ftest-infra Notice that the configuration section depends on the repo selected, but the snippet is just a static example.

  1. BranchCleaner is a passive plugin and don't give comment command, rather than lgtm or retitle, and I'm confused about how it could be configured, there are two styles of configuration formats

Passive plugins can have configuration, the addition you made to the plugins.Configuration struct is exactly what I'm talking about. The configuration format you already added looks good and is consistent with other plugin configurations, so no need to change it.

# branches in this allow map would be exempt from branch gc
# even if the branches are already merged into the target branch
preserved_branches:
"": null
Copy link
Member

Choose a reason for hiding this comment

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

Populating the PluginHelp.Snippet field as I mentioned in the other comment will result in a commented version of the YAML config like this, but with the currently configured values.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, this was confusing and not quite accurate. I didn't mean to suggest that this file would update, just that the commented config snippet would look similar to this due to being generated with the same mechanism. I was wrong about the config snippet showing the currently configured values, it should just be a static example config.

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 19, 2021
Copy link
Member

@cjwagner cjwagner left a comment

Choose a reason for hiding this comment

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

Thanks for adding the PluginHelp info!

# branches in this allow map would be exempt from branch gc
# even if the branches are already merged into the target branch
preserved_branches:
"": null
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, this was confusing and not quite accurate. I didn't mean to suggest that this file would update, just that the commented config snippet would look similar to this due to being generated with the same mechanism. I was wrong about the config snippet showing the currently configured values, it should just be a static example config.

@@ -41,26 +41,31 @@ func helpProvider(config *plugins.Configuration, _ []config.OrgRepo) (*pluginhel
}
Copy link
Member

Choose a reason for hiding this comment

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

I've been tried to change the plugin helper content, but I found the prow/plugins/plugin-config-documented.yaml didn't change.

It is not expected to, that file is generated based on an empty plugins.Configuration struct and doesn't involve PluginHelp.
PluginHelp information is displayed via Prow's front end. Try clicking on the "Details" button for the "Approve" plugin card on this page to see an example of the configuration section and the example snippet section. https://prow.k8s.io/plugins?repo=kubernetes%2Ftest-infra Notice that the configuration section depends on the repo selected, but the snippet is just a static example.

  1. BranchCleaner is a passive plugin and don't give comment command, rather than lgtm or retitle, and I'm confused about how it could be configured, there are two styles of configuration formats

Passive plugins can have configuration, the addition you made to the plugins.Configuration struct is exactly what I'm talking about. The configuration format you already added looks good and is consistent with other plugin configurations, so no need to change it.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 19, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cjwagner, Colstuwjx, petr-muller

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

The pull request process is described 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 approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 19, 2021
@k8s-ci-robot k8s-ci-robot merged commit b0788a9 into kubernetes:master Oct 19, 2021
@k8s-ci-robot k8s-ci-robot added this to the v1.23 milestone Oct 19, 2021
@Colstuwjx Colstuwjx deleted the prow-branchcleaner-protect-branches branch October 19, 2021 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/prow/plugins Issues or PRs related to prow's plugins for the hook component area/prow Issues or PRs related to prow cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. sig/testing Categorizes an issue or PR as relevant to SIG Testing. 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.

Prow: branchcleaner should support filter with source branch
4 participants