Skip to content

Commit 3fd0736

Browse files
[yugabyte#8950][Platform] Use matching helm chart version to operate on db k8s pods
Summary: Modify platform release metadata to associate a helm chart with each release version. Perform kubernetes universe operations (create, edit, upgrade, etc.), using the helm chart associated with the universe version. If there is no associated helm chart (and the universe version < 2.7), use special "legacy" helm chart to manage the universe. Test Plan: Launch previous version platform. Create k8s provider and universe. Stop the platform. Add two new releases to releases dir and add their helm charts to helm.packagePath. Start new version of platform and verify that the helm charts in the helm.packagePpath are now copied into the releases directory (alongside the release binary archives) and the platform stores the helm chart paths in the release metadata. Observe the releases page shows the helm chart paths for each release. Perform following operations and ensure the correct version of the helm chart is used for each step: 1. Increase # of pods (verify legacy 2.7 helm chart is used) 2. Upgrade universe (to newer version that has associated chart) 3. Modify gflags 4. Upgrade universe version (to other newer version) 5. Decrease # of pods 6. Modify gflags 7. Delete universe Run unit tests. Run K8s integration tests. Reviewers: arnav, sanketh Reviewed By: sanketh Subscribers: jason, yugaware, jenkins-bot Differential Revision: https://phabricator.dev.yugabyte.com/D12255
1 parent d99463e commit 3fd0736

24 files changed

+509
-137
lines changed

managed/devops/replicated.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ components:
294294
releases.path = "/opt/yugabyte/releases"
295295
docker.release = "/opt/yugabyte/release"
296296
thirdparty.packagePath = /opt/third-party
297-
helm.package = "/opt/yugabyte/helm/yugabyte-latest.tgz"
297+
helm.packagePath = "/opt/yugabyte/helm"
298298
health.check_interval_ms = 300000
299299
health.status_interval_ms = 43200000
300300
health.default_email = "YB_ALERTS_EMAIL_REPLACE"

managed/src/main/java/com/yugabyte/yw/commissioner/tasks/EditKubernetesUniverse.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,14 @@ public void updateRemainingPods(
286286
PlacementInfoUtil.computeMasterAddresses(
287287
newPI, newPlacement.masters, taskParams().nodePrefix, provider, masterRpcPort);
288288

289+
String ybSoftwareVersion = taskParams().getPrimaryCluster().userIntent.ybSoftwareVersion;
290+
289291
upgradePodsTask(
290292
newPlacement,
291293
masterAddresses,
292294
currPlacement,
293295
serverType,
294-
null,
296+
ybSoftwareVersion,
295297
DEFAULT_WAIT_TIME_MS,
296298
masterChanged,
297299
tserverChanged);

managed/src/main/java/com/yugabyte/yw/commissioner/tasks/KubernetesTaskBase.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ public void createPodsTask(
6464
ServerType serverType,
6565
PlacementInfo activeZones) {
6666

67+
String ybSoftwareVersion = taskParams().getPrimaryCluster().userIntent.ybSoftwareVersion;
68+
6769
boolean edit = currPlacement != null;
6870
boolean isMultiAz = masterAddresses != null;
6971

@@ -151,7 +153,7 @@ public void createPodsTask(
151153
tempPI,
152154
azCode,
153155
masterAddresses,
154-
null,
156+
ybSoftwareVersion,
155157
serverType,
156158
config,
157159
masterPartition,
@@ -189,6 +191,7 @@ public void createPodsTask(
189191
tempPI,
190192
azCode,
191193
masterAddresses,
194+
ybSoftwareVersion,
192195
config));
193196

194197
// Add zone to active configs.
@@ -324,6 +327,8 @@ public void deletePodsTask(
324327
KubernetesPlacement newPlacement,
325328
boolean userIntentChange) {
326329

330+
String ybSoftwareVersion = taskParams().getPrimaryCluster().userIntent.ybSoftwareVersion;
331+
327332
boolean edit = newPlacement != null;
328333
boolean isMultiAz = masterAddresses != null;
329334

@@ -370,7 +375,12 @@ public void deletePodsTask(
370375
newPlacement.masters.getOrDefault(azUUID, 0);
371376
helmDeletes.addTask(
372377
createKubernetesExecutorTask(
373-
CommandType.HELM_UPGRADE, tempPI, azCode, masterAddresses, config));
378+
CommandType.HELM_UPGRADE,
379+
tempPI,
380+
azCode,
381+
masterAddresses,
382+
ybSoftwareVersion,
383+
config));
374384
podsWait.addTask(
375385
createKubernetesCheckPodNumTask(
376386
KubernetesCheckNumPod.CommandType.WAIT_FOR_PODS,
@@ -472,22 +482,23 @@ public Set<NodeDetails> getPodsToRemove(
472482
// Create Kubernetes Executor task for creating the namespaces and pull secrets.
473483
public KubernetesCommandExecutor createKubernetesExecutorTask(
474484
KubernetesCommandExecutor.CommandType commandType, String az, Map<String, String> config) {
475-
return createKubernetesExecutorTask(commandType, null, az, null, config);
485+
return createKubernetesExecutorTask(commandType, null, az, null, null, config);
476486
}
477487

478488
// Create the Kubernetes Executor task for the helm deployments. (USED)
479489
public KubernetesCommandExecutor createKubernetesExecutorTask(
480-
KubernetesCommandExecutor.CommandType commandType,
490+
CommandType commandType,
481491
PlacementInfo pi,
482492
String az,
483493
String masterAddresses,
494+
String ybSoftwareVersion,
484495
Map<String, String> config) {
485496
return createKubernetesExecutorTaskForServerType(
486497
commandType,
487498
pi,
488499
az,
489500
masterAddresses,
490-
null,
501+
ybSoftwareVersion,
491502
ServerType.EITHER,
492503
config,
493504
0 /* master partition */,

managed/src/main/java/com/yugabyte/yw/commissioner/tasks/UpgradeKubernetesUniverse.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,15 @@ private SubTaskGroupType getTaskSubGroupType() {
124124
}
125125

126126
private void createUpgradeTask(UserIntent userIntent, Universe universe, PlacementInfo pi) {
127-
String version = null;
127+
String ybSoftwareVersion = null;
128128
boolean masterChanged = false;
129129
boolean tserverChanged = false;
130130
if (taskParams().taskType == UpgradeTaskType.Software) {
131-
version = taskParams().ybSoftwareVersion;
131+
ybSoftwareVersion = taskParams().ybSoftwareVersion;
132132
masterChanged = true;
133133
tserverChanged = true;
134134
} else {
135+
ybSoftwareVersion = userIntent.ybSoftwareVersion;
135136
if (!taskParams().masterGFlags.equals(userIntent.masterGFlags)) {
136137
masterChanged = true;
137138
}
@@ -164,7 +165,7 @@ private void createUpgradeTask(UserIntent userIntent, Universe universe, Placeme
164165
masterAddresses,
165166
null,
166167
ServerType.MASTER,
167-
version,
168+
ybSoftwareVersion,
168169
taskParams().sleepAfterMasterRestartMillis,
169170
masterChanged,
170171
tserverChanged);
@@ -179,7 +180,7 @@ private void createUpgradeTask(UserIntent userIntent, Universe universe, Placeme
179180
masterAddresses,
180181
null,
181182
ServerType.TSERVER,
182-
version,
183+
ybSoftwareVersion,
183184
taskParams().sleepAfterTServerRestartMillis,
184185
false /* master change is false since it has already been upgraded.*/,
185186
tserverChanged);

managed/src/main/java/com/yugabyte/yw/commissioner/tasks/subtasks/KubernetesCommandExecutor.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ public void run() {
174174
overridesFile = this.generateHelmOverride();
175175
response =
176176
kubernetesManager.helmInstall(
177+
taskParams().ybSoftwareVersion,
177178
config,
178179
taskParams().providerUUID,
179180
taskParams().nodePrefix,
@@ -185,7 +186,11 @@ public void run() {
185186
overridesFile = this.generateHelmOverride();
186187
response =
187188
kubernetesManager.helmUpgrade(
188-
config, taskParams().nodePrefix, taskParams().namespace, overridesFile);
189+
taskParams().ybSoftwareVersion,
190+
config,
191+
taskParams().nodePrefix,
192+
taskParams().namespace,
193+
overridesFile);
189194
flag = true;
190195
break;
191196
case UPDATE_NUM_NODES:

managed/src/main/java/com/yugabyte/yw/common/KubernetesManager.java

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import com.fasterxml.jackson.databind.JsonNode;
66
import com.google.common.collect.ImmutableList;
77
import com.google.inject.Inject;
8-
import com.yugabyte.yw.models.Provider;
8+
import java.io.File;
99
import java.util.ArrayList;
1010
import java.util.List;
1111
import java.util.Map;
@@ -16,17 +16,22 @@
1616

1717
@Singleton
1818
public class KubernetesManager {
19-
public static final Logger LOG = LoggerFactory.getLogger(KubernetesManager.class);
2019

21-
private static final long DEFAULT_TIMEOUT_SECS = 300;
20+
@Inject ReleaseManager releaseManager;
2221

2322
@Inject ShellProcessHandler shellProcessHandler;
2423

2524
@Inject play.Configuration appConfig;
2625

27-
private static String SERVICE_INFO_JSONPATH =
26+
public static final Logger LOG = LoggerFactory.getLogger(KubernetesManager.class);
27+
28+
private static final long DEFAULT_TIMEOUT_SECS = 300;
29+
30+
private static final String SERVICE_INFO_JSONPATH =
2831
"{.spec.clusterIP}|" + "{.status.*.ingress[0].ip}|{.status.*.ingress[0].hostname}";
2932

33+
private static final String LEGACY_HELM_CHART_FILENAME = "yugabyte-2.7-helm-legacy.tar.gz";
34+
3035
public ShellResponse createNamespace(Map<String, String> config, String universePrefix) {
3136
List<String> commandList = ImmutableList.of("kubectl", "create", "namespace", universePrefix);
3237
return execCommand(config, commandList);
@@ -54,17 +59,15 @@ public String getTimeout() {
5459
}
5560

5661
public ShellResponse helmInstall(
62+
String ybSoftwareVersion,
5763
Map<String, String> config,
5864
UUID providerUUID,
5965
String universePrefix,
6066
String namespace,
6167
String overridesFile) {
62-
String helmPackagePath = appConfig.getString("yb.helm.package");
63-
if (helmPackagePath == null || helmPackagePath.isEmpty()) {
64-
throw new RuntimeException("Helm Package path not provided.");
65-
}
66-
Provider provider = Provider.get(providerUUID);
67-
Map<String, String> configProvider = provider.getConfig();
68+
69+
String helmPackagePath = this.getHelmPackagePath(ybSoftwareVersion);
70+
6871
List<String> commandList =
6972
ImmutableList.of(
7073
"helm",
@@ -180,11 +183,14 @@ public ShellResponse runGetSecret(
180183
}
181184

182185
public ShellResponse helmUpgrade(
183-
Map<String, String> config, String universePrefix, String namespace, String overridesFile) {
184-
String helmPackagePath = appConfig.getString("yb.helm.package");
185-
if (helmPackagePath == null || helmPackagePath.isEmpty()) {
186-
throw new RuntimeException("Helm Package path not provided.");
187-
}
186+
String ybSoftwareVersion,
187+
Map<String, String> config,
188+
String universePrefix,
189+
String namespace,
190+
String overridesFile) {
191+
192+
String helmPackagePath = this.getHelmPackagePath(ybSoftwareVersion);
193+
188194
List<String> commandList =
189195
ImmutableList.of(
190196
"helm",
@@ -257,4 +263,38 @@ private ShellResponse execCommand(Map<String, String> config, List<String> comma
257263
String description = String.join(" ", command);
258264
return shellProcessHandler.run(command, config, description);
259265
}
266+
267+
public String getHelmPackagePath(String ybSoftwareVersion) {
268+
String helmPackagePath = null;
269+
270+
// Get helm package filename from release metadata.
271+
ReleaseManager.ReleaseMetadata releaseMetadata =
272+
releaseManager.getReleaseByVersion(ybSoftwareVersion);
273+
if (releaseMetadata != null) {
274+
helmPackagePath = releaseMetadata.chartPath;
275+
}
276+
277+
if (helmPackagePath == null || helmPackagePath.isEmpty()) {
278+
// TODO: The "legacy" helm chart is included in the yugaware container build to ensure that
279+
// universes deployed using previous versions of the platform (that did not use versioned
280+
// helm charts) will still be usable after upgrading to newer versions of the platform (that
281+
// use versioned helm charts). We can (and should) remove this special case once all customers
282+
// that use the k8s provider have upgraded their platforms and universes to versions > 2.7.
283+
if (Util.compareYbVersions(ybSoftwareVersion, "2.8.0.0") < 0) {
284+
helmPackagePath =
285+
new File(appConfig.getString("yb.helm.packagePath"), LEGACY_HELM_CHART_FILENAME)
286+
.toString();
287+
} else {
288+
throw new RuntimeException("Helm Package path not found for release: " + ybSoftwareVersion);
289+
}
290+
}
291+
292+
// Ensure helm package file actually exists.
293+
File helmPackage = new File(helmPackagePath);
294+
if (!helmPackage.exists()) {
295+
throw new RuntimeException("Helm Package file not found: " + helmPackagePath);
296+
}
297+
298+
return helmPackagePath;
299+
}
260300
}

0 commit comments

Comments
 (0)