From 5578e6e5bc141067ba1139d1876bd18fa5cb9bb1 Mon Sep 17 00:00:00 2001 From: Daniel Shubin Date: Tue, 19 Mar 2024 00:25:16 +0000 Subject: [PATCH] [PLAT-12935] Kubernetes only releases are disabled Summary: Kubernetes (helm chart) only releases are disabled, as we need a valid db build when performing an upgrade. This is done by adding helm charts in an "Incomplete" state, and automatically moving them to "active" when a db.tgz is added also Test Plan: unit tests added k8s release - disabled uploaded db.tgz - active Reviewers: muthu, anijhawan Reviewed By: muthu Subscribers: yugaware Differential Revision: https://phorge.dev.yugabyte.com/D33297 --- .../yugabyte/yw/common/ReleaseContainer.java | 8 +++++++ .../com/yugabyte/yw/common/ReleasesUtils.java | 5 +++-- .../java/com/yugabyte/yw/models/Release.java | 13 +++++++++-- .../com/yugabyte/yw/models/ReleasesTest.java | 22 +++++++++++++++++-- 4 files changed, 42 insertions(+), 6 deletions(-) diff --git a/managed/src/main/java/com/yugabyte/yw/common/ReleaseContainer.java b/managed/src/main/java/com/yugabyte/yw/common/ReleaseContainer.java index ff8e5349022f..66694babdc7b 100644 --- a/managed/src/main/java/com/yugabyte/yw/common/ReleaseContainer.java +++ b/managed/src/main/java/com/yugabyte/yw/common/ReleaseContainer.java @@ -447,4 +447,12 @@ private void setArtifactMatchingPackage(String ybPackage) { } throw new RuntimeException("Unable to find matching artifact for package " + ybPackage); } + + public boolean isActive() { + if (isLegacy()) { + return this.metadata.state == ReleaseManager.ReleaseState.ACTIVE; + } else { + return this.release.getState() == Release.ReleaseState.ACTIVE; + } + } } diff --git a/managed/src/main/java/com/yugabyte/yw/common/ReleasesUtils.java b/managed/src/main/java/com/yugabyte/yw/common/ReleasesUtils.java index 223098a53610..f4e62391605a 100644 --- a/managed/src/main/java/com/yugabyte/yw/common/ReleasesUtils.java +++ b/managed/src/main/java/com/yugabyte/yw/common/ReleasesUtils.java @@ -43,7 +43,8 @@ public class ReleasesUtils { public final String YB_PACKAGE_REGEX = "yugabyte-(?:ee-)?(.*)-(alma|centos|linux|el8|darwin)(.*).tar.gz"; - public final String YB_HELM_PACKAGE_REGEX = "(.*)yugabyte-(?:ee-)?(.*)-(helm)(.*).tar.gz"; + // We can see helm packages as either yugabyte-.tgz or yugabyte-version-helm.tgz + public final String YB_HELM_PACKAGE_REGEX = "yugabyte-(?:ee-)?(.*?)(?:-helm)?.tar.gz"; // Match release form 2.16.1.2 and return 2.16 or 2024.1.0.0 and return 2024 public final String YB_VERSION_TYPE_REGEX = "(2\\.\\d+|\\d\\d\\d\\d)"; @@ -254,7 +255,7 @@ public ExtractedMetadata metadataFromName(String fileName) { } } else if (helmPackage.find()) { em.platform = ReleaseArtifact.Platform.KUBERNETES; - em.version = helmPackage.group(2); + em.version = helmPackage.group(1); em.architecture = null; } else { throw new RuntimeException("failed to parse package " + fileName); diff --git a/managed/src/main/java/com/yugabyte/yw/models/Release.java b/managed/src/main/java/com/yugabyte/yw/models/Release.java index ba345c438102..3ecc9e42c2c0 100644 --- a/managed/src/main/java/com/yugabyte/yw/models/Release.java +++ b/managed/src/main/java/com/yugabyte/yw/models/Release.java @@ -56,6 +56,7 @@ public enum YbType { public enum ReleaseState { ACTIVE, DISABLED, + INCOMPLETE, DELETED } @@ -75,7 +76,7 @@ public static Release create(UUID releaseUUID, String version, String releaseTyp release.version = version; release.releaseType = releaseType; release.yb_type = YbType.YBDB; - release.state = ReleaseState.ACTIVE; + release.state = ReleaseState.INCOMPLETE; release.save(); return release; } @@ -105,7 +106,7 @@ public static Release createFromRequest(CreateRelease reqRelease) { } } release.releaseNotes = reqRelease.release_notes; - release.state = ReleaseState.ACTIVE; + release.state = ReleaseState.INCOMPLETE; release.save(); return release; @@ -153,6 +154,14 @@ public void addArtifact(ReleaseArtifact artifact) { artifact.getPlatform(), artifact.getArchitecture())); } artifact.setReleaseUUID(releaseUUID); + + // Move the state from incomplete to active when adding a Linux type. Kubernetes artifacts + // are not sufficient to make a release move into the "active" state. + if (artifact.getPlatform() == ReleaseArtifact.Platform.LINUX + && this.state == ReleaseState.INCOMPLETE) { + state = ReleaseState.ACTIVE; + save(); + } } public List getArtifacts() { diff --git a/managed/src/test/java/com/yugabyte/yw/models/ReleasesTest.java b/managed/src/test/java/com/yugabyte/yw/models/ReleasesTest.java index d793965c8026..f292266befe1 100644 --- a/managed/src/test/java/com/yugabyte/yw/models/ReleasesTest.java +++ b/managed/src/test/java/com/yugabyte/yw/models/ReleasesTest.java @@ -3,6 +3,7 @@ import static org.junit.Assert.assertEquals; import com.yugabyte.yw.cloud.PublicCloudConstants; +import com.yugabyte.yw.cloud.PublicCloudConstants.Architecture; import com.yugabyte.yw.common.FakeDBApplication; import com.yugabyte.yw.common.PlatformServiceException; import java.util.List; @@ -31,7 +32,8 @@ public void testBadRequest() { public void testAddArtifact() { Release release = Release.create(UUID.randomUUID(), "1.2.3", "LTS"); ReleaseArtifact artifact = - ReleaseArtifact.create("sha256", ReleaseArtifact.Platform.KUBERNETES, null, "file_url"); + ReleaseArtifact.create( + "sha256", ReleaseArtifact.Platform.LINUX, Architecture.x86_64, "file_url"); release.addArtifact(artifact); assertEquals(artifact.getReleaseUUID(), release.getReleaseUUID()); ReleaseArtifact newArtifact = ReleaseArtifact.get(artifact.getArtifactUUID()); @@ -42,7 +44,8 @@ public void testAddArtifact() { public void testGetArtifacts() { Release release = Release.create(UUID.randomUUID(), "1.2.3", "LTS"); ReleaseArtifact art1 = - ReleaseArtifact.create("sha256", ReleaseArtifact.Platform.KUBERNETES, null, "file_url"); + ReleaseArtifact.create( + "sha256", ReleaseArtifact.Platform.LINUX, Architecture.aarch64, "file_url"); ReleaseArtifact art2 = ReleaseArtifact.create( "sha257", @@ -79,4 +82,19 @@ public void testGetForArtifactType() { assertEquals(1, result2.size()); assertEquals(release2.getReleaseUUID(), result2.get(0).getReleaseUUID()); } + + @Test + public void testAddingK8S() { + Release release = Release.create(UUID.randomUUID(), "1.2.3", "LTS"); + ReleaseArtifact artifact = + ReleaseArtifact.create("sha256", ReleaseArtifact.Platform.KUBERNETES, null, "file_url"); + + release.addArtifact(artifact); + assertEquals(Release.ReleaseState.INCOMPLETE, release.getState()); + ReleaseArtifact art1 = + ReleaseArtifact.create( + "sha256", ReleaseArtifact.Platform.LINUX, Architecture.aarch64, "file_url"); + release.addArtifact(art1); + assertEquals(Release.ReleaseState.ACTIVE, release.getState()); + } }