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

✨ feat: accept resource mutators in Move operation #7966

Merged

Conversation

takirala
Copy link
Contributor

@takirala takirala commented Jan 21, 2023

What this PR does / why we need it:

As a developer I would like to move capi resources from one cluster to another cluster and while doing so, i would want to control the namespace the resources are created in the target cluster. Right now, when i perform a move operation, clusters are always moved to the same namespace on target cluster as they are originally created in the originating cluster. I want to be able to control this so that I can move resources from multiple clusters to a single cluster and still organize them by namespace post move operation.

This PR takes the approach discussed in #7940 (comment) An alternative to this PR was initially proposed at #7941 but that approach seemed inflexible. So this PR overrides #7941

Which issue(s) this PR fixes:
Fixes #7940

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 21, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @takirala. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@fabriziopandini
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jan 23, 2023
@fabriziopandini
Copy link
Member

/ok-to-test
/area clusterctl

@k8s-ci-robot k8s-ci-robot added the area/clusterctl Issues or PRs related to clusterctl label Jan 23, 2023
@takirala
Copy link
Contributor Author

The tests are failing with

sigs.k8s.io/cluster-api/cmd/clusterctl/client/cluster
  Incompatible changes:
  - ObjectMover.Move: changed from func(string, Client, bool) error to func(string, []ResourceMutatorFunc, Client, bool) error
  Compatible changes:
  - ResourceMutatorFunc: added
sigs.k8s.io/cluster-api/cmd/clusterctl/client
  Incompatible changes:
  - MoveOptions: old is comparable, new is not
  Compatible changes:
  - MoveOptions.ExperimentalResourceMutators: added
make: *** [Makefile:568: apidiff] Error 1

I imagine this is expected as we need to change the interface. Any advice on how can I move forward or any other advice (accept the the breaking change VS making changes backwards compatibe - i don't know how though) cc @fabriziopandini @sbueringer ?!

@fabriziopandini
Copy link
Member

pull-cluster-api-apidiff-main is not a blocking job, it is just a warning for reviewers to look at what is changed in our public API

@dlipovetsky
Copy link
Contributor

Will we be able to release in a 1.3.x patch, given the clusterctl/client/cluster go API change? Or will this need to wait for the first 1.4 release?

@sbueringer
Copy link
Member

sbueringer commented Jan 24, 2023

In general our policy today doesn't allow feature backports (so it has to wait even if it wouldn't change the API)

Signed-off-by: Tarun Gupta Akirala <takirala@users.noreply.github.com>
Copy link
Contributor

@Jont828 Jont828 left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! I don't see anything that looks wrong on a first pass. Have you been able to try running this to move a cluster based on the use case you outlined?

api/v1beta1/cluster_types.go Outdated Show resolved Hide resolved
api/v1beta1/clusterclass_types.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/cluster/mover.go Outdated Show resolved Hide resolved
Signed-off-by: Tarun Gupta Akirala <takirala@users.noreply.github.com>
@takirala
Copy link
Contributor Author

takirala commented Jan 26, 2023

Have you been able to try running this to move a cluster based on the use case you outlined?

@Jont828 yes! I have validated the following scenario:

cluster A (from-kubeconfig cluster):

  • capi resources were in default namespace
  • they were backed by capa provider

cluster B (to-kubeconfig cluster):

  • capi components were pre installed and then move was performed
  • capi resources were moved to foobar namespace
  • everything was healthy (ensured foobar takijan25 Provisioned 68m status)
  • deleted the cluster and all its resources were cleaned up by capa pod running on cluster B.

@takirala
Copy link
Contributor Author

/test pull-cluster-api-test-mink8s-main

@takirala takirala requested review from Jont828 and removed request for enxebre, stmcginnis and ykakarap January 26, 2023 15:50
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 1, 2023
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: b5c246c338f721cc3b0ed465b723e21fca1327ef

Copy link
Member

@fabriziopandini fabriziopandini left a comment

Choose a reason for hiding this comment

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

I will be happy to get this in this release if we can address comments before the code freeze (around the 15th of March, please check the exact date)

cmd/clusterctl/client/cluster/mover.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/cluster/mover.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/cluster/mover.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/cluster/mover.go Show resolved Hide resolved
cmd/clusterctl/client/cluster/mover.go Show resolved Hide resolved
cmd/clusterctl/client/cluster/mover_test.go Outdated Show resolved Hide resolved
@dlipovetsky
Copy link
Contributor

While reviewing the code with @takirala, we realized that there is a small bug here, namely that we call ensureNamespaces with the unmutated objects, so we end up creating all the namespaces from the source cluster on the target cluster; these namespaces are not needed if mutators change the namespace.

https://github.com/kubernetes-sigs/cluster-api/pull/7966/files#diff-3458bf9e9c245fe801573500c33de535f05d3a5887f080a405b819e3c0fed415R337

Signed-off-by: Tarun Gupta Akirala <takirala@users.noreply.github.com>
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 10, 2023
@takirala
Copy link
Contributor Author

@fabriziopandini @ykakarap all the previous comments are addressed to the best of my understanding - could you PTAL again ? Thanks!

Signed-off-by: Tarun Gupta Akirala <takirala@users.noreply.github.com>
@takirala
Copy link
Contributor Author

takirala commented Apr 5, 2023

Ping @fabriziopandini @ykakarap can you PTAL again ? TIA!

@k8s-ci-robot
Copy link
Contributor

@takirala: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-cluster-api-apidiff-main a8b898f link false /test pull-cluster-api-apidiff-main

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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. I understand the commands that are listed here.

@takirala
Copy link
Contributor Author

takirala commented May 2, 2023

Ping @fabriziopandini @ykakarap can you PTAL again ? TIA!

@fabriziopandini
Copy link
Member

Great work, and sorry for the lack of answer but between KubeCon and other internal events April was mostly an AFK month for me.

Unfortunately, it seems that both @ykakarap and @Jont828 didn't have the bandwidth to take a look at this PR too, but I think the implementation is sound and if they have some feedback there is room to get them addressed before the release.
/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 8, 2023
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 7fd99f31dcdf3f58d85ac7ee6b2068ae663cedda

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fabriziopandini

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 8, 2023
@k8s-ci-robot k8s-ci-robot merged commit 813991b into kubernetes-sigs:main May 8, 2023
5 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.5 milestone May 8, 2023
@takirala takirala deleted the tga/support-resource-mutators branch May 11, 2023 17:01
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. area/clusterctl Issues or PRs related to clusterctl cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support moving capi resources to a configurable namespace
8 participants