use of org.ballerinax.kubernetes.models.KubernetesContext in project kubernetes by ballerinax.
the class KubernetesPlugin method validateDeploymentDependencies.
private void validateDeploymentDependencies() throws KubernetesPluginException {
KubernetesContext context = KubernetesContext.getInstance();
Map<PackageID, KubernetesDataHolder> packageToDataHolderMap = context.getPackageIDtoDataHolderMap();
DependencyValidator dependencyValidator = new DependencyValidator();
for (KubernetesDataHolder dataHolder : packageToDataHolderMap.values()) {
// add other dependent deployments
List<String> dependencies = new ArrayList<>();
// add the current deployment as 0th element
String currentDeployment = dataHolder.getDeploymentModel().getName();
if (currentDeployment == null) {
return;
}
dependencies.add(currentDeployment);
Set<String> dependsOn = dataHolder.getDeploymentModel().getDependsOn();
for (String listenerName : dependsOn) {
String dependentDeployment = context.getDeploymentNameFromListener(listenerName);
if (dependentDeployment == null) {
return;
}
if (!dependentDeployment.equals(currentDeployment)) {
dependencies.add(dependentDeployment);
} else {
// Listener is in the same package.
throw new KubernetesPluginException("@kubernetes:Deployment{} contains cyclic dependencies");
}
}
String[] array = dependencies.toArray(new String[0]);
if (!dependencyValidator.validateDependency(array)) {
throw new KubernetesPluginException("@kubernetes:Deployment{} contains cyclic dependencies");
}
}
}
use of org.ballerinax.kubernetes.models.KubernetesContext in project kubernetes by ballerinax.
the class HelmChartGeneratorTests method testHelmGenerate.
@Test
public void testHelmGenerate() throws KubernetesPluginException {
DockerModel dockerModel = new DockerModel();
Set<Integer> ports = new HashSet<>();
ports.add(9090);
ports.add(9091);
ports.add(9092);
dockerModel.setPorts(ports);
dockerModel.setService(true);
dockerModel.setJarFileName("hello.jar");
dockerModel.setEnableDebug(true);
dockerModel.setBaseImage(OPENJDK_11_JRE_SLIM_BASE);
dockerModel.setDebugPort(5005);
dockerModel.setBuildImage(false);
KubernetesContext context = KubernetesContext.getInstance();
KubernetesDataHolder dataHolder = context.getDataHolder();
dataHolder.setDockerModel(dockerModel);
new DockerHandler().createArtifacts();
new HelmChartHandler().createArtifacts();
File charYaml = dataHolder.getK8sArtifactOutputPath().resolve(module.name.toString()).resolve("hello-deployment").resolve("Chart.yaml").toFile();
Assert.assertTrue(charYaml.exists());
charYaml.deleteOnExit();
}
use of org.ballerinax.kubernetes.models.KubernetesContext in project kubernetes by ballerinax.
the class HandlerTestSuite method setUp.
@BeforeSuite
public void setUp() {
KubernetesContext context = KubernetesContext.getInstance();
context.addDataHolder(module, Paths.get("build"));
dataHolder = context.getDataHolder();
Path buildDir = Paths.get(System.getProperty("buildDir"));
dataHolder.setK8sArtifactOutputPath(buildDir.resolve(KUBERNETES).resolve(module.name.toString()));
dataHolder.setDockerArtifactOutputPath(buildDir.resolve(DOCKER).resolve(module.name.toString()));
Path resourcesDirectory = Paths.get("src").resolve("test").resolve("resources");
DeploymentModel deploymentModel = new DeploymentModel();
deploymentModel.setSingleYAML(false);
dataHolder.setDeploymentModel(deploymentModel);
dataHolder.setUberJarPath(resourcesDirectory.toAbsolutePath().resolve("hello.jar"));
}
Aggregations