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

MIWI API endpoints #3608

Merged
merged 26 commits into from
Jun 6, 2024
Merged

MIWI API endpoints #3608

merged 26 commits into from
Jun 6, 2024

Conversation

kimorris27
Copy link
Contributor

Which issue this PR addresses:

https://issues.redhat.com/browse/ARO-6448

What this PR does / why we need it:

This PR introduces the API endpoints for the PlatformWorkloadIdentityRoleSet proxy resources as discussed in MIWI design documents. The only deviation from the design docs is that I did not implement an admin PATCH - it's extra work, and we are hardly if ever going to use it (refer to update_ocp_versions.go to see how we do OpenShiftVersions today and talk directly to Cosmos DB without even using the PUT API endpoint). But if the team reviews and thinks a PATCH is worth adding, we can add it.

The three new endpoints are:

  • External GET (list)
  • Admin GET (list)
  • Admin PUT

Test plan for issue:

  • Unit tests
  • Tested the endpoints with a full service dev RP
  • (Should I test in INT as well?)

Is there any documentation that needs to be updated for this PR?

No (I think?)

How do you know this will function as expected in production?

Tested the endpoints with a full service RP, reused existing battle-tested frontend code, and was thorough in writing unit test cases.

Copy link
Collaborator

@cadenmarchese cadenmarchese left a comment

Choose a reason for hiding this comment

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

mostly lgtm! Just a few questions / comments. thanks!

cmd/aro/rp.go Show resolved Hide resolved
out.Properties.PlatformWorkloadIdentityRoles[i].ServiceAccounts = make([]string, 0, len(r.ServiceAccounts))
out.Properties.PlatformWorkloadIdentityRoles[i].ServiceAccounts = append(out.Properties.PlatformWorkloadIdentityRoles[i].ServiceAccounts, r.ServiceAccounts...)
for _, r := range s.Properties.PlatformWorkloadIdentityRoles {
role := PlatformWorkloadIdentityRole{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: space between PlatformWorkloadIdentityRole and {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd put a space before the curly brace if for example this were line 23 and I had left out the space after the range expression, but I think it's normal Go style to avoid leaving blank space in that spot in a struct literal, and that's what's done throughout the codebase.

for i, r := range new.Properties.PlatformWorkloadIdentityRoles {
if r.OperatorName == "" {
errs = append(errs, api.NewCloudError(http.StatusBadRequest, api.CloudErrorCodeInvalidParameter, fmt.Sprintf("properties.platformWorkloadIdentityRoles[%d].operatorName", i), "Must be provided"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of comparing struct fields individually, consider using this: https://github.com/go-playground/validator

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I played around with it, but I don't think it's good for our static validators simply because it doesn't give the user friendly error messages that we want going to those making API requests. For example:

Key: 'PlatformWorkloadIdentityRole.OperatorName' Error:Field validation for 'OperatorName' failed on the 'required' tag

This error message would be perfectly fine for me as a regular developer of the RP, but it doesn't even include the fully qualified path of the API field presenting the issue, which won't be great for external users. (Well, I say "external users", but this is the admin API... 🙂)

I think adding it in just for this PR would create an inconsistency with respect to our error messaging and that with that in mind it would be best considered as a future refactor that we do across all of the static validators. Your thoughts?

@hlipsig
Copy link
Contributor

hlipsig commented Jun 3, 2024

I agree that patch seems unnecessary. This PR is already large, if we decide we need patch after a while then let's do it in its own PR. Still reviewing code may have more comments later.

Copy link
Contributor

@hlipsig hlipsig left a comment

Choose a reason for hiding this comment

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

half done review for discussion points.

@kimorris27 kimorris27 force-pushed the kimorris27/ARO-6448-api-endpoints branch from a6c513a to 9607267 Compare June 3, 2024 19:52
@hlipsig
Copy link
Contributor

hlipsig commented Jun 3, 2024

/azp run e2e

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@hlipsig
Copy link
Contributor

hlipsig commented Jun 4, 2024

/azp run ci

I originally wrote the code the way I did so that we could aggregate
errors so that we could provide a better UX in cases where there are
multiple similar errors in the request content. I found while writing
unit tests that aggregating the errors in this way and not wrapping them
in a CloudError causes the RP to return an internal server error instead
of a 400 bad request.

Is there a way we can aggregate the errors and still wrap them in a
CloudError? I'm not sure of the formatting requirements for the text of
CloudErrors.
@kimorris27 kimorris27 force-pushed the kimorris27/ARO-6448-api-endpoints branch from bae3131 to d7e58e2 Compare June 5, 2024 21:12
@kimorris27
Copy link
Contributor Author

/azp run ci, e2e

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@SudoBrendan SudoBrendan self-requested a review June 5, 2024 21:58
Copy link
Collaborator

@SudoBrendan SudoBrendan left a comment

Choose a reason for hiding this comment

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

LGTM. I left one final comment I honestly don't know the answer to - just want to get a thought out there. Great work!

if err != nil {
t.Fatal(err)
}
oc := tt.preflightRequest()

go f.Run(ctx, nil, nil)
f.mu.Lock()
f.ocpVersionsMu.Lock()
Copy link
Collaborator

Choose a reason for hiding this comment

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

correct - I'm just trying to wrap my head around concurrent writes to different tables. I understand that from a Cosmos perspective, we should be able to write to both containers at the same time, but my question is, can the RP handle that? Would it be safer code-wise to keep all locks as the same thing, even if it is inefficient, so we don't risk a future change mistakingly using the wrong lock, because the RP doesn't write enough to Cosmos for us to care? ... Maybe I'm over-thinking this. 😅

Copy link
Collaborator

@cadenmarchese cadenmarchese left a comment

Choose a reason for hiding this comment

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

lgtm!

@cadenmarchese cadenmarchese merged commit 31c7252 into master Jun 6, 2024
20 checks passed
@SudoBrendan SudoBrendan deleted the kimorris27/ARO-6448-api-endpoints branch July 24, 2024 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chainsaw Pull requests or issues owned by Team Chainsaw ready-for-review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants