Skip to content

Commit

Permalink
[PLAT-15034][K8s] Add changes to apply master_join_existing_cluster g…
Browse files Browse the repository at this point in the history
…flag

Summary:
Added changes to set `master_join_existing_cluster` gflag with appropriate value.
https://docs.google.com/document/d/1Zo0viPJzXidaIuhflr1qi1TnV4Z_jO5IIghUJCAMLTk/edit?pli=1#heading=h.i435m0k67cgl

Create Universe
- For create universe, during Helm Install, we set it to `false`.
- During configure universe step, add a non-restart upgrade subtask to set the gflag to `true`.

For all other cases, the gflag stays `true`.

Test Plan: - Verified the gflag is set to true in master conf file after universe creation.

Reviewers: anijhawan, sanketh

Reviewed By: anijhawan

Subscribers: yugaware

Differential Revision: https://phorge.dev.yugabyte.com/D37412
  • Loading branch information
kv83821-yb committed Sep 25, 2024
1 parent 6ca8cc4 commit dca5923
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,32 @@ public void run() {
.setSubTaskGroupType(SubTaskGroupType.ConfigureUniverse);
}

createConfigureUniverseTasks(primaryCluster, null);
// Params for master_join_existing_universe gflag update
Runnable nonRestartMasterGflagUpgrade = null;
if (KubernetesUtil.isNonRestartGflagsUpgradeSupported(
primaryCluster.userIntent.ybSoftwareVersion)) {
KubernetesGflagsUpgradeCommonParams gflagsParams =
new KubernetesGflagsUpgradeCommonParams(universe, primaryCluster);
nonRestartMasterGflagUpgrade =
() ->
upgradePodsNonRestart(
universe.getName(),
// Use generated placement since gflagsParams placement will not have masters
// populated.
placement,
gflagsParams.getMasterAddresses(),
ServerType.MASTER,
gflagsParams.getYbSoftwareVersion(),
gflagsParams.getUniverseOverrides(),
gflagsParams.getAzOverrides(),
gflagsParams.isNewNamingStyle(),
false /* isReadOnlyCluster */,
gflagsParams.isEnableYbc(),
gflagsParams.getYbcSoftwareVersion());
}

createConfigureUniverseTasks(
primaryCluster, null /* masterNodes */, nonRestartMasterGflagUpgrade);
// Run all the tasks.
getRunnableTask().runSubTasks();
} catch (Throwable t) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public void run() {
.setSubTaskGroupType(SubTaskGroupType.ConfigureUniverse);
}

createConfigureUniverseTasks(primaryCluster, newMasters);
createConfigureUniverseTasks(primaryCluster, newMasters, null /* gflagsUpgradeSubtasks */);

// Create Load Balancer map to add nodes to load balancer
Map<LoadBalancerPlacement, LoadBalancerConfig> loadBalancerMap =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import play.libs.Json;

@Slf4j
Expand Down Expand Up @@ -749,9 +750,9 @@ private Map<UUID, ServerType> getServersToUpdateAzMap(
KubernetesPlacement placement, ServerType serverType) {
Map<UUID, ServerType> serversToUpdate = new HashMap<>();
if (serverType.equals(ServerType.EITHER)) {
placement.masters.keySet().parallelStream()
placement.masters.keySet().stream()
.forEach(azUUID -> serversToUpdate.put(azUUID, ServerType.MASTER));
placement.tservers.keySet().parallelStream()
placement.tservers.keySet().stream()
.forEach(
azUUID -> {
if (serversToUpdate.containsKey(azUUID)) {
Expand All @@ -760,14 +761,12 @@ private Map<UUID, ServerType> getServersToUpdateAzMap(
serversToUpdate.put(azUUID, ServerType.TSERVER);
}
});
} else if (serverType.equals(ServerType.MASTER)) {
placement.masters.keySet().stream()
.forEach(azUUID -> serversToUpdate.put(azUUID, ServerType.MASTER));
} else {
if (serverType.equals(ServerType.MASTER)) {
placement.masters.keySet().parallelStream()
.forEach(azUUID -> serversToUpdate.put(azUUID, ServerType.MASTER));
} else {
placement.tservers.keySet().parallelStream()
.forEach(azUUID -> serversToUpdate.put(azUUID, ServerType.TSERVER));
}
placement.tservers.keySet().stream()
.forEach(azUUID -> serversToUpdate.put(azUUID, ServerType.TSERVER));
}
return serversToUpdate;
}
Expand Down Expand Up @@ -1648,6 +1647,11 @@ public KubernetesCommandExecutor createKubernetesExecutorTaskForServerType(
params.universeDetails = taskParams();
params.universeConfig = universe.getConfig();
}
// Case when new Universe is being created, we set the gflag "master_join_existing_cluster"
// to 'false'.
if ((commandType == CommandType.HELM_INSTALL) && StringUtils.isNotEmpty(masterAddresses)) {
params.masterJoinExistingCluster = false;
}
params.masterPartition = masterPartition;
params.tserverPartition = tserverPartition;
params.enableNodeToNodeEncrypt = primaryCluster.userIntent.enableNodeToNodeEncrypt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -997,15 +997,18 @@ public SubTaskGroup createGFlagsOverrideTasks(
}

public void createConfigureUniverseTasks(
Cluster primaryCluster, @Nullable Collection<NodeDetails> masterNodes) {
Cluster primaryCluster,
@Nullable Collection<NodeDetails> masterNodes,
@Nullable Runnable gflagsUpgradeSubtasks) {
// Wait for a Master Leader to be elected.
createWaitForMasterLeaderTask().setSubTaskGroupType(SubTaskGroupType.ConfigureUniverse);

// Update the gflags to set master_join_existing_universe to true.
if (CollectionUtils.isNotEmpty(masterNodes)
&& primaryCluster.userIntent.providerType != CloudType.kubernetes) {
// Update the gflags to set master_join_existing_universe to false.
// It is not set for k8s universe because this restarts the pods.
createGFlagsOverrideTasks(masterNodes, ServerType.MASTER, null /* param customizer */);
} else if (gflagsUpgradeSubtasks != null) {
gflagsUpgradeSubtasks.run();
}

// Persist the placement info into the YB master leader.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ public static class Params extends UniverseTaskParams {
public boolean usePreviousGflagsChecksum = false;
public boolean createNamespacedService = false;
public Set<String> deleteServiceNames;
// Only set false for create universe case initially
public boolean masterJoinExistingCluster = true;
}

protected KubernetesCommandExecutor.Params taskParams() {
Expand Down Expand Up @@ -1138,6 +1140,9 @@ private String generateHelmOverride() {
XClusterConfigTaskBase.XCLUSTER_ROOT_CERTS_DIR_GFLAG,
taskUniverseDetails.xClusterInfo.sourceRootCertDirPath);
}
if (taskParams().masterJoinExistingCluster) {
masterGFlags.put(GFlagsUtil.MASTER_JOIN_EXISTING_UNIVERSE, "true");
}
if (!masterGFlags.isEmpty()) {
gflagOverrides.put("master", masterGFlags);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static boolean isNonRestartGflagsUpgradeSupported(String universeSoftware
MIN_VERSION_NON_RESTART_GFLAGS_UPGRADE_SUPPORT_STABLE,
MIN_VERSION_NON_RESTART_GFLAGS_UPGRADE_SUPPORT_PREVIEW,
true)
> 0;
>= 0;
}

public static boolean isNamespacedServiceSupported(String universeSoftwareVersion) {
Expand All @@ -82,7 +82,7 @@ public static boolean isNamespacedServiceSupported(String universeSoftwareVersio
MIN_VERSION_NAMESPACED_SERVICE_SUPPORT_STABLE,
MIN_VERSION_NAMESPACED_SERVICE_SUPPORT_PREVIEW,
true)
> 0;
>= 0;
}

// ToDo: Old k8s provider needs to be fixed, so that we can get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static com.yugabyte.yw.commissioner.tasks.subtasks.KubernetesCommandExecutor.CommandType.APPLY_SECRET;
import static com.yugabyte.yw.commissioner.tasks.subtasks.KubernetesCommandExecutor.CommandType.CREATE_NAMESPACE;
import static com.yugabyte.yw.commissioner.tasks.subtasks.KubernetesCommandExecutor.CommandType.HELM_INSTALL;
import static com.yugabyte.yw.commissioner.tasks.subtasks.KubernetesCommandExecutor.CommandType.HELM_UPGRADE;
import static com.yugabyte.yw.commissioner.tasks.subtasks.KubernetesCommandExecutor.CommandType.POD_INFO;
import static com.yugabyte.yw.common.ApiUtils.getTestUserIntent;
import static com.yugabyte.yw.common.AssertHelper.assertJsonEqual;
Expand Down Expand Up @@ -363,6 +364,8 @@ private void setupCommon() {
TaskType.InstallingThirdPartySoftware,
TaskType.WaitForServer,
TaskType.WaitForMasterLeader,
TaskType.KubernetesCommandExecutor,
TaskType.WaitForDuration,
TaskType.UpdatePlacementInfo,
TaskType.WaitForTServerHeartBeats,
TaskType.SwamperTargetsFileUpdate,
Expand All @@ -387,6 +390,8 @@ private List<JsonNode> getExpectedCreateUniverseTaskResults() {
Json.toJson(ImmutableMap.of()),
Json.toJson(ImmutableMap.of()),
Json.toJson(ImmutableMap.of()),
Json.toJson(ImmutableMap.of("commandType", HELM_UPGRADE.name())),
Json.toJson(ImmutableMap.of()),
Json.toJson(ImmutableMap.of()),
Json.toJson(ImmutableMap.of()),
Json.toJson(ImmutableMap.of("removeFile", false)),
Expand All @@ -406,7 +411,25 @@ private List<Integer> getTaskPositionsToSkip(boolean skipNamespace) {

private List<Integer> getTaskCountPerPosition(int namespaceTasks, int parallelTasks) {
return ImmutableList.of(
1, namespaceTasks, parallelTasks, parallelTasks, 0, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1);
1,
namespaceTasks,
parallelTasks,
parallelTasks,
0,
1,
1,
3,
1,
parallelTasks,
1,
1,
1,
1,
1,
1,
1,
1,
1);
}

private void assertTaskSequence(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,13 +310,6 @@ private Map<String, Object> getExpectedOverrides(boolean exposeAll) {
expectedOverrides.put("ip_version_support", "v6_only");
}

// For all tests but 1, value should default to true.
if (defaultUserIntent.enableExposingService == ExposingServiceState.UNEXPOSED) {
expectedOverrides.put("enableLoadBalancer", false);
} else {
expectedOverrides.put("enableLoadBalancer", true);
}

Map<String, Object> partition = new HashMap<>();
partition.put("tserver", 0);
partition.put("master", 0);
Expand All @@ -331,6 +324,7 @@ private Map<String, Object> getExpectedOverrides(boolean exposeAll) {
masterGFlags.put("placement_zone", defaultAZ.getCode());
masterGFlags.put(
"placement_uuid", defaultUniverse.getUniverseDetails().getPrimaryCluster().uuid.toString());
masterGFlags.put("master_join_existing_universe", "true");
gflagOverrides.put("master", masterGFlags);

// Tserver flags.
Expand All @@ -345,10 +339,6 @@ private Map<String, Object> getExpectedOverrides(boolean exposeAll) {
// Put all the flags together.
expectedOverrides.put("gflags", gflagOverrides);

Map<String, Object> ybcOverrides = new HashMap<>();
ybcOverrides.put("enabled", false);
expectedOverrides.put("ybc", ybcOverrides);

Map<String, String> universeConfig = defaultUniverse.getConfig();
if (universeConfig.getOrDefault(Universe.LABEL_K8S_RESOURCES, "false").equals("true")) {
expectedOverrides.put(
Expand Down Expand Up @@ -382,6 +372,14 @@ private Map<String, Object> getExpectedOverrides(boolean exposeAll) {
}
}
expectedOverrides.put("disableYsql", !defaultUserIntent.enableYSQL);

// For all tests but 1, value should default to true.
if (defaultUserIntent.enableExposingService == ExposingServiceState.UNEXPOSED) {
expectedOverrides.put("enableLoadBalancer", false);
} else {
expectedOverrides.put("enableLoadBalancer", true);
}

boolean helmLegacy =
Universe.HelmLegacy.valueOf(universeConfig.get(Universe.HELM2_LEGACY))
== Universe.HelmLegacy.V2TO3;
Expand All @@ -400,6 +398,10 @@ private Map<String, Object> getExpectedOverrides(boolean exposeAll) {
yugabytedUiInfo.put("metricsSnapshotter", metricsSnapshotterInfo);
expectedOverrides.put("yugabytedUi", yugabytedUiInfo);

Map<String, Object> ybcOverrides = new HashMap<>();
ybcOverrides.put("enabled", false);
expectedOverrides.put("ybc", ybcOverrides);

expectedOverrides.put("defaultServiceScope", "AZ");
return expectedOverrides;
}
Expand Down

0 comments on commit dca5923

Please sign in to comment.