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

Design of methods with XXXOptions #3349

Closed
shawkins opened this issue Jul 23, 2021 · 1 comment
Closed

Design of methods with XXXOptions #3349

shawkins opened this issue Jul 23, 2021 · 1 comment

Comments

@shawkins
Copy link
Contributor

This topic originated on #3316. list/watch both support ListOptions as an argument. Delete does not, but does support quite a few context methods.

It is not clear if delete should also support delete(DeleteOptions) for consistency with the list/watch methods.

There is also a consideration of what passing options directly makes sense given the usage of conflicting context values.

For example if you do:

client.configMaps().withField("y", "z").list(new ListOptionsBuilder().withFieldSelector("x=y").build())

It will currently send both:

GET /api/v1/namespaces/test/configmaps?fieldSelector=x%3Dy&fieldSelector=y%3Dz

An alternative design to directly passing the options is to inline the fluent construction, similar to what is being done for filtering:

public interface DeleteOptionsNested<T> extends DeleteOptionsFluent<DeleteOptionsNested<T>>, Nested<T> {
  
  default T endDeleteOptions() {
    return and();
  }
  
}
...
public interface Deletable {

  ...
  DeleteOptionsNested<Deletable> withDeleteOptions();

}

That allows for calls like:

client.configMaps().withName("map1").withDeleteOptions().withNewPreconditions("800", null).and().delete()

The understanding here is that the constructed deleted options will be the ones passed to the operation. If you override the default value passed in from the context, then it is explicit what you want to have happen.

The implementation with inline fluents is straight-forward. The context needs a reference to DeleteOptions and an extended DeleteFluentImpl to maintain a reference to the operation so that it can be returned with the updated context when the fluent nested ends.

Any property that is specific to a given operation (gracePeriodSeconds, propagationPolicy, cascading) would just move to a DeleteOptions on the context, rather than having an individual value. However common things like dryRun and this locked resourceVersion don't map neatly and would still need placeholders in the context and would presumably influence the default values of the DeleteOptions returned by withDeleteOptions.

@rohanKanojia @manusa WDYT:

  • should delete support all options?
  • should we stick with passing options or inline their construction?
  • if we stick with passing in the options, should we clarify what the relationship is between the existing context values and those in the options?
@shawkins
Copy link
Contributor Author

After some discussion it seems preferred not to further complicate the context (with) methods.

Another option is to use methods similar to edit:

delete(UnaryOperation<DeleteOptions> options)
list(UnaryOperation<ListOptions> options)
watch(UnaryOperation<ListOptions> options)

The options passed into the function will be populated already with values from the context. Anything done to manipulate them further will be what is passed to the api call. We can optionally consider using the signature:

delete(Consumer<DeleteOptionsBuilder> options)

Which would be more concise for the recommended usage pattern, but more restrictive.

The methods directly passing in ListOptions will be deprecated.

The context withXXX methods that apply to only one operation, such as withPropagationPolicy, could be deprecated - just to minimize what needs to be exposed.

@metacosm @manusa @rohanKanojia do you prefer the UnaryOperation or the Builder form of these functions?

shawkins added a commit to shawkins/kubernetes-client that referenced this issue Aug 1, 2021
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Aug 1, 2021
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Aug 1, 2021
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Aug 1, 2021
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Aug 2, 2021
@manusa manusa closed this as completed in b5ef58c Aug 3, 2021
MUzairS15 pushed a commit to MUzairS15/kubernetes-client that referenced this issue Aug 4, 2021
    pick fca47f8 chore(deps): bump maven-enforcer-plugin from 3.0.0-M3 to 3.0.0
    pick b5ef58c fix fabric8io#3349: adding consistency to the handling of option values
    pick a7c7b321a Updated changelog
    pick 1ad8eb953 Fixed indentation, renamed cinverdionReview.json and updated changelog
MUzairS15 pushed a commit to MUzairS15/kubernetes-client that referenced this issue Aug 5, 2021
    pick fca47f8 chore(deps): bump maven-enforcer-plugin from 3.0.0-M3 to 3.0.0
    pick b5ef58c fix fabric8io#3349: adding consistency to the handling of option values
    pick a7c7b321a Updated changelog
    pick 1ad8eb953 Fixed indentation, renamed cinverdionReview.json and updated changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant