-
Notifications
You must be signed in to change notification settings - Fork 71
feat: Refactor set-namespace #785
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
Conversation
6bd45e7
to
bd2a258
Compare
b5723c3
to
7aeb38a
Compare
7aeb38a
to
596d5f7
Compare
I like this callback approach a lot 👍 |
4db2c75
to
200f250
Compare
- Define visitNamespace with callback function as params to replace multiple individual object iterations. - Define Namespace struct to provide callback functions for different iterations
200f250
to
fcba72c
Compare
Thank you so much for the suggestions! |
fcba72c
to
f9c2dc8
Compare
merge after
f9c2dc8
to
d9db966
Compare
* updated behavior and tests for ensure-name-substring * adjusted fix-simple test to not specify include-meta-resources * kubeval-simple: skip Kptfile validation * adjusted starlark tests/examples to handle Kptfile and StarlarkRun files * adjusted search-replace tests to match kpt behavior to include meta resources by default * adjusted create-setters-simple test to match kpt behavior * adjusted set-project-id to match the kpt fn behavior * adjusted generate-kpt-pkg-docs-simple test to match kpt behavior * adjusted set-annotations tests to match new kpt fn behavior * adjusted set-labels test to match new kpt fn behavior * adjusted the golden file for generate-folders function * using kpt@main
8148ca3
to
38ddcdb
Compare
functions/go/set-namespace/README.md
Outdated
namespace: irrelevant # skip since namespace does not match "example". | ||
``` | ||
|
||
##### Selector Mode |
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 should have at least one example for each mode.
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'll do that in a follow up PR.
Co-authored-by: Sunil Arora <[email protected]>
New logic
set-namespace
supports three modesnamespaceSelector
parameter in the functionConfig. If given, thenamespaceSelector
value is the "oldNs"namespace
object in the resourcelist.items. If found (andnamespaceSelector
is not given), use the namespacemetadata.name
value as "oldNs"namespaceSelector
nornamespace
object are found, we require all namespace scoped resources have the same namespace value, which is the "oldNs".set-namespace
only replace the namespace fields which match the "oldNs" to the new Namespace.config.kubernetes.io/local-config
"ClusterRoleBinding" and "RoleBinding" changes
RoleBinding
subjects
namespace check. BecauseRoleBinding
is namespace-scoped so it only works for resources under the same namespace. Itselfmetadata.namespace
should be updated.ClusterRoleBinding
check to not check subjects "ServiceAccount" kind. For clusterrolebinding, only ServiceAccount may be namespace scoped.New Code Structure
Define
VisitNamespace
with callback function as params to iterationsresourcelist.items
.Define
Namespace
struct to provide callback functions for different iterations, includingFindAllNamespaces
to check duplication,UpdateNamespace
to update namespace value via string pointer,GetDependsOnMap
to build a key value pairs by resourcesdepends-on
annotation, andUpdateAnnotation
to update the namespace segment in thedepends-on
annotation.Call the new function in go-sdk
IsGVKMatch
for duck typing check.Update the KRM resources' namespace value via string pointer.
Rewrite the README