Skip to content

Commit

Permalink
[PLAT-13681] Generate YBA Managed bundles in case the provider contai…
Browse files Browse the repository at this point in the history
…ns 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
  • Loading branch information
Vars-07 committed Apr 28, 2024
1 parent a5a05d0 commit c4056b7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
28 changes: 12 additions & 16 deletions managed/src/main/java/com/yugabyte/yw/common/AppInit.java
Expand Up @@ -210,23 +210,19 @@ public AppInit(
}
}
}
if (vmOsPatchingEnabled && defaultYbaOsVersion != null) {
if (vmOsPatchingEnabled) {
String providerCode = provider.getCode();
if (defaultYbaOsVersion.containsKey(providerCode)) {
Map<String, String> currOSVersionDBMap =
(Map<String, String>) 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<String, String> currOSVersionDBMap = null;
if (defaultYbaOsVersion != null && defaultYbaOsVersion.containsKey(providerCode)) {
currOSVersionDBMap = (Map<String, String>) 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);
}
}
}
Expand Down
29 changes: 29 additions & 0 deletions managed/src/main/java/com/yugabyte/yw/common/ImageBundleUtil.java
Expand Up @@ -246,6 +246,35 @@ public void migrateImageBundlesForProviders(Provider provider) {
enableVMOSPatching);
}

public boolean migrateYBADefaultBundles(
Map<String, String> 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<ImageBundle> 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<UUID, ImageBundle> collectUniversesImageBundles() {
Map<UUID, ImageBundle> imageBundleMap = new HashMap<>();
for (Customer customer : Customer.getAll()) {
Expand Down

0 comments on commit c4056b7

Please sign in to comment.