From c4056b7ad8065d2f057d555be01c1916c8d7bf3f Mon Sep 17 00:00:00 2001 From: Shubham Varshney Date: Sun, 28 Apr 2024 16:22:53 +0530 Subject: [PATCH] [PLAT-13681] Generate YBA Managed bundles in case the provider contains legacy bundles Summary: Before the VM_OS_Patching flag is enabled we do not set the versions in the `yugaware_property` because of which the bundles were not getting generated even in case YBA moved to a higher version. With this diff, we fix the same & generates the bundle. 1. If the version specified in the `yugaware_property` does not match the one present in `CloudImageBundleSetup`. 2. Bundles are legacy one without the metadata. Test Plan: Created a provider in YBA 2.18 Migrated the same to the YBA version having the patch applied. Verified that the bundles are getting generated as expected. Changed the version in YBA metadata manually Verified that the bundles are generated as expected. Reviewers: amalyshev Reviewed By: amalyshev Subscribers: yugaware Differential Revision: https://phorge.dev.yugabyte.com/D34469 --- .../java/com/yugabyte/yw/common/AppInit.java | 28 ++++++++---------- .../yugabyte/yw/common/ImageBundleUtil.java | 29 +++++++++++++++++++ 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/managed/src/main/java/com/yugabyte/yw/common/AppInit.java b/managed/src/main/java/com/yugabyte/yw/common/AppInit.java index 645c23b1415..d2d402108db 100644 --- a/managed/src/main/java/com/yugabyte/yw/common/AppInit.java +++ b/managed/src/main/java/com/yugabyte/yw/common/AppInit.java @@ -210,23 +210,19 @@ public AppInit( } } } - if (vmOsPatchingEnabled && defaultYbaOsVersion != null) { + if (vmOsPatchingEnabled) { String providerCode = provider.getCode(); - if (defaultYbaOsVersion.containsKey(providerCode)) { - Map currOSVersionDBMap = - (Map) defaultYbaOsVersion.get(providerCode); - if (currOSVersionDBMap != null - && currOSVersionDBMap.containsKey("version") - && !currOSVersionDBMap - .get("version") - .equals(CloudImageBundleSetup.CLOUD_OS_MAP.get(providerCode).getVersion())) { - // In case defaultYbaAmiVersion is not null & not equal to version specified in - // CloudImageBundleSetup.YBA_AMI_VERSION, we will check in the provider bundles - // & migrate all the YBA_DEFAULT -> YBA_DEPRECATED, & at the same time generating - // new bundle with the latest AMIs. This will only hold in case the provider - // does not have CUSTOM bundles. - imageBundleUtil.migrateImageBundlesForProviders(provider); - } + Map currOSVersionDBMap = null; + if (defaultYbaOsVersion != null && defaultYbaOsVersion.containsKey(providerCode)) { + currOSVersionDBMap = (Map) defaultYbaOsVersion.get(providerCode); + } + if (imageBundleUtil.migrateYBADefaultBundles(currOSVersionDBMap, provider)) { + // In case defaultYbaAmiVersion is not null & not equal to version specified in + // CloudImageBundleSetup.YBA_AMI_VERSION, we will check in the provider bundles + // & migrate all the YBA_DEFAULT -> YBA_DEPRECATED, & at the same time generating + // new bundle with the latest AMIs. This will only hold in case the provider + // does not have CUSTOM bundles. + imageBundleUtil.migrateImageBundlesForProviders(provider); } } } diff --git a/managed/src/main/java/com/yugabyte/yw/common/ImageBundleUtil.java b/managed/src/main/java/com/yugabyte/yw/common/ImageBundleUtil.java index 4b2dbc9fbc5..0eeaf2fb7be 100644 --- a/managed/src/main/java/com/yugabyte/yw/common/ImageBundleUtil.java +++ b/managed/src/main/java/com/yugabyte/yw/common/ImageBundleUtil.java @@ -246,6 +246,35 @@ public void migrateImageBundlesForProviders(Provider provider) { enableVMOSPatching); } + public boolean migrateYBADefaultBundles( + Map currOSVersionDBMap, Provider provider) { + String providerCode = provider.getCode(); + if (currOSVersionDBMap != null + && currOSVersionDBMap.containsKey("version") + && !currOSVersionDBMap + .get("version") + .equals(CloudImageBundleSetup.CLOUD_OS_MAP.get(providerCode).getVersion())) { + return true; + } + + List getYbaDefaultImageBundles = + ImageBundle.getYBADefaultBundles(provider.getUuid()); + if (getYbaDefaultImageBundles.size() != 0) { + ImageBundle ybaDefaultBundle = getYbaDefaultImageBundles.get(0); + if (ybaDefaultBundle.getMetadata() == null + || (ybaDefaultBundle.getMetadata() != null + && ybaDefaultBundle.getMetadata().getVersion() != null + && ybaDefaultBundle.getMetadata().getVersion() + != CloudImageBundleSetup.CLOUD_OS_MAP.get(providerCode).getVersion())) { + return true; + } + } else if (getYbaDefaultImageBundles.size() == 0) { + return true; + } + + return false; + } + public Map collectUniversesImageBundles() { Map imageBundleMap = new HashMap<>(); for (Customer customer : Customer.getAll()) {