-
Notifications
You must be signed in to change notification settings - Fork 101
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
Updating listSecrets to use the new Azure Client #4862
Conversation
9f447ac
to
63a4a20
Compare
63a4a20
to
adb9534
Compare
360d44e
to
e9d5d18
Compare
adb9534
to
cbd7f79
Compare
pkg/rp/secretvalueclient.go
Outdated
custom := clients.NewCustomActionClient(parsed.FindScope(resources.SubscriptionsSegment), c.ARM.Auth) | ||
response, err := custom.InvokeCustomAction(ctx, arm.ID, arm.APIVersion, action, nil) | ||
subscriptionID := parsed.FindScope(resources.SubscriptionsSegment) | ||
client, err := clientv2.NewCustomActionClient(subscriptionID, c.ARM.ClientOption.Cred) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're taking a resource ID in BeginCustomAction
do we need to pass the subscription id here? That would simplify life if we don't have to.
pkg/azure/clientv2/customaction.go
Outdated
@@ -27,7 +28,7 @@ type CustomActionClient struct { | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please address all missing feedbacks in #4851
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About the unit tests; the tests in the current client (not v2) are as follows:
- resourcedeploymentclient_test.go (https://github.com/project-radius/radius/blob/main/pkg/azure/clients/resourcedeploymentclient_test.go)
- resourcedeploymentoperationsclient_test.go (https://github.com/project-radius/radius/blob/main/pkg/azure/clients/resourcedeploymentoperationsclient_test.go)
- unfold_test.go (https://github.com/project-radius/radius/blob/main/pkg/azure/clients/unfold_test.go).
The first two only have one test in each. And those tests can't be moved over to the new client because those functions don't exist anymore in client v2.
unfold.go
will be handled in another PR and therefore the tests will be also moved/changed accordingly in that PR.
I will also have another PR just for adding/polishing unit tests after we migrate to the new clients.
Please let me know if that doesn't for you @youngbupark @rynowak. I am open to suggestions of any kind.
Right now this PR is the step 1 of the migration to client v2.
882e918
to
c36dad9
Compare
7090307
to
f081ad6
Compare
f081ad6
to
4127268
Compare
4127268
to
baf08ef
Compare
pkg/azure/clientv2/customaction.go
Outdated
if err != nil { | ||
return nil, err | ||
} | ||
|
||
pipeline, err := armruntime.NewPipeline(moduleName, moduleVersion, credential, runtime.PipelineOptions{}, options) | ||
pipeline, err := armruntime.NewPipeline(ModuleName, ModuleVersion, options.Cred, runtime.PipelineOptions{}, armClientOptions) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it means customactionclient always requires the credentials, but client.CustomActionClient does not use any authorizer. Can you please review CustomActionClient usage again?
Also if cred is not required, then how should we use newclient without cred?
pkg/rp/secretvalueclient.go
Outdated
return nil, err | ||
} | ||
|
||
options := clientv2.NewClientBeginCustomActionOptions(arm.ID, action, arm.APIVersion) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need additional Begin* function ? I do not think we need to split InvokeCustomAction to NewClientBeginCustomActionOptions and BeginCustomAction.
baf08ef
to
2e662b8
Compare
// ClientOption is the client v2 option including new client credentials. | ||
ClientOption clientv2.AzureClientOption | ||
// ClientOptions is the client v2 options including new client credentials. | ||
ClientOptions clientv2.Options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason I named this as ClientOptions is to specify that this is the Options struct that is in the Clients package.
2e662b8
to
c4593a7
Compare
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" | ||
"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" | ||
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" | ||
"github.com/project-radius/radius/pkg/ucp/resources" | ||
) | ||
|
||
type CustomActionClient struct { | ||
*BaseClient | ||
type ClientCustomActionResponse struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add comments to all public struct/methods/members...
108a32f
to
b40e4cf
Compare
// Cred represents a credential for OAuth token. | ||
Cred azcore.TokenCredential | ||
|
||
BaseURI string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need this BaseURI here ? please add comment to public member.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still use this as the way to pass in a BaseURI to the client. I am going to see in the other PRs if we actually need this, and then update if necessary.
b40e4cf
to
9f76a56
Compare
} | ||
|
||
func NewClientBeginCreateOrUpdateOptions(resourceID, resumeToken, apiVersion string) *ClientBeginCreateOrUpdateOptions { | ||
// FIXME: This is to validate the resourceID. | ||
func NewClientBeginCreateOrUpdateOptions(resourceID, apiVersion string) *ClientBeginCreateOrUpdateOptions { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have the reason why you introduce Begin pattern? the older client doesn't have this begin. To me, begin* is an unnecessary helper. Please make it simple.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we discussed, this clientv2 pkg wraps the client, but we do not need to follow the generated client pattern. Generator has to use the same pattern to generate client even though it is inefficient. I strongly recommend to follow the older client pattern although the implementation is different.
So, we do not need ClientBeginCreateOrUpdateOptions
. We only need two methods like below.
// ....
func (client *DeploymentsClient) CreateOrUpdate(ctx context.Context, resourceID string, parameters Deployment) (*runtime.Poller[ClientCreateOrUpdateResponse], error) {
// validate resourceID
req, err := client.createCreateOrUpdateRequest(ctx, resourceID, parameters)
resp, err := client.Pipeline.Do(req)
if err != nil {
return nil, err
}
if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated, http.StatusAccepted) {
return nil, runtime.NewResponseError(resp)
}
return runtime.NewPoller[ClientCreateOrUpdateResponse](resp, *client.Pipeline, nil)
}
func (client *DeploymentsClient) createCreateOrUpdateRequest(ctx context.Context, resourceID string, parameters Deployment) (*policy.Request, error) {
// return Request
}
9f76a56
to
c7b6c3b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
pkg/azure/clientv2/customaction.go
Outdated
urlPath = strings.ReplaceAll(urlPath, "{resourceID}", url.PathEscape(resourceID)) | ||
|
||
if opts.action == "" { | ||
if action == "" { | ||
return nil, errors.New("action cannot be empty") | ||
} | ||
urlPath = strings.ReplaceAll(urlPath, "{action}", url.PathEscape(opts.action)) | ||
urlPath = strings.ReplaceAll(urlPath, "{action}", url.PathEscape(action)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QQ: is there a reason why we use ReplaceAll
?
Can we just use fmt.sprintf
?
if resourceID == "" {
return nil, errors.New("resourceID cannot be empty")
}
if action == "" {
return nil, errors.New("action cannot be empty")
}
urlPath := fmt.Sprintf("%s/%s", url.PathEscape(resourceID), url.PathEscape(action))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can also use runtime.JoinPaths
instead of urlPath.
if resourceID == "" {
return nil, errors.New("resourceID cannot be empty")
}
if action == "" {
return nil, errors.New("action cannot be empty")
}
urlPath := runtime.JoinPaths(client.baseURI, url.PathEscape(resourceID), url.PathEscape(action))
req, err := runtime.NewRequest(ctx, http.MethodPost, urlPath)
0aff153
to
8a56a94
Compare
pkg/azure/clientv2/customaction.go
Outdated
} | ||
return resp, nil | ||
} | ||
urlPath := "{resourceID}/{action}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not need this anymore.
8a56a94
to
f2631b4
Compare
# Description Clients migrated: 1. Custom Action Functions: 1. GetResourceLocation Function Work in Progress: 1. Unit Test 3. Functional Test ## Issue reference Fixes: #issue_number ## Checklist Please make sure you've completed the relevant tasks for this PR, out of the following list: * [ ] Code compiles correctly * [ ] Adds necessary unit tests for change * [ ] Adds necessary E2E tests for change * [ ] Unit tests passing * [ ] Extended the documentation / Created issue for it
Description
Clients migrated:
Functions:
Work in Progress:
Issue reference
Fixes: #issue_number
Checklist
Please make sure you've completed the relevant tasks for this PR, out of the following list: