Skip to content

Add support for transforming objects in shared informers #2148

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

Merged
merged 1 commit into from
Feb 24, 2022

Conversation

dddddai
Copy link
Contributor

@dddddai dddddai commented Feb 23, 2022

Fixes #2146

@k8s-ci-robot k8s-ci-robot added 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. labels Feb 23, 2022
*
* @param transformFunc the transform function
*/
void setTransformFunc(Function<KubernetesObject, KubernetesObject> transformFunc);
Copy link
Member

Choose a reason for hiding this comment

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

lets define a functional interface named TransformFunc to align w/ the upsteam, also the original go function returns an error upon failure, so i think we should declare a checked exception e.g. throws ObjectTransformException. the unit test should also cover the failure path when the checked exception is thrown.

Copy link
Contributor Author

@dddddai dddddai Feb 23, 2022

Choose a reason for hiding this comment

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

also the original go function returns an error upon failure, so i think we should declare a checked exception e.g. throws ObjectTransformException.

The exception handling references addIndexers, which returns an error in client-go while in client-java it doesn't declare an exception
https://github.com/kubernetes/kubernetes/blob/v1.23.4/staging/src/k8s.io/client-go/tools/cache/shared_informer.go#L189

public void addIndexers(Map<String, Function<ApiType, List<String>>> indexers) {
if (started) {
throw new IllegalStateException("cannot add indexers to a running informer");
}
indexer.addIndexers(indexers);
}

Do you mean something like this?

public interface TransformFunc {

  /**
   * @param the original object to be transformed
   * @return the transformed object
   */
  KubernetesObject transform(KubernetesObject object) throws ObjectTransformException;
}

or keep it aligned with addIndexers?

Copy link
Member

Choose a reason for hiding this comment

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

Do you mean something like this?

yes, thats exactly what i thought, as for addIndexers, i think we can keep it, it's the legacy code and it's working.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, fixed

Copy link
Member

@yue9944882 yue9944882 left a comment

Choose a reason for hiding this comment

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

@dddddai thanks! one outstanding comment otherwise lgtm

@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 Feb 24, 2022
Copy link
Member

@yue9944882 yue9944882 left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dddddai, yue9944882

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 lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Feb 24, 2022
@k8s-ci-robot k8s-ci-robot merged commit e168bb9 into kubernetes-client:master Feb 24, 2022
@dddddai dddddai deleted the transform branch March 7, 2022 11:41
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.

Support for transforming objects in shared informers
3 participants