From 54353876234609f5556cfb5bc73c77443f50881b Mon Sep 17 00:00:00 2001 From: Chris Friesen Date: Mon, 22 Apr 2024 11:37:37 -0600 Subject: [PATCH] Add support for symlinks instead of bindmounts for version control We have been using bind mounts to select K8s versions, but they are not well supported by Puppet and suffer from fragility since you cannot remove a bind mount while an executable is still running from it. They also need to be re-created when creating an OSTree hotfix or when applying software patches. Symlinks suffer from no such issues, they just need to be created in a filesystem that is not managed by OSTree. Accordingly, make the current bindmount-related code conditional on the bindmount directory actually being present. That way the code will not complain when we switch to using symlinks. Story: 2011047 Task: 49917 TEST PLAN: PASS: Run the modified code snippet standalone on system where /usr/local/kubernetes/current/ exists, ensure it attempts to run the two mount commands. PASS: Run the modified code snippet standalone on system where /usr/local/kubernetes/current/ does not exist, ensure it does not attempt to run the two mount commands. Change-Id: I1dfea974ae9532cf316bb1fac701ae93f5507681 --- software/software/ostree_utils.py | 19 +++++++++++-------- .../cgcs-patch/cgcs_patch/ostree_utils.py | 19 +++++++++++-------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/software/software/ostree_utils.py b/software/software/ostree_utils.py index c5e713e1..5e36e6ad 100644 --- a/software/software/ostree_utils.py +++ b/software/software/ostree_utils.py @@ -287,14 +287,17 @@ def mount_new_deployment(deployment_dir): LOG.warning(info_msg) raise OSTreeCommandFail(msg) finally: - try: - sh.mount("/usr/local/kubernetes/current/stage1") - sh.mount("/usr/local/kubernetes/current/stage2") - except sh.ErrorReturnCode: - msg = "Failed to mount kubernetes. Please manually run these commands:\n" \ - "sudo mount /usr/local/kubernetes/current/stage1\n" \ - "sudo mount /usr/local/kubernetes/current/stage2\n" - LOG.info(msg) + # Handle the switch from bind mounts to symlinks for K8s versions. + # Can be removed once the switch is complete. + if os.path.isdir('/usr/local/kubernetes/current'): + try: + sh.mount("/usr/local/kubernetes/current/stage1") + sh.mount("/usr/local/kubernetes/current/stage2") + except sh.ErrorReturnCode: + msg = "Failed to mount kubernetes. Please manually run these commands:\n" \ + "sudo mount /usr/local/kubernetes/current/stage1\n" \ + "sudo mount /usr/local/kubernetes/current/stage2\n" + LOG.info(msg) def delete_older_deployments(): diff --git a/sw-patch/cgcs-patch/cgcs_patch/ostree_utils.py b/sw-patch/cgcs-patch/cgcs_patch/ostree_utils.py index 8a373b84..c406c7f7 100644 --- a/sw-patch/cgcs-patch/cgcs_patch/ostree_utils.py +++ b/sw-patch/cgcs-patch/cgcs_patch/ostree_utils.py @@ -313,14 +313,17 @@ def mount_new_deployment(deployment_dir): LOG.warning(info_msg) raise OSTreeCommandFail(msg) finally: - try: - sh.mount("/usr/local/kubernetes/current/stage1") - sh.mount("/usr/local/kubernetes/current/stage2") - except sh.ErrorReturnCode: - msg = "Failed to mount kubernetes. Please manually run these commands:\n" \ - "sudo mount /usr/local/kubernetes/current/stage1\n" \ - "sudo mount /usr/local/kubernetes/current/stage2\n" - LOG.info(msg) + # Handle the switch from bind mounts to symlinks for K8s versions. + # Can be removed once the switch is complete. + if os.path.isdir('/usr/local/kubernetes/current'): + try: + sh.mount("/usr/local/kubernetes/current/stage1") + sh.mount("/usr/local/kubernetes/current/stage2") + except sh.ErrorReturnCode: + msg = "Failed to mount kubernetes. Please manually run these commands:\n" \ + "sudo mount /usr/local/kubernetes/current/stage1\n" \ + "sudo mount /usr/local/kubernetes/current/stage2\n" + LOG.info(msg) def delete_older_deployments():