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

Extend existing reattach-pv tool to allow using existing PVs to create newly named cluster. #6118

Merged
merged 9 commits into from
Oct 27, 2022

Conversation

naemono
Copy link
Contributor

@naemono naemono commented Oct 25, 2022

The proposed change would extend the existing reattach-pv tool to support creating a new cluster (clusterB) using PVs from a previously deleted cluster (clusterA), while maintaining the new name (clusterB).

Why is this needed?

If a user accidentally deletes clusterA, then immediately re-creates clusterA, it will be created with the same name, and new PersistentVolumes, becoming a new cluster. If that cluster begins ingesting data of some sort, then it will contain indexes with valid data that would need to be retained.

This change would allow the Released PVs of clusterA to be used to build a new clusterB, which contains the old data of clusterA, which would allow clusterA then to ingest the data of clusterB, and have the whole of the customer's data.

What is missing?

  • Readme is not yet updated.

Testing Done

  1. Create, delete, delete PVCs from prev cluster, then use tool to re-create existing cluster with existing PVs, verifying indexes with previous data exist. (previous functionality)
  2. Create kubectl apply -f es.yaml, delete kubectl delete es, delete PVCs from prev cluster, create again with same name kubectl apply -f es.yaml, then create 2nd cluster using existing PVs, and verify indexes with previous data exist.

…uster, from previous PVs from previously named cluster.
in findReleasedPVs, adjust the pv.claimref.name depending on whether re-creating missing cluster, or creating new cluster with existing cluster.
when updating PVs claim ref, also update the name, not only uid, and resourceVersion
@naemono naemono added the discuss We need to figure this out label Oct 25, 2022
@botelastic botelastic bot added the triage label Oct 25, 2022
Copy link
Contributor

@barkbay barkbay left a comment

Choose a reason for hiding this comment

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

This change would allow the Released PVs of clusterA to be used to build a new clusterB

I think an alternative would be to recreate clusterA, with the same name, but in a different namespace. The "only" manual step is to patch the PersistentVolumes to refer to the new namespace, with something along those lines:

  1. get the released PVs
 k get pv | grep Released
NAME   CAPACITY  ACCESS MODES   RECLAIM POLICY   STATUS      CLAIM                                                      STORAGECLASS         AGE
pv1   2Gi        RWO            Retain           Released    ns1/elasticsearch-data-elasticsearch-sample-es-default-0   retain-sc            17m
pv2   2Gi        RWO            Retain           Released    ns1/elasticsearch-data-elasticsearch-sample-es-default-2   retain-sc            17m
pv3   2Gi        RWO            Retain           Released    ns1/elasticsearch-data-elasticsearch-sample-es-default-1   retain-sc            17m
  1. patch the PVs with the new namespace
 kubectl patch pv pv1 pv2 pv3  -p '{"spec":{"claimRef": {"namespace": "ns2"} }}'
  1. Ensure that the new namespace ns2 does exist and is set in the metadata.namespace of the Elasticsearch manifest we want to recreate.

  2. Run the reattach-pv tool as usual

It involves some manual steps, maybe a bit error prone...

support/reattach-pv/main.go Outdated Show resolved Hide resolved
support/reattach-pv/main.go Outdated Show resolved Hide resolved
support/reattach-pv/main.go Outdated Show resolved Hide resolved
support/reattach-pv/main.go Outdated Show resolved Hide resolved
support/reattach-pv/main.go Outdated Show resolved Hide resolved
support/reattach-pv/main.go Outdated Show resolved Hide resolved
Move var to boolean, and rename more appropriately.
Move regex var out of loop.
Move github link to permalink.
Fix typo in comment.
@naemono naemono marked this pull request as ready for review October 26, 2022 13:52
use oldEsName in matchPVsWithClaim in Regex to ensure only volumes associated with old cluster are used.
Copy link
Contributor

@barkbay barkbay left a comment

Choose a reason for hiding this comment

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

LGTM 👍

support/reattach-pv/main.go Outdated Show resolved Hide resolved
support/reattach-pv/main.go Show resolved Hide resolved
support/reattach-pv/main.go Outdated Show resolved Hide resolved
support/reattach-pv/main.go Outdated Show resolved Hide resolved
support/reattach-pv/main.go Outdated Show resolved Hide resolved
support/reattach-pv/main.go Show resolved Hide resolved
@naemono naemono changed the title Draft: Extend existing reattach-pv tool Extend existing reattach-pv tool Oct 26, 2022
@barkbay barkbay added the >enhancement Enhancement of existing functionality label Oct 27, 2022
@botelastic botelastic bot removed the triage label Oct 27, 2022
Copy link
Contributor

@thbkrkr thbkrkr left a comment

Choose a reason for hiding this comment

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

Code LGTM. I left two comments to try to make the doc a little more clear and concise.

support/reattach-pv/README.md Show resolved Hide resolved
support/reattach-pv/README.md Outdated Show resolved Hide resolved
@thbkrkr thbkrkr removed the discuss We need to figure this out label Oct 27, 2022
@naemono
Copy link
Contributor Author

naemono commented Oct 27, 2022

README changes applied @thbkrkr . Let me know if all looks well. Thanks.

@naemono naemono merged commit 0bf5e43 into elastic:main Oct 27, 2022
@naemono naemono deleted the sdh-2142 branch October 27, 2022 15:13
@thbkrkr thbkrkr added the v2.6.0 label Nov 8, 2022
@naemono naemono changed the title Extend existing reattach-pv tool Extend existing reattach-pv tool to allow using existing PVs to create newly named cluster. Nov 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement Enhancement of existing functionality v2.6.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants