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

Implement ConfigTree in approve plugin #12440

Closed
wants to merge 5 commits into from

Conversation

matthyx
Copy link
Contributor

@matthyx matthyx commented May 1, 2019

Fixes #9757
@cjwagner I couldn't make this work without encapsulating the config inside a config section... if you have any idea on how to make that work with json.RawMessage pls advise.

@k8s-ci-robot k8s-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label May 1, 2019
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. area/prow Issues or PRs related to prow sig/testing Categorizes an issue or PR as relevant to SIG Testing. labels May 1, 2019
@matthyx
Copy link
Contributor Author

matthyx commented May 1, 2019

Hmm, looks like I have to tweak func checkUnknownFields for the RawMessage parts...

Copy link
Contributor

@stevekuznetsov stevekuznetsov left a comment

Choose a reason for hiding this comment

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

I'm not sure I am the biggest fan of how this looks to use as a consumer and the loss of type safety. I wonder how complex the Go program would be to auto-generate a typed tree struct given a type?

prow/plugins.yaml Outdated Show resolved Hide resolved
prow/plugins/approve/approve_test.go Outdated Show resolved Hide resolved
prow/plugins/helpers.go Outdated Show resolved Hide resolved
@matthyx
Copy link
Contributor Author

matthyx commented May 1, 2019

I am not sure it's possible to generate types at runtime in Go...
I did try several approaches, but that one had the benefit of using generic methods for the get repo/org/branch and we get the default behavior of maps for merging.

@stevekuznetsov
Copy link
Contributor

stevekuznetsov commented May 1, 2019

Sorry, not at runtime but at compile time -- we can check in the generated code. Something like this: https://github.com/taylorchu/generic

The runtime/ast library is wonderful

@matthyx
Copy link
Contributor Author

matthyx commented May 1, 2019

But this is a bit against what @cjwagner was saying here: #9757 (comment)
Should we ask him?

@cjwagner
Copy link
Member

cjwagner commented May 2, 2019

Instead of having the leaf config struct type be json.RawMessage I was imagining we could use an interface:

type LeafConfig interface {
  MarshalJSON() ([]byte, error)
  UnmarshalJSON([]byte) error
  Apply(parent LeafConfig) (LeafConfig, error)
}

Concrete implementations of LeafConfig would have to use a type cast in the Apply function to convert parent to the concrete type and plugins would similarly have to cast to the concrete type when using the config, but that doesn't seem like a big deal. This pattern will also allow for flexible LeafConfig merging behavior so that we can do more than just have the child config overwrite the top level keys of the parent config (e.g. append slices together, merge maps, etc.).

I'd also be ok with Steve's suggestion, but I'd prefer to use the features go provides instead of code generation if possible.

@matthyx
Copy link
Contributor Author

matthyx commented May 2, 2019

Thanks, I will try my best :)

@stevekuznetsov
Copy link
Contributor

I'm pretty sure the ast package et al are provided by the language specifically to allow people to do what I mentioned. Does the interface you expected still require the FillConfig style call when we want to use the fields?

@cjwagner
Copy link
Member

cjwagner commented May 2, 2019

I'm pretty sure the ast package et al are provided by the language specifically to allow people to do what I mentioned.

I'm not familiar with that package and https://golang.org/pkg/go/ast/#pkg-examples doesn't really make it clear how we would use the package for these purposes. How would you use the ast package to define and merge the leaf configs?

Does the interface you expected still require the FillConfig style call when we want to use the fields?

No. I don't think that is even necessary with the current implementation. We can and should be applying the parent configs to child configs when the config is first loaded. We probably still want a getter func to retrieve the most specific config that is available given an org, repo, and branch (like we have for branch protection).

@stevekuznetsov
Copy link
Contributor

You generate code by building the AST then printing it -- that's what is used for all of the generated clients, conversions, deep-copies for k8s, etc.

If we have an interface-based approach that doesn't need the FillConfig step it seems reasonable, but I would like to see typed accessors and good validation on load as well if possible, so that downstream code doesn't touch interface{}

@cjwagner
Copy link
Member

cjwagner commented May 3, 2019

AST sounds cool and would likely provide the cleanest API, but I think the interface approach will be nearly as clean, will probably be simpler, and will allow for more flexible leaf config merging so thats what I'm leaning towards right now.
I'm totally ok with either approach though. The tradeoffs seem like they balance out.

@stevekuznetsov
Copy link
Contributor

Agreed -- the implementation in the PR today resolves the values at runtime and offloads that to the caller which I think is not the most clean implementation, but if we can get typed accessors and validation on config load I think the interface based approach would be perfect.

