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

fix: test and namespace isolation #2187

Merged
merged 5 commits into from May 17, 2024
Merged

Conversation

lkingland
Copy link
Member

@lkingland lkingland commented Feb 28, 2024

Changes

  • 🧹 removes now-unnecessary Namespace member from structs
  • 🐛 several small bugfixes
  • 🧹 general cleanup

tl;dr

Namespace as a struct member only works under fairly tight circumstances. Recent functional additions invalidate this assumption. This PR therefore removes namespace as a structure state member, adding it to method signatures where appropriate. This keeps things flat and stupid-simple.

Background

The initial design was to encapsulate the effective namespace within a fn.Client instance (and concrete implementations of the constituent interfaces like Deployer, Lister, Remover etc) by providing it as a constructor argument. All operations conducted via the client instance would then be targeted at that namespace. Clients, being lightweight structures, can be instantiated easily, one for each namespace. This allowed the target namespace to only be a concern during initial instantiation, with all following operations being able to ignore this internal state. However, this assumption turned out to be incorrect for a couple of reasons: cross-namespace operations and developer familiarity.

As new methods and options were added to the Client, there came to exist a few operations whose target namespace was either ambiguous or undefined. For example deploying a function to a new namespace requires removing it from the old. What, then, is the internal state of the namespace member? This broke the encapsulation of that complexity.

Second, and perhaps more practical, is the expectation by users of the client instance (most of whom are at least familiar with the underlying Kubernetes implementation) expect namespace to be a primary concern.

These two conspired to result in several operations which expected namespace as a per-request argument. This of course caused all logic to then treat the struct member as more of a fallback or default.

This is unnecessary complexity. If a member like namespace can be completely internalized and removed from all method arguments, only being considered during instantiation, then it has succeeded in reducing complexy. If this member "leaks" into any of the struct methods, then it is no longer assisting,but instead causing more complexity than just adding it to the set of expected arguments.

Therefore, this PR accepts that namespace is an expected argument in most cases, removing it from constructors and any state.

/kind bug
/kind cleanup

Fixes #

Release Note

Fixed Function namespace resolution in some edge cases.

Docs


@knative-prow knative-prow bot added the kind/bug Categorizes issue or PR as related to a bug. label Feb 28, 2024
Copy link

knative-prow bot commented Feb 28, 2024

@lkingland: The label(s) kind/<kind> cannot be applied, because the repository doesn't have them.

In response to this:

Changes

  • 🧹 removes now-unnecessary Deployer Namespace member
  • 🐛 fix test failure if environment already has an active k8s context
  • 🧹 FromTempDirectory moved to shared testing package

/kind bug

/kind

Fixes #

Release Note

Fixed Function namespace resolution in some edge cases.

Docs


Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@knative-prow knative-prow bot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 28, 2024
@lkingland lkingland requested review from gauron99 and removed request for maximilien and navidshaikh February 28, 2024 08:22
pkg/testing/testing.go Outdated Show resolved Hide resolved
pkg/testing/testing.go Outdated Show resolved Hide resolved
Copy link
Contributor

@gauron99 gauron99 left a comment

Choose a reason for hiding this comment

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

lgtm after removing the left over "withDeployerNamespace" in tests and typos.
One less namespace-resolution complication 🎉

@lkingland lkingland marked this pull request as draft February 29, 2024 06:31
@knative-prow knative-prow bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 29, 2024
@knative-prow knative-prow bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 4, 2024
@lkingland lkingland added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Mar 5, 2024
@lkingland lkingland force-pushed the test-isolation branch 2 times, most recently from c3917e5 to a3a11f2 Compare March 6, 2024 04:47
@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 17, 2024
@knative-prow-robot knative-prow-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 8, 2024
Copy link

codecov bot commented Apr 8, 2024

Codecov Report

Attention: Patch coverage is 65.38462% with 117 lines in your changes are missing coverage. Please review.

Project coverage is 64.49%. Comparing base (b97d841) to head (98dc85b).
Report is 92 commits behind head on main.

Files Patch % Lines
pkg/pipelines/tekton/pipelines_provider.go 46.55% 25 Missing and 6 partials ⚠️
pkg/functions/client.go 74.60% 12 Missing and 4 partials ⚠️
pkg/pipelines/tekton/pipelines_pac_provider.go 0.00% 12 Missing ⚠️
cmd/describe.go 71.42% 4 Missing and 4 partials ⚠️
pkg/mock/pipelines_provider.go 46.15% 3 Missing and 4 partials ⚠️
cmd/deploy.go 66.66% 3 Missing and 3 partials ⚠️
cmd/delete.go 80.76% 4 Missing and 1 partial ⚠️
cmd/root.go 70.58% 2 Missing and 3 partials ⚠️
pkg/mock/deployer.go 50.00% 3 Missing and 1 partial ⚠️
pkg/pipelines/tekton/resources.go 50.00% 2 Missing and 2 partials ⚠️
... and 11 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2187      +/-   ##
==========================================
+ Coverage   64.21%   64.49%   +0.28%     
==========================================
  Files         108      127      +19     
  Lines       13918    11454    -2464     
