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

Refactor: Merge TokenFile auth with refresh auth #3817

Conversation

yue9944882
Copy link
Member

This pull request addresses the TODO comment:

// TODO: Merge this with TokenFileAuthentication.

It simplifies the TokenFileAuthentication by taking RefreshAuthentication as the parent class

@k8s-ci-robot k8s-ci-robot added 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. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Dec 9, 2024
@yue9944882 yue9944882 force-pushed the refactor/merge-token-file-auth branch 2 times, most recently from 6d6d2e4 to f1e0eaf Compare December 9, 2024 21:50
try {
return new String(Files.readAllBytes(Paths.get(file)), Charset.defaultCharset()).trim();
} catch (IOException e) {
throw new RuntimeException("Cannot read file: " + file);
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably convert this to some sort of non-RuntimeException like "FailedTokenAquisitionException" and handle that inside the RefreshAuthentication.java

Copy link
Member Author

Choose a reason for hiding this comment

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

That sounds like a good idea but I ended up adding the exception conversion as a runtime/unchecked exception in the parent class RefreshAuthentication. I also tried making it a checked exception in the token supplier function however it will break backward compatibility so I implemented the unchecked exception in the new commit. one example that compatibility would be broken is here where we're loading the token eagerly in RefreshAuthentication :

https://github.com/kubernetes-client/java/blob/master/util/src/main/java/io/kubernetes/client/util/credentials/RefreshAuthentication.java#L43

so the new checked exception would have to be added to the constructor which will require all places referencing it adding explicit handling the checked exception. does that make sense?

@brendandburns
Copy link
Contributor

One small comment and looks like format/testing is failing.

Signed-off-by: Min Jin <minkimzz@amazon.com>
@yue9944882 yue9944882 force-pushed the refactor/merge-token-file-auth branch from f1e0eaf to 80d68d1 Compare December 12, 2024 22:10
@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 Dec 12, 2024
@@ -63,19 +65,6 @@ void tokenProvided() throws ApiException {
1,
getRequestedFor(urlPathEqualTo("/api/v1/pods"))
.withHeader("Authorization", equalTo("Bearer token1")));

this.auth.setFile(SERVICEACCOUNT_TOKEN2_PATH);
Copy link
Member Author

Choose a reason for hiding this comment

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

these unit tests are no longer needed as it was originally for testing token expiry/rotation behavior. now it's decoupled/delegated to the RefreshAuthentication class.

@brendandburns
Copy link
Contributor

/lgtm
/approve

Looks good to me. Let's consider refactoring these exceptions in the future.

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: brendandburns, 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:
  • OWNERS [brendandburns,yue9944882]

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 merged commit fda5d89 into kubernetes-client:master Dec 13, 2024
18 checks passed
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.

3 participants