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 setter by reflection #8896

Merged
merged 1 commit into from
Aug 30, 2020
Merged

Conversation

justinsb
Copy link
Member

@justinsb justinsb commented Apr 10, 2020

This means we no longer have to individually hard-code the kops set fields, however we use the "language" we're now demonstrated.

We add tests to ensure we have parity with our existing (hard-coded) setter logic.

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 10, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: justinsb

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 Apr 10, 2020
@justinsb justinsb added this to the v1.19 milestone Apr 10, 2020
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 17, 2020
@justinsb justinsb force-pushed the reflect_set branch 5 times, most recently from ffd3037 to 27ed901 Compare August 16, 2020 15:26
@justinsb justinsb changed the title WIP: Implement setter by reflection Implement setter by reflection Aug 16, 2020
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 16, 2020
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Aug 16, 2020
@justinsb
Copy link
Member Author

Removing WIP, this seems to work and I wish we had this e.g. when I was testing CoreDNS!

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Aug 28, 2020
@justinsb
Copy link
Member Author

/test pull-kops-e2e-k8s-containerd

/test pull-kops-verify-staticcheck

Timeout & an old test

@justinsb
Copy link
Member Author

/test pull-kops-e2e-k8s-containerd

Copy link
Member

@johngmyers johngmyers left a comment

Choose a reason for hiding this comment

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

Really looking forward to this. I think the pointer assignability is the only real blocker, though we should decide if we want to split on "," for string slices.

Path: "Spec.Containers[0].Policy.Name",
Value: "allowed",
},
// Not sure if we should do this...
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 if it's effectively appending an element, then it's okay.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's appending an intermediate element (containers[0]) which is what gave me pause. In this semi-fictional example, the created container is unlikely to be valid; it feels more likely to be an array indexing user-error.

Copy link
Member

Choose a reason for hiding this comment

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

We insert intermediate elements when they're nil pointers, which seems analogous. If it's not valid after processing all setters then API validation will catch that.

This means we no longer have to individually hard-code the `kops set`
fields, however we use the "language" we're now demonstrated.

We add tests to ensure we have parity with our existing (hard-coded)
setter logic.
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Aug 30, 2020
Copy link
Member

@johngmyers johngmyers left a comment

Choose a reason for hiding this comment

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

/lgtm

Path: "Spec.Containers[0].Policy.Name",
Value: "allowed",
},
// Not sure if we should do this...
Copy link
Member

Choose a reason for hiding this comment

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

We insert intermediate elements when they're nil pointers, which seems analogous. If it's not valid after processing all setters then API validation will catch that.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 30, 2020
@k8s-ci-robot k8s-ci-robot merged commit 4d7632a into kubernetes:master Aug 30, 2020
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. 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. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants