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

Add patch namespace and split test utils #5506

Merged
merged 1 commit into from
May 1, 2023
Merged

Conversation

rynowak
Copy link
Contributor

@rynowak rynowak commented May 1, 2023

Description

This change adds the server-side "patch namespace" functionality to a shared utility package and adds tests for it.

Adding tests triggered a need to refactor our testutil package. The problem is that testutil references many different abstractions across Radius (like store and secrets) which causes a package reference cycle. Our shared Kubernetes utilities are used by the store, and secret manager.

The fix is to split the Kubernetes testutils functionality into its own package. 'utils' packages need to be really granular in Go or else you end up with cycles like this frequently.

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

@rynowak rynowak requested a review from a team as a code owner May 1, 2023 18:54
return fmt.Errorf("error applying namespace: %w", err)
}

return nil
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This functionality was copied from the handlers package. It didn't have any tests.

return c.WithWatch.Create(ctx, obj)
} else {
return c.WithWatch.Update(ctx, obj)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@youngbupark - this is similar to the workaround we have for client-go + Server-Side Apply. Fake runtime client does not support SSA, and they are not planning to fix it, so they recommend this workaround.

It's really lame that none of the clients support SSA for testing, because SSA is recommended in new code.

@github-actions
Copy link

github-actions bot commented May 1, 2023

Test Results

2 460 tests  +1   2 453 ✔️ +1   1m 58s ⏱️ +2s
   229 suites ±0          7 💤 ±0 
       1 files   ±0          0 ±0 

Results for commit e4f1666. ± Comparison against base commit 22877cd.

This pull request removes 2 and adds 3 tests. Note that renamed tests count towards both.
github.com/project-radius/radius/pkg/armrpc/frontend/controller ‑ TestValidateEtag_IfMatch/fc243fff-e701-49a9-9c1c-4490e08ab01d
github.com/project-radius/radius/pkg/armrpc/frontend/controller ‑ TestValidateEtag_IfMatch/fc243fff-e701-49a9-9c1c-4490e08ab01d#01
github.com/project-radius/radius/pkg/armrpc/frontend/controller ‑ TestValidateEtag_IfMatch/ee9072d4-4035-4425-8f17-ed89858c37d4
github.com/project-radius/radius/pkg/armrpc/frontend/controller ‑ TestValidateEtag_IfMatch/ee9072d4-4035-4425-8f17-ed89858c37d4#01
github.com/project-radius/radius/pkg/kubeutil ‑ Test_PatchNamespace

♻️ This comment has been updated with latest results.

@youngbupark
Copy link

Please fix the linters and tests.

)

// PatchNamespace creates a namespace if it does not exist.
func PatchNamespace(ctx context.Context, client runtime_client.Client, namespace string) error {

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There changes end up being big because of the two clients. All of the intermediate layers of code have to change when you swap to use a different client. This is why I started a discussion with you.

Let me see what I can easily consolidate.

Copy link
Contributor

@ytimocin ytimocin left a comment

Choose a reason for hiding this comment

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

There are some warnings -- a rebase might be necessary.

@rynowak
Copy link
Contributor Author

rynowak commented May 1, 2023

Looks like there's a unit test failure to fix. I'll also see if I can dedupe further.

@rynowak
Copy link
Contributor Author

rynowak commented May 1, 2023

I found like 3 more copies of this code 😆

This change adds the server-side "patch namespace" functionality to a shared utility package and adds tests for it.

Adding tests triggered a need to refactor our `testutil` package. The problem is that `testutil` references many different abstractions across Radius (like store and secrets) which causes a package reference cycle. Our shared Kubernetes utilities are used by the store, and secret manager.

The fix is to split the Kubernetes testutils functionality into its own package. 'utils' packages need to be really granular in Go or else you end up with cycles like this frequently.
@rynowak rynowak force-pushed the rynowak/runtime-client branch from a5deb41 to e4f1666 Compare May 1, 2023 19:59
@github-actions
Copy link

github-actions bot commented May 1, 2023

61.8

For the detailed report, please go to Checks tab, click Build and Test, and then download unit_test_coverage artifact at the bottom of build page.

  • Your PR branch coverage: 61.8 %
  • main branch coverage: 61.8 %
  • diff coverage: 0 %

The coverage result does not include the functional test coverage.

@rynowak rynowak merged commit ed78234 into main May 1, 2023
@rynowak rynowak deleted the rynowak/runtime-client branch May 1, 2023 21:46
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.

4 participants