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

⚠️ Convert client.List to use functional options #294

Merged
merged 1 commit into from
Jan 16, 2019

Conversation

droot
Copy link
Contributor

@droot droot commented Jan 15, 2019

Replaces:

List(ctx, ListOptions, list)

with:

List(ctx, list, ...Option)

This matches the functional options signature of client.Delete in #94.

A few examples (I tried formatting these as a table but it wasn't wide enough):

Select all:

// current
List(ctx, nil, list)
// proposed
List(ctx, list)

Filter by namespace:

// current
List(ctx, client.InNamespace(ns), list)
// proposed
List(ctx, list, client.InNamespace(ns))

Filter by namespace and labels:

// current
List(ctx, client.InNamespace(ns).MatchingLabels(labels), list)
// proposed
List(ctx, list, client.InNamespace(ns), client.MatchingLabels(labels))

To assemble a ListOptions with the builder methods or some other strategy, use the UseListOptions functional option:

lo := &client.ListOptions{}
client.List(ctx, list, client.UseListOptions(
  lo.InNamespace(ns).MatchingLabels(labels)
))

Note: This PR was contributed by @grantr but we couldn't get it merged because of the breaking changes, but now we are ready for a major revision 0.2.0, so I manually ported #106

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jan 15, 2019
@droot
Copy link
Contributor Author

droot commented Jan 15, 2019

@grantr would be great if you can take a quick look.

@droot droot assigned mengqiy and unassigned DirectXMan12 Jan 15, 2019
@mengqiy mengqiy added this to the 0.2.0 milestone Jan 16, 2019
Copy link
Contributor

@DirectXMan12 DirectXMan12 left a comment

Choose a reason for hiding this comment

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

lgtm modulo one minor detail

// cl.List(ctx, list, client.UseListOptions(lo.InNamespace(ns).MatchingLabels(labels)))
func UseListOptions(newOpts *ListOptions) ListOptionFunc {
return func(opts *ListOptions) {
opts.LabelSelector = newOpts.LabelSelector
Copy link
Contributor

Choose a reason for hiding this comment

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

can this just be *opts = *newOpts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Replaces:

List(ctx, ListOptions, list)

with:

List(ctx, list, ...option)

This matches the upcoming functional options signature of client.Delete.

To use the previous builder options, use the UseListOptions functional
option:

lo := &client.ListOptions{}
client.List(ctx, list, client.UseListOptions(
  lo.InNamespace(ns).MatchingLabels(labels)
  ))

Ported kubernetes-sigs#106 PR
@DirectXMan12
Copy link
Contributor

/lgtm
/approve

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

@grantr grantr left a comment

Choose a reason for hiding this comment

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

Thanks @droot! LGTM.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: DirectXMan12, droot, grantr

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

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/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.

None yet

5 participants