==========================================
- Hits         8937     7387    -1550     
+ Misses       4108     3160     -948     
- Partials      873      907      +34     
Flag Coverage Δ
e2e-test 38.14% <43.70%> (+0.76%) ⬆️
e2e-test-oncluster 31.19% <41.05%> (+0.69%) ⬆️
e2e-test-oncluster-runtime 27.49% <35.43%> (?)
e2e-test-runtime-go 26.09% <29.80%> (?)
e2e-test-runtime-node 27.12% <30.46%> (?)
e2e-test-runtime-python 27.05% <29.80%> (?)
e2e-test-runtime-quarkus 27.14% <29.80%> (?)
e2e-test-runtime-rust 26.19% <29.80%> (?)
e2e-test-runtime-springboot 26.22% <29.80%> (?)
e2e-test-runtime-typescript 27.21% <30.46%> (?)
integration-tests 50.13% <60.94%> (+0.27%) ⬆️
unit-tests 49.15% <44.67%> (?)
unit-tests-macos-latest ?
unit-tests-ubuntu-latest ?
unit-tests-windows-latest ?

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@knative-prow knative-prow bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 9, 2024
@knative-prow knative-prow bot requested review from jrangelramos and nainaz May 9, 2024 00:27
@lkingland lkingland requested review from matzew, matejvasek and gauron99 and removed request for jrangelramos and nainaz May 9, 2024 01:05
@@ -25,7 +25,7 @@ func NewConfigGitRemoveCmd(newClient ClientFactory) *cobra.Command {
such as local generated Pipelines resources and any resources generated on the cluster.
`,
SuggestFor: []string{"rem", "rmeove", "del", "dle"},
PreRunE: bindEnv("path", "namespace", "delete-local", "delete-cluster"),
PreRunE: bindEnv("path", "delete-local", "delete-cluster"),
Copy link
Member

Choose a reason for hiding this comment

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

the ns comes from?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is just cleanup. That command does not use namespace. This command removes git settings from the function's metadata. This is not func delete which actually removes the running service (and requires namespace)

@@ -28,7 +28,7 @@ No local files are deleted.
{{rootCmdUse}} delete

# Undeploy the function 'myfunc' in namespace 'apps'
{{rootCmdUse}} delete -n apps myfunc
{{rootCmdUse}} delete myfunc --namespace apps
Copy link
Member

Choose a reason for hiding this comment

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

does this need release notes? Mirgation? or the like?

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 two commands are equivalent. I was just making the documentation use the long-form name for (hopefully) better clarity.

Copy link
Member

@matzew matzew left a comment

Choose a reason for hiding this comment

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

/lgtm

/hold
for other reviewers

@knative-prow knative-prow bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 13, 2024
@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label May 13, 2024
Copy link

knative-prow bot commented May 13, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lkingland, matzew

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:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Contributor

@gauron99 gauron99 left a comment

Choose a reason for hiding this comment

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

amazing stuff! just a few comments

cmd/deploy.go Outdated Show resolved Hide resolved
cmd/deploy_test.go Outdated Show resolved Hide resolved
cmd/root_test.go Outdated Show resolved Hide resolved
pkg/config/config_test.go Outdated Show resolved Hide resolved
pkg/pipelines/tekton/pipelines_integration_test.go Outdated Show resolved Hide resolved
@matzew
Copy link
Member

matzew commented May 16, 2024

@lkingland any updates?

@knative-prow knative-prow bot removed the lgtm Indicates that a PR is ready to be merged. label May 17, 2024
@lkingland
Copy link
Member Author

@lkingland any updates?

Could use another /LGTM presuming the tests pass!

@gauron99
Copy link
Contributor

/lgtm

@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label May 17, 2024
@knative-prow knative-prow bot removed the lgtm Indicates that a PR is ready to be merged. label May 17, 2024
@gauron99
Copy link
Contributor

/lgtm

@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label May 17, 2024
@lkingland lkingland removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 17, 2024
@knative-prow knative-prow bot merged commit e6fa020 into knative:main May 17, 2024
38 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. kind/bug Categorizes issue or PR as related to a bug. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants