Skip to content

Conversation

yuwenma
Copy link
Contributor

@yuwenma yuwenma commented Mar 23, 2022

New logic

  • set-namespace supports three modes
    • support a new namespaceSelector parameter in the functionConfig. If given, the namespaceSelector value is the "oldNs"
    • allow no more than one namespace object in the resourcelist.items. If found (and namespaceSelector is not given), use the namespace metadata.name value as "oldNs"
    • If either namespaceSelector nor namespace 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.
  • Skip resources which have annotation config.kubernetes.io/local-config

"ClusterRoleBinding" and "RoleBinding" changes

  • Remove code about RoleBinding subjects namespace check. Because RoleBinding is namespace-scoped so it only works for resources under the same namespace. Itself metadata.namespace should be updated.
  • Simplify the 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 iterations resourcelist.items.

  • Define Namespace struct to provide callback functions for different iterations, including FindAllNamespaces to check duplication, UpdateNamespace to update namespace value via string pointer, GetDependsOnMap to build a key value pairs by resources depends-on annotation, and UpdateAnnotation to update the namespace segment in the depends-on annotation.

  • Call the new function in go-sdk

    • GetSlice to handle the ClusterRoleBinding "subjects" modification
    • GetXXXOrDie to get a KRM resource component from a field path, and panic if field path is wrong (expecting the go SDK to handle the panic and gives user friendly guidance)
    • SetXXXOrDie
    • IsGVKMatch for duck typing check.
  • Update the KRM resources' namespace value via string pointer.

Rewrite the README

@yuwenma yuwenma changed the title Update set-namespace logic feat: Introduce 3 updateMode in set-namespace function Mar 23, 2022
@yuwenma yuwenma requested a review from justinsb March 23, 2022 07:50
@yuwenma yuwenma force-pushed the set-namespace-v2 branch 2 times, most recently from 6bd45e7 to bd2a258 Compare March 23, 2022 19:12
@yuwenma yuwenma force-pushed the set-namespace-v2 branch 3 times, most recently from b5723c3 to 7aeb38a Compare March 28, 2022 23:00
@yuwenma yuwenma changed the title feat: Introduce 3 updateMode in set-namespace function feat: Refactor set-namespace Mar 28, 2022
@justinsb
Copy link
Contributor

I like this callback approach a lot 👍

@yuwenma yuwenma force-pushed the set-namespace-v2 branch 5 times, most recently from 4db2c75 to 200f250 Compare April 5, 2022 03:15
yuwenma added 3 commits April 4, 2022 20:15
- Define visitNamespace with callback function as params to replace multiple individual object iterations.
- Define Namespace struct to provide callback functions for different iterations
@yuwenma yuwenma force-pushed the set-namespace-v2 branch from 200f250 to fcba72c Compare April 5, 2022 03:15
@yuwenma
Copy link
Contributor Author

yuwenma commented Apr 5, 2022

I like this callback approach a lot 👍

Thank you so much for the suggestions!

@yuwenma yuwenma force-pushed the set-namespace-v2 branch from fcba72c to f9c2dc8 Compare April 5, 2022 04:08
@yuwenma yuwenma force-pushed the set-namespace-v2 branch from f9c2dc8 to d9db966 Compare April 5, 2022 05:58
* 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
@yuwenma yuwenma force-pushed the set-namespace-v2 branch from 8148ca3 to 38ddcdb Compare April 5, 2022 23:14
namespace: irrelevant # skip since namespace does not match "example".
```

##### Selector Mode
Copy link
Contributor

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.

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'll do that in a follow up PR.

@yuwenma yuwenma merged commit 366d9be into kptdev:master Apr 6, 2022
yuwenma added a commit that referenced this pull request May 4, 2022
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