diff --git a/managed/src/main/java/com/yugabyte/yw/commissioner/tasks/CreateKubernetesUniverse.java b/managed/src/main/java/com/yugabyte/yw/commissioner/tasks/CreateKubernetesUniverse.java index 1f46a6a85ff1..f612214f4001 100644 --- a/managed/src/main/java/com/yugabyte/yw/commissioner/tasks/CreateKubernetesUniverse.java +++ b/managed/src/main/java/com/yugabyte/yw/commissioner/tasks/CreateKubernetesUniverse.java @@ -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) { diff --git a/managed/src/main/java/com/yugabyte/yw/commissioner/tasks/CreateUniverse.java b/managed/src/main/java/com/yugabyte/yw/commissioner/tasks/CreateUniverse.java index 8a1818098c8b..e6d4ef7cb8a5 100644 --- a/managed/src/main/java/com/yugabyte/yw/commissioner/tasks/CreateUniverse.java +++ b/managed/src/main/java/com/yugabyte/yw/commissioner/tasks/CreateUniverse.java @@ -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 loadBalancerMap = diff --git a/managed/src/main/java/com/yugabyte/yw/commissioner/tasks/KubernetesTaskBase.java b/managed/src/main/java/com/yugabyte/yw/commissioner/tasks/KubernetesTaskBase.java index 633d2281bde6..1361706e629c 100644 --- a/managed/src/main/java/com/yugabyte/yw/commissioner/tasks/KubernetesTaskBase.java +++ b/managed/src/main/java/com/yugabyte/yw/commissioner/tasks/KubernetesTaskBase.java @@ -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 @@ -749,9 +750,9 @@ private Map getServersToUpdateAzMap( KubernetesPlacement placement, ServerType serverType) { Map 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)) { @@ -760,14 +761,12 @@ private Map 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; } @@ -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; diff --git a/managed/src/main/java/com/yugabyte/yw/commissioner/tasks/UniverseDefinitionTaskBase.java b/managed/src/main/java/com/yugabyte/yw/commissioner/tasks/UniverseDefinitionTaskBase.java index 9a6a898f5f45..84ff3be96a84 100644 --- a/managed/src/main/java/com/yugabyte/yw/commissioner/tasks/UniverseDefinitionTaskBase.java +++ b/managed/src/main/java/com/yugabyte/yw/commissioner/tasks/UniverseDefinitionTaskBase.java @@ -997,15 +997,18 @@ public SubTaskGroup createGFlagsOverrideTasks( } public void createConfigureUniverseTasks( - Cluster primaryCluster, @Nullable Collection masterNodes) { + Cluster primaryCluster, + @Nullable Collection 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. diff --git a/managed/src/main/java/com/yugabyte/yw/commissioner/tasks/subtasks/KubernetesCommandExecutor.java b/managed/src/main/java/com/yugabyte/yw/commissioner/tasks/subtasks/KubernetesCommandExecutor.java index 0373b9f3cc75..17e4a145b911 100644 --- a/managed/src/main/java/com/yugabyte/yw/commissioner/tasks/subtasks/KubernetesCommandExecutor.java +++ b/managed/src/main/java/com/yugabyte/yw/commissioner/tasks/subtasks/KubernetesCommandExecutor.java @@ -243,6 +243,8 @@ public static class Params extends UniverseTaskParams { public boolean usePreviousGflagsChecksum = false; public boolean createNamespacedService = false; public Set deleteServiceNames; + // Only set false for create universe case initially + public boolean masterJoinExistingCluster = true; } protected KubernetesCommandExecutor.Params taskParams() { @@ -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); } diff --git a/managed/src/main/java/com/yugabyte/yw/common/KubernetesUtil.java b/managed/src/main/java/com/yugabyte/yw/common/KubernetesUtil.java index d2d8f1dff05d..ec55f3d2e0fc 100644 --- a/managed/src/main/java/com/yugabyte/yw/common/KubernetesUtil.java +++ b/managed/src/main/java/com/yugabyte/yw/common/KubernetesUtil.java @@ -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) { @@ -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 diff --git a/managed/src/test/java/com/yugabyte/yw/commissioner/tasks/CreateKubernetesUniverseTest.java b/managed/src/test/java/com/yugabyte/yw/commissioner/tasks/CreateKubernetesUniverseTest.java index 6113ef4e5ac0..e9590866f14d 100644 --- a/managed/src/test/java/com/yugabyte/yw/commissioner/tasks/CreateKubernetesUniverseTest.java +++ b/managed/src/test/java/com/yugabyte/yw/commissioner/tasks/CreateKubernetesUniverseTest.java @@ -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; @@ -363,6 +364,8 @@ private void setupCommon() { TaskType.InstallingThirdPartySoftware, TaskType.WaitForServer, TaskType.WaitForMasterLeader, + TaskType.KubernetesCommandExecutor, + TaskType.WaitForDuration, TaskType.UpdatePlacementInfo, TaskType.WaitForTServerHeartBeats, TaskType.SwamperTargetsFileUpdate, @@ -387,6 +390,8 @@ private List 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)), @@ -406,7 +411,25 @@ private List getTaskPositionsToSkip(boolean skipNamespace) { private List 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( diff --git a/managed/src/test/java/com/yugabyte/yw/commissioner/tasks/subtasks/KubernetesCommandExecutorTest.java b/managed/src/test/java/com/yugabyte/yw/commissioner/tasks/subtasks/KubernetesCommandExecutorTest.java index 1f94f97e80ae..aca147fab54d 100644 --- a/managed/src/test/java/com/yugabyte/yw/commissioner/tasks/subtasks/KubernetesCommandExecutorTest.java +++ b/managed/src/test/java/com/yugabyte/yw/commissioner/tasks/subtasks/KubernetesCommandExecutorTest.java @@ -310,13 +310,6 @@ private Map 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 partition = new HashMap<>(); partition.put("tserver", 0); partition.put("master", 0); @@ -331,6 +324,7 @@ private Map 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. @@ -345,10 +339,6 @@ private Map getExpectedOverrides(boolean exposeAll) { // Put all the flags together. expectedOverrides.put("gflags", gflagOverrides); - Map ybcOverrides = new HashMap<>(); - ybcOverrides.put("enabled", false); - expectedOverrides.put("ybc", ybcOverrides); - Map universeConfig = defaultUniverse.getConfig(); if (universeConfig.getOrDefault(Universe.LABEL_K8S_RESOURCES, "false").equals("true")) { expectedOverrides.put( @@ -382,6 +372,14 @@ private Map 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; @@ -400,6 +398,10 @@ private Map getExpectedOverrides(boolean exposeAll) { yugabytedUiInfo.put("metricsSnapshotter", metricsSnapshotterInfo); expectedOverrides.put("yugabytedUi", yugabytedUiInfo); + Map ybcOverrides = new HashMap<>(); + ybcOverrides.put("enabled", false); + expectedOverrides.put("ybc", ybcOverrides); + expectedOverrides.put("defaultServiceScope", "AZ"); return expectedOverrides; }