@matthyx matthyx force-pushed the config-lib branch 3 times, most recently from 1858660 to 5785601 Compare May 4, 2019 14:46
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 4, 2019
@matthyx
Copy link
Contributor Author

matthyx commented May 6, 2019

@cjwagner one question though... what type should I put in config.go for Approve?
This is the same issue I had faced before falling back to rawMessage.

If I put ConfigTree as it is now on my branch, I don't see how the unmarshaller will understand it contains some Approve structs, even if Approve implement LeafConfig interface?

It seems (I might be wrong) that somehow I have to declare all the chain ApproveConfigTree, ApproveOrg, ...
In that case I much prefer the code generation path :-/

@cjwagner
Copy link
Member

cjwagner commented May 8, 2019

If I put ConfigTree as it is now on my branch, I don't see how the unmarshaller will understand it contains some Approve structs, even if Approve implement LeafConfig interface?

Hmmm, we can't unmarshal into a nil interface, but we should be able to unmarshal into a populated interface variable since it implements Unmarshaller. I was thinking we could just populate the interfaces with the concrete type before unmarshalling to them, but that can't be easily done for the LeafConfigs that are stored as map values because we don't know which keys to specify concrete values for until after we have parsed.
I think our options are:

  1. Parse the maps without the leaf configs first to determine the extant keys, then specify concrete LeafConfig structs for each of the identified keys and reparse with the leaf configs included.
  2. Avoid using interfaces and define the full chain of structs like you described.
  3. Resort to code generation.

@stevekuznetsov
Copy link
Contributor

Generation is what makes k8s apimachinery work and honestly I think it's a bit scary up-front but the output is really simple -- reviewable Go code, etc. I think it might be our best bet here.

@matthyx
Copy link
Contributor Author

matthyx commented May 9, 2019

I will experiment, but it'll be later as I'm handling my KEP for 1.15 in priority...

@matthyx
Copy link
Contributor Author

matthyx commented Jun 4, 2019

I was thinking of trying with https://github.com/google/gvisor/blob/master/tools/go_generics/generics.go any thoughts?

@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 Oct 16, 2022
@matthyx
Copy link
Contributor Author

matthyx commented Oct 16, 2022

@BenTheElder I should present this work to the sig-testing meeting one day... to check if it still makes sense to modify the configuration format.
/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Oct 16, 2022
@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 Jan 14, 2023
@cblecker
Copy link
Member

/remove-lifecycle stale
/cc @MadhavJivrajani

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jan 15, 2023
@k8s-triage-robot
Copy link

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

This bot triages 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 PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this 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 Jul 4, 2023
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 15, 2023
@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

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-triage-robot
Copy link

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

This bot triages 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 PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle rotten
  • Close this 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 Jan 19, 2024
@k8s-triage-robot
Copy link

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

This bot triages 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 PR is closed

You can:

  • Reopen this PR with /reopen
  • Mark this 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 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 PR is closed

You can:

  • Reopen this PR with /reopen
  • Mark this 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.

@matthyx
Copy link
Contributor Author

matthyx commented Feb 18, 2024

/reopen
will rebase and merge once we move prow repo

@k8s-ci-robot k8s-ci-robot reopened this Feb 18, 2024
@k8s-ci-robot
Copy link
Contributor

@matthyx: Reopened this PR.

In response to this:

/reopen
will rebase and merge once we move prow repo

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
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: matthyx
Once this PR has been reviewed and has the lgtm label, please ask for approval from cjwagner. For more information see the Kubernetes Code Review Process.

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
Copy link
Contributor

@matthyx: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-test-infra-lint 0fb05cb link /test pull-test-infra-lint
pull-test-infra-verify-config 0fb05cb link /test pull-test-infra-verify-config
pull-test-infra-prow-checkconfig f45c923 link /test pull-test-infra-prow-checkconfig
pull-test-infra-misc-image-build-test b7bf1a2 link true /test pull-test-infra-misc-image-build-test

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.

@jihoon-seo
Copy link
Member

Hello @matthyx, the Prow source code has been moved to https://github.com/kubernetes-sigs/prow on April 9, 2024.
Please consider migrate this PR (by opening a new one in there).
Thanks!

@matthyx
Copy link
Contributor Author

matthyx commented Apr 16, 2024

Yes thanks for the reminder I'll do this soon

@matthyx
Copy link
Contributor Author

matthyx commented May 13, 2024

kubernetes-sigs/prow#147

@matthyx matthyx closed this May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/config Issues or PRs related to code in /config 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. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

prow config: where possible, all config should behave like branchprotector for overrides
10 participants