Skip to content

Commit 7428555

Browse files
authored
Merge branch 'yugabyte:master' into master
2 parents 5b0e20b + cc9e979 commit 7428555

File tree

55 files changed

+2293
-389
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2293
-389
lines changed

managed/build.sbt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ libraryDependencies ++= Seq(
242242
"io.fabric8" % "kubernetes-client" % "6.8.0",
243243
"io.fabric8" % "kubernetes-client-api" % "6.8.0",
244244
"io.fabric8" % "kubernetes-model" % "6.8.0",
245+
"io.fabric8" % "kubernetes-server-mock" % "6.8.0",
245246
"org.modelmapper" % "modelmapper" % "2.4.4",
246247
"com.datadoghq" % "datadog-api-client" % "2.25.0" classifier "shaded-jar",
247248
"javax.xml.bind" % "jaxb-api" % "2.3.1",
@@ -468,7 +469,7 @@ generateCrdObjects / fileInputs += baseDirectory.value.toGlob /
468469
generateCrdObjects := {
469470
if (generateCrdObjects.inputFileChanges.hasChanges) {
470471
ybLog("Generating crd classes...")
471-
val generatedSourcesDirectory = baseDirectory.value / "target/scala-2.13/"
472+
val generatedSourcesDirectory = baseDirectory.value / "target/operatorCRD/"
472473
val command = s"mvn generate-sources -DoutputDirectory=$generatedSourcesDirectory"
473474
val status = Process(command, baseDirectory.value / "src/main/java/com/yugabyte/yw/common/operator/").!
474475
status
@@ -477,6 +478,7 @@ generateCrdObjects := {
477478
0
478479
}
479480
}
481+
Compile / unmanagedSourceDirectories += baseDirectory.value / "target/operatorCRD/"
480482

481483
downloadThirdPartyDeps := {
482484
ybLog("Downloading third-party dependencies...")

managed/node-agent/app/task/install_otel_collector.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,13 @@ func (h *InstallOtelCollector) Handle(ctx context.Context) (*pb.DescribeTaskResp
8787
return nil, err
8888
}
8989

90-
// 4) stop the systemd-unit if it's running.
91-
if err := module.StopSystemdService(ctx, h.username, OtelCollectorService, h.logOut); err != nil {
90+
// 4) Stop and disable the systemd service
91+
if err := module.DisableSystemdService(
92+
ctx,
93+
h.username,
94+
OtelCollectorService,
95+
"", // Don't remove the unit file - we need it for re-enabling later
96+
h.logOut); err != nil {
9297
return nil, err
9398
}
9499

@@ -99,9 +104,14 @@ func (h *InstallOtelCollector) Handle(ctx context.Context) (*pb.DescribeTaskResp
99104
return nil, err
100105
}
101106

102-
// 6) Start and enable the otel-collector service.
103-
if err = module.StartSystemdService(ctx, h.username, OtelCollectorService, h.logOut); err != nil {
104-
return nil, err
107+
// 6) Start and enable the service only if config file exists
108+
if h.param.GetOtelColConfigFile() != "" {
109+
if err = module.StartSystemdService(ctx, h.username, OtelCollectorService, h.logOut); err != nil {
110+
return nil, err
111+
}
112+
if err = module.EnableSystemdService(ctx, h.username, OtelCollectorService, h.logOut); err != nil {
113+
return nil, err
114+
}
105115
}
106116
return nil, nil
107117
}

managed/src/main/java/MainModule.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@
8484
import com.yugabyte.yw.common.operator.OperatorStatusUpdaterFactory;
8585
import com.yugabyte.yw.common.operator.YBInformerFactory;
8686
import com.yugabyte.yw.common.operator.YBReconcilerFactory;
87+
import com.yugabyte.yw.common.operator.utils.KubernetesClientFactory;
8788
import com.yugabyte.yw.common.operator.utils.OperatorUtils;
89+
import com.yugabyte.yw.common.operator.utils.UniverseImporter;
8890
import com.yugabyte.yw.common.rbac.PermissionUtil;
8991
import com.yugabyte.yw.common.rbac.RoleBindingUtil;
9092
import com.yugabyte.yw.common.rbac.RoleUtil;
@@ -94,7 +96,6 @@
9496
import com.yugabyte.yw.common.ybflyway.YBFlywayInit;
9597
import com.yugabyte.yw.controllers.MetricGrafanaController;
9698
import com.yugabyte.yw.controllers.PlatformHttpActionAdapter;
97-
import com.yugabyte.yw.controllers.handlers.OperatorResourceMigrateHandler;
9899
import com.yugabyte.yw.metrics.MetricQueryHelper;
99100
import com.yugabyte.yw.models.CertificateInfo;
100101
import com.yugabyte.yw.models.HealthCheck;
@@ -303,7 +304,8 @@ public void configure() {
303304
bind(ReleasesUtils.class).asEagerSingleton();
304305
bind(ReleaseContainerFactory.class).asEagerSingleton();
305306
bind(SoftwareUpgradeHelper.class).asEagerSingleton();
306-
bind(OperatorResourceMigrateHandler.class).asEagerSingleton();
307+
bind(KubernetesClientFactory.class).asEagerSingleton();
308+
bind(UniverseImporter.class).asEagerSingleton();
307309

308310
// Destroy current session on SSO logout.
309311
final LogoutController logoutController = new LogoutController();

managed/src/main/java/api/v2/controllers/UniverseApiControllerImp.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import api.v2.models.UniverseEditGFlags;
1919
import api.v2.models.UniverseEditKubernetesOverrides;
2020
import api.v2.models.UniverseEditSpec;
21+
import api.v2.models.UniverseOperatorImportReq;
2122
import api.v2.models.UniverseQueryLogsExport;
2223
import api.v2.models.UniverseResourceDetails;
2324
import api.v2.models.UniverseRestart;
@@ -220,4 +221,16 @@ public YBATask configureMetricsExport(
220221
Request request, UUID cUUID, UUID uniUUID, ConfigureMetricsExportSpec req) throws Exception {
221222
return universeUpgradeHandler.configureMetricsExport(request, cUUID, uniUUID, req);
222223
}
224+
225+
@Override
226+
public YBATask operatorImportUniverse(
227+
Request request, UUID cUUID, UUID uniUUID, UniverseOperatorImportReq req) throws Exception {
228+
return universeHandler.operatorImportUniverse(request, cUUID, uniUUID, req);
229+
}
230+
231+
@Override
232+
public void operatorImportUniversePrecheck(
233+
Request request, UUID cUUID, UUID uniUUID, UniverseOperatorImportReq req) throws Exception {
234+
universeHandler.precheckOperatorImportUniverse(request, cUUID, uniUUID, req);
235+
}
223236
}

managed/src/main/java/api/v2/handlers/UniverseManagementHandler.java

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import api.v2.models.UniverseCreateSpec;
2020
import api.v2.models.UniverseDeleteSpec;
2121
import api.v2.models.UniverseEditSpec;
22+
import api.v2.models.UniverseOperatorImportReq;
2223
import api.v2.models.UniverseSpec;
2324
import api.v2.models.YBATask;
2425
import api.v2.utils.ApiControllerUtils;
@@ -709,4 +710,76 @@ public api.v2.models.UniverseResourceDetails getUniverseResources(
709710
}
710711
return v2Response;
711712
}
713+
714+
public void precheckOperatorImportUniverse(
715+
Request request, UUID cUUID, UUID uniUUID, UniverseOperatorImportReq req) {
716+
Customer customer = Customer.getOrBadRequest(cUUID);
717+
Universe universe = Universe.getOrBadRequest(uniUUID, customer);
718+
719+
// validate the universe is kubernetes
720+
if (!Util.isKubernetesBasedUniverse(universe)) {
721+
log.error(
722+
"Universe {} is not a Kubernetes universe, cannot migrate to operator",
723+
universe.getName());
724+
throw new PlatformServiceException(BAD_REQUEST, "Universe is not a Kubernetes universe");
725+
}
726+
if (!confGetter.getGlobalConf(GlobalConfKeys.KubernetesOperatorEnabled)) {
727+
log.error("Operator is not enabled, cannot migrate universe {}", universe.getName());
728+
throw new PlatformServiceException(
729+
BAD_REQUEST,
730+
"Operator is not enabled. Please enable the runtime config"
731+
+ " 'yb.kubernetes.operator.enabled' and restart YBA");
732+
}
733+
734+
// Check if the namespace is the same as the operator namespace if it is set
735+
boolean migrateNamespaceSet = req.getNamespace() != null && !req.getNamespace().isEmpty();
736+
String operatorNamespace = confGetter.getGlobalConf(GlobalConfKeys.KubernetesOperatorNamespace);
737+
boolean operatorNamespaceSet = operatorNamespace != null && !operatorNamespace.isEmpty();
738+
if (migrateNamespaceSet
739+
&& operatorNamespaceSet
740+
&& !req.getNamespace().equals(operatorNamespace)) {
741+
log.error(
742+
"Namespace {} is not the same as the operator namespace {}",
743+
req.getNamespace(),
744+
operatorNamespace);
745+
throw new PlatformServiceException(
746+
BAD_REQUEST,
747+
"Namespace is not the same as the operator namespace. Please set the namespace to the"
748+
+ " same as the operator namespace");
749+
}
750+
751+
// Read Replicas clusters are not supported
752+
if (universe.getUniverseDetails().clusters.size() > 1) {
753+
log.error(
754+
"Universe {} has read-only clusters, cannot migrate to operator", universe.getName());
755+
throw new PlatformServiceException(BAD_REQUEST, "Universe has read-only clusters");
756+
}
757+
758+
// XCluster is not supported by operator
759+
if (!XClusterConfig.getByUniverseUuid(universe.getUniverseUUID()).isEmpty()) {
760+
log.error("Universe {} has xClusterInfo set, cannot migrate to operator", universe.getName());
761+
throw new PlatformServiceException(
762+
BAD_REQUEST, "Cannot migrate universes in an xcluster setup.");
763+
}
764+
765+
// AZ Level overrides are not supported by operator
766+
Map<String, String> azOverrides =
767+
universe.getUniverseDetails().getPrimaryCluster().userIntent.azOverrides;
768+
if (azOverrides != null && azOverrides.size() > 0) {
769+
log.error(
770+
"Universe {} has AZ level overrides set, cannot migrate to operator", universe.getName());
771+
throw new PlatformServiceException(
772+
BAD_REQUEST, "Cannot migrate universes with AZ level overrides.");
773+
}
774+
}
775+
776+
public YBATask operatorImportUniverse(
777+
Request request, UUID cUUID, UUID uniUUID, UniverseOperatorImportReq req) {
778+
Customer customer = Customer.getOrBadRequest(cUUID);
779+
Universe universe = Universe.getOrBadRequest(uniUUID, customer);
780+
// TODO: Implement the migration logic
781+
UUID taskUuid = UUID.randomUUID();
782+
YBATask ybaTask = new YBATask().taskUuid(taskUuid).resourceUuid(universe.getUniverseUUID());
783+
return ybaTask;
784+
}
712785
}

0 commit comments

Comments
 (0)