Skip to content

Commit

Permalink
[PLAT-8863] Generating CRD Classes using crdgen and wiring it up in t…
Browse files Browse the repository at this point in the history
…he build.

Summary:
Building using and generating CRD classess instead of hard coding them.
We are using fabric8 crddgen now to build this code, the good part is any
crd yaml in resources directory will get automatically generated.

Test Plan:
Build code.
deploy a universe

Reviewers: dshubin, sanketh, shashank, nbhatia, sb-yb

Reviewed By: dshubin, sb-yb

Subscribers: sb-yb, yugaware

Differential Revision: https://phorge.dev.yugabyte.com/D26423
  • Loading branch information
amannijhawan committed Jun 28, 2023
1 parent 77360ba commit c3c8931
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 454 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,10 @@ submodules/
managed/yba-installer/bin/yba-ctl
managed/yba-installer/yba-ctl
managed/devops/pex/pexEnv/
managed/src/main/java/com/yugabyte/yw/common/operator/io/*

*.bad_clang_tidy_output.*
*.compiler_errors.txt

# jenv local version
**/.java-version
**/.java-version
19 changes: 19 additions & 0 deletions managed/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ lazy val consoleSetting = settingKey[PlayInteractionMode]("custom console settin
lazy val versionGenerate = taskKey[Int]("Add version_metadata.json file")

lazy val buildVenv = taskKey[Int]("Build venv")
lazy val generateCrdObjects = taskKey[Int]("Generating CRD classes..")
lazy val buildUI = taskKey[Int]("Build UI")
lazy val buildModules = taskKey[Int]("Build modules")
lazy val buildDependentArtifacts = taskKey[Int]("Build dependent artifacts")
Expand All @@ -99,6 +100,7 @@ lazy val releaseModulesLocally = taskKey[Int]("Release modules locally")
lazy val cleanUI = taskKey[Int]("Clean UI")
lazy val cleanVenv = taskKey[Int]("Clean venv")
lazy val cleanModules = taskKey[Int]("Clean modules")
lazy val cleanCrd = taskKey[Int]("Clean CRD")


lazy val compileJavaGenClient = taskKey[Int]("Compile generated Java code")
Expand Down Expand Up @@ -194,6 +196,8 @@ libraryDependencies ++= Seq(
"io.fabric8" % "kubernetes-client-api" % "6.4.1",
"io.fabric8" % "kubernetes-model" % "4.9.2",
"io.fabric8" % "kubernetes-api" % "3.0.12",
"org.modelmapper" % "modelmapper" % "2.4.4",

"io.jsonwebtoken" % "jjwt-api" % "0.11.5",
"io.jsonwebtoken" % "jjwt-impl" % "0.11.5",
"io.jsonwebtoken" % "jjwt-jackson" % "0.11.5",
Expand Down Expand Up @@ -306,6 +310,7 @@ externalResolvers := {
(Compile / compilePlatform) := {
(Compile / compile).value
Def.sequential(
generateCrdObjects,
buildVenv,
releaseModulesLocally
).value
Expand All @@ -316,6 +321,7 @@ externalResolvers := {
cleanPlatform := {
clean.value
(swagger / clean).value
cleanCrd.value
cleanVenv.value
cleanUI.value
cleanModules.value
Expand Down Expand Up @@ -359,10 +365,17 @@ releaseModulesLocally := {

buildDependentArtifacts := {
ybLog("Building dependencies...")
generateCrdObjects.value
val status = Process("mvn install -P buildDependenciesOnly", baseDirectory.value / "parent-module").!
status
}

generateCrdObjects := {
ybLog("Generating crd classes...")
val status = Process("mvn generate-sources", baseDirectory.value / "src/main/java/com/yugabyte/yw/common/operator/").!
status
}

compileJavaGenClient := {
val buildType = sys.env.getOrElse("BUILD_TYPE", "release")
val status = Process("mvn install", new File(baseDirectory.value + "/client/java/generated")).!
Expand Down Expand Up @@ -392,6 +405,12 @@ cleanVenv := {
status
}

cleanCrd := {
ybLog("Cleaning CRD generated code...")
val status = Process("mvn clean", baseDirectory.value / "src/main/java/com/yugabyte/yw/common/operator/").!
status
}

// Generate a Java API client.
lazy val javagen = project.in(file("client/java"))
.settings(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.fabric8.kubernetes.client.informers.ResourceEventHandler;
import io.fabric8.kubernetes.client.informers.SharedIndexInformer;
import io.fabric8.kubernetes.client.informers.SharedInformerFactory;
import io.yugabyte.operator.v1alpha1.YBUniverse;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import org.slf4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.yugabyte.yw.models.Universe;
import com.yugabyte.yw.models.Users;
import com.yugabyte.yw.models.helpers.CloudInfoInterface;
import com.yugabyte.yw.models.helpers.DeviceInfo;
import io.fabric8.kubernetes.api.model.KubernetesResourceList;
import io.fabric8.kubernetes.api.model.ObjectMeta;
import io.fabric8.kubernetes.client.KubernetesClient;
Expand All @@ -34,6 +35,7 @@
import io.fabric8.kubernetes.client.informers.SharedIndexInformer;
import io.fabric8.kubernetes.client.informers.cache.Cache;
import io.fabric8.kubernetes.client.informers.cache.Lister;
import io.yugabyte.operator.v1alpha1.YBUniverse;
import java.lang.reflect.Field;
import java.util.ArrayDeque;
import java.util.ArrayList;
Expand All @@ -48,6 +50,7 @@
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.stream.Collectors;
import org.modelmapper.ModelMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yb.util.Pair;
Expand Down Expand Up @@ -509,7 +512,9 @@ private UserIntent createUserIntent(YBUniverse ybUniverse, UUID customerUUID) {
userIntent.ybSoftwareVersion = ybUniverse.getSpec().getYbSoftwareVersion();
userIntent.accessKeyCode = "";
userIntent.assignPublicIP = ybUniverse.getSpec().getAssignPublicIP();
userIntent.deviceInfo = ybUniverse.getSpec().getDeviceInfo();
// Deep copy from operator yaml to model
ModelMapper modelMapper = new ModelMapper();
userIntent.deviceInfo = modelMapper.map(ybUniverse.getSpec().getDeviceInfo(), DeviceInfo.class);
userIntent.useTimeSync = ybUniverse.getSpec().getUseTimeSync();
userIntent.enableYSQL = ybUniverse.getSpec().getEnableYSQL();
userIntent.enableYEDIS = ybUniverse.getSpec().getEnableYEDIS();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.dsl.MixedOperation;
import io.fabric8.kubernetes.client.dsl.Resource;
import io.yugabyte.operator.v1alpha1.*;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
Expand Down

This file was deleted.

Loading

0 comments on commit c3c8931

Please sign in to comment.