Skip to content

Commit

Permalink
[PLAT-13921] [K8] [UI] Universe action tasks are disabled after a fai…
Browse files Browse the repository at this point in the history
…led shrink rr node task

Summary: Fixed validation logic for k8s universe edit (decrease volume restriction should work for both primary and async clusters)

Test Plan: sbt test

Reviewers: cwang

Reviewed By: cwang

Subscribers: yugaware

Differential Revision: https://phorge.dev.yugabyte.com/D37771
  • Loading branch information
yorq committed Sep 5, 2024
1 parent f24eb10 commit ee18df8
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1543,8 +1543,20 @@ public void verifyParams(UniverseOpType opType) {
PlacementInfoUtil.verifyNumNodesAndRF(
cluster.clusterType, cluster.userIntent.numNodes, cluster.userIntent.replicationFactor);

// Verify kubernetes overrides.
if (cluster.userIntent.providerType == CloudType.kubernetes) {
if (opType == UniverseOpType.EDIT
&& cluster.userIntent.deviceInfo != null
&& cluster.userIntent.deviceInfo.volumeSize != null
&& cluster.userIntent.deviceInfo.volumeSize
< univCluster.userIntent.deviceInfo.volumeSize) {
String errMsg =
String.format(
"Cannot decrease disk size in a Kubernetes cluster (%dG to %dG)",
univCluster.userIntent.deviceInfo.volumeSize,
cluster.userIntent.deviceInfo.volumeSize);
throw new IllegalStateException(errMsg);
}
// Verify kubernetes overrides.
if (cluster.clusterType == ClusterType.ASYNC) {
// Readonly cluster should not have kubernetes overrides.
if (StringUtils.isNotBlank(cluster.userIntent.universeOverrides)
Expand All @@ -1554,17 +1566,6 @@ public void verifyParams(UniverseOpType opType) {
}
} else {
if (opType == UniverseOpType.EDIT) {
if (cluster.userIntent.deviceInfo != null
&& cluster.userIntent.deviceInfo.volumeSize != null
&& cluster.userIntent.deviceInfo.volumeSize
< univCluster.userIntent.deviceInfo.volumeSize) {
String errMsg =
String.format(
"Cannot decrease disk size in a Kubernetes cluster (%dG to %dG)",
univCluster.userIntent.deviceInfo.volumeSize,
cluster.userIntent.deviceInfo.volumeSize);
throw new IllegalStateException(errMsg);
}
// During edit universe, overrides can't be changed.
Map<String, String> curUnivOverrides =
HelmUtils.flattenMap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import static com.yugabyte.yw.models.TaskInfo.State.Success;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
Expand All @@ -33,6 +34,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.net.HostAndPort;
import com.yugabyte.yw.commissioner.Common;
import com.yugabyte.yw.commissioner.tasks.UniverseTaskBase.ServerType;
import com.yugabyte.yw.common.ApiUtils;
import com.yugabyte.yw.common.PlacementInfoUtil;
Expand Down Expand Up @@ -62,6 +64,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -909,6 +912,46 @@ public void testShrinkUniverseDiskCheckTaskFailsModifiedTargetUsage() {
assertTrue(subTaskInfo.getErrorMessage().contains(expectedMsg));
}

@Test
public void testVolumeDecreaseForRRIsForbidden() {
setupUniverseSingleAZ(/* Create Masters */ true);
UniverseDefinitionTaskParams.UserIntent userIntent =
new UniverseDefinitionTaskParams.UserIntent();
userIntent.numNodes = 1;
userIntent.replicationFactor = 1;
userIntent.deviceInfo = ApiUtils.getDummyDeviceInfo(1, 100);
userIntent.provider = kubernetesProvider.getUuid().toString();
userIntent.providerType = Common.CloudType.kubernetes;
userIntent.regionList =
Collections.singletonList(Region.getByCode(kubernetesProvider, "region-1").getUuid());
PlacementInfo pi = new PlacementInfo();
PlacementInfoUtil.addPlacementZone(
AvailabilityZone.getByCode(kubernetesProvider, "az-1").getUuid(), pi, 1, 1, true);
defaultUniverse =
Universe.saveDetails(
defaultUniverse.getUniverseUUID(),
ApiUtils.mockUniverseUpdaterWithReadReplica(userIntent, pi));

UniverseDefinitionTaskParams taskParams = new UniverseDefinitionTaskParams();
taskParams.setUniverseUUID(defaultUniverse.getUniverseUUID());
taskParams.expectedUniverseVersion = defaultUniverse.getVersion();
taskParams.nodeDetailsSet = defaultUniverse.getUniverseDetails().nodeDetailsSet;
taskParams.clusters =
Collections.singletonList(
defaultUniverse.getUniverseDetails().getReadOnlyClusters().get(0));
taskParams.getReadOnlyClusters().get(0).userIntent.deviceInfo.volumeSize--;
taskParams.nodePrefix = NODE_PREFIX;
Exception expected = null;
try {
UUID taskUUID = commissioner.submit(TaskType.EditKubernetesUniverse, taskParams);
waitForTask(taskUUID);
} catch (Exception e) {
expected = e;
}
assertNotNull(expected);
assertTrue(expected.getMessage().contains("Cannot decrease disk size in a Kubernetes cluster"));
}

private void mockMetrics(
Set<NodeDetails> nodeDetails, ServerType serverType, double totalUsedSizeGb) {
List<MetricQueryResponse.Entry> sizeResponseList = new ArrayList<>();
Expand Down

0 comments on commit ee18df8

Please sign in to comment.