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

feat(timeout): Implement customizable timeout for Azure CLI token ret… #362

Merged
merged 1 commit into from
Nov 23, 2023

Conversation

Aricg
Copy link
Contributor

@Aricg Aricg commented Nov 16, 2023

This commit introduces the ability to specify a custom timeout for Azure CLI token retrieval within the kubelogin package. The AzureCLIToken struct now includes a timeout field, allowing users to set a specific timeout duration.

@Aricg
Copy link
Contributor Author

Aricg commented Nov 16, 2023

@microsoft-github-policy-service agree company="AIFI"

@Aricg
Copy link
Contributor Author

Aricg commented Nov 16, 2023

relevant message from a maintainer of azure-sdk-for-go/sdk/azidentity/
Azure/azure-sdk-for-go#21985 (comment)

@weinong
Copy link
Contributor

weinong commented Nov 16, 2023

Looking forward to it!

@Aricg Aricg force-pushed the feat/configurable-timeout branch 8 times, most recently from d8cd938 to 18dd1ad Compare November 17, 2023 14:20
@Aricg
Copy link
Contributor Author

Aricg commented Nov 17, 2023

@weinong can you run the CI please?

golangci-lint run
pkg/token/federatedIdentity.go:65:15: string `/.default` has 3 occurrences, make it a constant (goconst)
		resource += "/.default"
		            ^
 ```
 
 
 Also, am I meant to fix this with a global const?

main.go Outdated Show resolved Hide resolved
@Aricg Aricg force-pushed the feat/configurable-timeout branch 2 times, most recently from a7f5109 to 4b47dd3 Compare November 17, 2023 19:12
@Aricg
Copy link
Contributor Author

Aricg commented Nov 17, 2023

I believe I also fixed the tests.

main.go Outdated Show resolved Hide resolved
kubelogin Outdated Show resolved Hide resolved
pkg/cmd/convert.go Outdated Show resolved Hide resolved
pkg/cmd/root.go Outdated Show resolved Hide resolved
pkg/token/options.go Outdated Show resolved Hide resolved
pkg/token/provider.go Outdated Show resolved Hide resolved
@Aricg Aricg force-pushed the feat/configurable-timeout branch 5 times, most recently from c256a27 to 19bb63e Compare November 19, 2023 20:11
@Aricg Aricg force-pushed the feat/configurable-timeout branch 5 times, most recently from a005fb1 to 35dd4b4 Compare November 20, 2023 00:39
@Aricg
Copy link
Contributor Author

Aricg commented Nov 20, 2023

linting is now passing my changes locally as well

@Aricg Aricg force-pushed the feat/configurable-timeout branch from 35dd4b4 to 0fa7d49 Compare November 20, 2023 14:32
@Aricg
Copy link
Contributor Author

Aricg commented Nov 20, 2023

I now see the timeout in both of the sub commands, and I am no longer wedging the --timeout into the main kubelogin command.

./kubelogin get-token --timeout 90s
./kubelogin convert-kubeconfig --timeout 90s
however we don't really pass the option to the the convert-kubeconfig subcommand..

pkg/cmd/ ->
convert.go
root.go *modified
token.go *modified

I'm only expecting to see it as an option in the get-token

./kubelogin  get-token --help | grep timeout
      --timeout duration                     Timeout duration for Azure CLI token requests (default 30s)
./kubelogin  convert-kubeconfig --help | grep timeout
      --timeout duration                     Timeout duration for Azure CLI token requests (default 30s)

do you know what I did wrong?

@weinong
Copy link
Contributor

weinong commented Nov 20, 2023

@Aricg , get-token and convert-kubeconfig share identical flags because convert-kubeconfig adds the flags to get-token command. Can you update the logic in convert.go so that it appends --timeout when that flag is used in convert-kubeconfig?

pkg/cmd/root.go Outdated Show resolved Hide resolved
pkg/cmd/token.go Outdated Show resolved Hide resolved
@Aricg Aricg force-pushed the feat/configurable-timeout branch from 0fa7d49 to 168c480 Compare November 21, 2023 19:42
@Aricg
Copy link
Contributor Author

Aricg commented Nov 21, 2023

@Aricg , get-token and convert-kubeconfig share identical flags because convert-kubeconfig adds the flags to get-token command. Can you update the logic in convert.go so that it appends --timeout when that flag is used in convert-kubeconfig?

Hi @weinong

I only need --timeout for
kubelogin get-token
not
kubelogin convert-kubeconfig

I don't see convert-kubeconfig using AzureCLIToken from https://github.com/Azure/azure-sdk-for-go/blob/7d4a3cbaadd5bf9f16322e1e2c673a633f146fb1/sdk/azidentity/azure_cli_credential.go#L105-L110

type AzureCLIToken struct {
	resourceID string
	tenantID   string
	timeout    time.Duration
}
func newAzureCLIToken(resourceID string, tenantID string, timeout time.Duration) (TokenProvider, error) {
 	if resourceID == "" {
 		return nil, errors.New("resourceID cannot be empty")
 	}

 	if timeout <= 0 {
 		timeout = defaultTimeout
 	}

 	return &AzureCLIToken{
 		resourceID: resourceID,
 		tenantID:   tenantID,
 		timeout:    timeout,
 	}, nil
 }

@weinong
Copy link
Contributor

weinong commented Nov 22, 2023

@Aricg convert-kubeconfig doesn't do network calls. It generally copy the flags into a kubecofig using get-token sub-command. It's fine you don't add it, if you don't find it a problem cracking up the kubeconfig to add the flag. Besides using the --timeout, a better usability may be via environment variable so that you don't need to update kubeconfig all the time.

Please fix up the UT, though!

@Aricg Aricg force-pushed the feat/configurable-timeout branch from 168c480 to 5b3b93c Compare November 22, 2023 12:58
@Aricg
Copy link
Contributor Author

Aricg commented Nov 22, 2023

go test -race -coverprofile=coverage.txt -covermode=atomic ./...
?   	github.com/Azure/kubelogin	[no test files]
?   	github.com/Azure/kubelogin/pkg/cmd	[no test files]
?   	github.com/Azure/kubelogin/pkg/token/mock_token	[no test files]
ok  	github.com/Azure/kubelogin/pkg/converter	1.988s	coverage: 90.0% of statements
ok  	github.com/Azure/kubelogin/pkg/pop	3.279s	coverage: 76.9% of statements
ok  	github.com/Azure/kubelogin/pkg/testutils	1.652s	coverage: 9.2% of statements
ok  	github.com/Azure/kubelogin/pkg/token	34.407s	coverage: 67.6% of statements
--timeout duration Timeout duration for Azure CLI token requests. It may be specified in AZURE_CLI_TIMEOUT environment variable (default 30s)

:)

@Aricg Aricg force-pushed the feat/configurable-timeout branch 2 times, most recently from 4f450da to 52ca6b1 Compare November 22, 2023 13:36
@codecov-commenter
Copy link

codecov-commenter commented Nov 22, 2023

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (369f19a) 65.02% compared to head (851453c) 65.16%.

Files Patch % Lines
pkg/token/options.go 63.63% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #362      +/-   ##
==========================================
+ Coverage   65.02%   65.16%   +0.13%     
==========================================
  Files          23       23              
  Lines        1710     1728      +18     
==========================================
+ Hits         1112     1126      +14     
- Misses        536      539       +3     
- Partials       62       63       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

pkg/cmd/token.go Outdated Show resolved Hide resolved
pkg/token/options_test.go Outdated Show resolved Hide resolved
@Aricg Aricg force-pushed the feat/configurable-timeout branch from 52ca6b1 to bb77dd6 Compare November 23, 2023 15:44
…rieval in kubelogin get-token

This commit introduces the ability to specify a custom timeout for Azure CLI token retrieval within the kubelogin get-token subcomand.
The `AzureCLIToken` struct now includes a `timeout` field, allowing users to set a specific timeout duration.
@Aricg Aricg force-pushed the feat/configurable-timeout branch from bb77dd6 to 851453c Compare November 23, 2023 15:58
Copy link
Contributor

@weinong weinong left a comment

Choose a reason for hiding this comment

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

LGTM

@weinong weinong merged commit 94ef8fb into Azure:master Nov 23, 2023
5 checks passed
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

Successfully merging this pull request may close these issues.

3 participants