Search in sources :

Example 6 with Binding

use of io.fabric8.kubernetes.api.model.Binding in project quarkus by quarkusio.

the class OpenshiftWithServiceBindingTest method assertGeneratedResources.

@Test
public void assertGeneratedResources() throws IOException {
    final Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes");
    assertThat(kubernetesDir).isDirectoryContaining(p -> p.getFileName().endsWith("openshift.json")).isDirectoryContaining(p -> p.getFileName().endsWith("openshift.yml"));
    List<HasMetadata> kubernetesList = DeserializationUtil.deserializeAsList(kubernetesDir.resolve("openshift.yml"));
    assertThat(kubernetesList).filteredOn(i -> "DeploymentConfig".equals(i.getKind())).singleElement().satisfies(i -> {
        assertThat(i).isInstanceOfSatisfying(DeploymentConfig.class, d -> {
            assertThat(d.getMetadata()).satisfies(m -> {
                assertThat(m.getName()).isEqualTo("openshift-with-service-binding");
            });
        });
    });
    assertThat(kubernetesList).filteredOn(i -> "ServiceBinding".equals(i.getKind())).singleElement().satisfies(i -> {
        assertThat(i).isInstanceOfSatisfying(ServiceBinding.class, s -> {
            assertThat(s.getMetadata()).satisfies(m -> {
                assertThat(m.getName()).isEqualTo("openshift-with-service-binding-my-db");
            });
            assertThat(s.getSpec()).satisfies(spec -> {
                assertThat(spec.getApplication()).satisfies(a -> {
                    assertThat(a.getGroup()).isEqualTo("apps.openshift.io");
                    assertThat(a.getVersion()).isEqualTo("v1");
                    assertThat(a.getKind()).isEqualTo("DeploymentConfig");
                });
                assertThat(spec.getServices()).hasOnlyOneElementSatisfying(service -> {
                    assertThat(service.getGroup()).isEqualTo("apps");
                    assertThat(service.getVersion()).isEqualTo("v1");
                    assertThat(service.getKind()).isEqualTo("Deployment");
                    assertThat(service.getName()).isEqualTo("my-postgres");
                });
            });
        });
    });
}
Also used : Path(java.nio.file.Path) Arrays(java.util.Arrays) AppArtifact(io.quarkus.bootstrap.model.AppArtifact) QuarkusProdModeTest(io.quarkus.test.QuarkusProdModeTest) Version(io.quarkus.builder.Version) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) IOException(java.io.IOException) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Test(org.junit.jupiter.api.Test) List(java.util.List) ServiceBinding(io.dekorate.servicebinding.model.ServiceBinding) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) ProdBuildResults(io.quarkus.test.ProdBuildResults) ProdModeTestResults(io.quarkus.test.ProdModeTestResults) Path(java.nio.file.Path) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) QuarkusProdModeTest(io.quarkus.test.QuarkusProdModeTest) Test(org.junit.jupiter.api.Test)

Example 7 with Binding

use of io.fabric8.kubernetes.api.model.Binding in project quarkus by quarkusio.

the class KubernetesWithServiceBindingTest method assertGeneratedResources.

@Test
public void assertGeneratedResources() throws IOException {
    final Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes");
    assertThat(kubernetesDir).isDirectoryContaining(p -> p.getFileName().endsWith("kubernetes.json")).isDirectoryContaining(p -> p.getFileName().endsWith("kubernetes.yml"));
    List<HasMetadata> kubernetesList = DeserializationUtil.deserializeAsList(kubernetesDir.resolve("kubernetes.yml"));
    assertThat(kubernetesList).filteredOn(i -> "Deployment".equals(i.getKind())).singleElement().satisfies(i -> {
        assertThat(i).isInstanceOfSatisfying(Deployment.class, d -> {
            assertThat(d.getMetadata()).satisfies(m -> {
                assertThat(m.getName()).isEqualTo("kubernetes-with-service-binding");
            });
            assertThat(d.getSpec()).satisfies(deploymentSpec -> {
                assertThat(deploymentSpec.getTemplate()).satisfies(t -> {
                    assertThat(t.getSpec()).satisfies(podSpec -> {
                    });
                });
            });
        });
    });
    assertThat(kubernetesList).filteredOn(i -> "ServiceBinding".equals(i.getKind())).singleElement().satisfies(i -> {
        assertThat(i).isInstanceOfSatisfying(ServiceBinding.class, s -> {
            assertThat(s.getMetadata()).satisfies(m -> {
                assertThat(m.getName()).isEqualTo("kubernetes-with-service-binding-my-db");
            });
            assertThat(s.getSpec()).satisfies(spec -> {
                assertThat(spec.getApplication()).satisfies(a -> {
                    assertThat(a.getGroup()).isEqualTo("apps");
                    assertThat(a.getVersion()).isEqualTo("v1");
                    assertThat(a.getKind()).isEqualTo("Deployment");
                });
                assertThat(spec.getServices()).hasOnlyOneElementSatisfying(service -> {
                    assertThat(service.getGroup()).isEqualTo("apps");
                    assertThat(service.getVersion()).isEqualTo("v1");
                    assertThat(service.getKind()).isEqualTo("Deployment");
                    assertThat(service.getName()).isEqualTo("my-postgres");
                });
            });
        });
    });
}
Also used : Path(java.nio.file.Path) Arrays(java.util.Arrays) AppArtifact(io.quarkus.bootstrap.model.AppArtifact) QuarkusProdModeTest(io.quarkus.test.QuarkusProdModeTest) Version(io.quarkus.builder.Version) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IOException(java.io.IOException) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Test(org.junit.jupiter.api.Test) List(java.util.List) ServiceBinding(io.dekorate.servicebinding.model.ServiceBinding) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) ProdBuildResults(io.quarkus.test.ProdBuildResults) ProdModeTestResults(io.quarkus.test.ProdModeTestResults) Path(java.nio.file.Path) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) QuarkusProdModeTest(io.quarkus.test.QuarkusProdModeTest) Test(org.junit.jupiter.api.Test)

Example 8 with Binding

use of io.fabric8.kubernetes.api.model.Binding in project quarkus by quarkusio.

the class KubernetesWithAutoMysqlBindingTest method assertGeneratedResources.

@Test
public void assertGeneratedResources() throws IOException {
    final Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes");
    assertThat(kubernetesDir).isDirectoryContaining(p -> p.getFileName().endsWith("kubernetes.json")).isDirectoryContaining(p -> p.getFileName().endsWith("kubernetes.yml"));
    List<HasMetadata> kubernetesList = DeserializationUtil.deserializeAsList(kubernetesDir.resolve("kubernetes.yml"));
    assertThat(kubernetesList).filteredOn(i -> "Deployment".equals(i.getKind())).singleElement().satisfies(i -> {
        assertThat(i).isInstanceOfSatisfying(Deployment.class, d -> {
            assertThat(d.getMetadata()).satisfies(m -> {
                assertThat(m.getName()).isEqualTo("kubernetes-with-auto-mysql-binding");
            });
            assertThat(d.getSpec()).satisfies(deploymentSpec -> {
                assertThat(deploymentSpec.getTemplate()).satisfies(t -> {
                    assertThat(t.getSpec()).satisfies(podSpec -> {
                    });
                });
            });
        });
    });
    assertThat(kubernetesList).filteredOn(i -> "ServiceBinding".equals(i.getKind())).singleElement().satisfies(i -> {
        assertThat(i).isInstanceOfSatisfying(ServiceBinding.class, s -> {
            assertThat(s.getMetadata()).satisfies(m -> {
                assertThat(m.getName()).isEqualTo("kubernetes-with-auto-mysql-binding-mysql");
            });
            assertThat(s.getSpec()).satisfies(spec -> {
                assertThat(spec.getApplication()).satisfies(a -> {
                    assertThat(a.getGroup()).isEqualTo("apps");
                    assertThat(a.getVersion()).isEqualTo("v1");
                    assertThat(a.getKind()).isEqualTo("Deployment");
                });
                assertThat(spec.getServices()).hasOnlyOneElementSatisfying(service -> {
                    assertThat(service.getGroup()).isEqualTo("pxc.percona.com");
                    assertThat(service.getVersion()).isEqualTo("v1-9-0");
                    assertThat(service.getKind()).isEqualTo("PerconaXtraDBCluster");
                    assertThat(service.getName()).isEqualTo("mysql");
                });
            });
        });
    });
}
Also used : Path(java.nio.file.Path) Arrays(java.util.Arrays) AppArtifact(io.quarkus.bootstrap.model.AppArtifact) QuarkusProdModeTest(io.quarkus.test.QuarkusProdModeTest) Version(io.quarkus.builder.Version) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IOException(java.io.IOException) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Test(org.junit.jupiter.api.Test) List(java.util.List) ServiceBinding(io.dekorate.servicebinding.model.ServiceBinding) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) ProdBuildResults(io.quarkus.test.ProdBuildResults) ProdModeTestResults(io.quarkus.test.ProdModeTestResults) Path(java.nio.file.Path) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) QuarkusProdModeTest(io.quarkus.test.QuarkusProdModeTest) Test(org.junit.jupiter.api.Test)

Example 9 with Binding

use of io.fabric8.kubernetes.api.model.Binding in project quarkus by quarkusio.

the class KubernetesWithAutoPostgresBindingTest method assertGeneratedResources.

@Test
public void assertGeneratedResources() throws IOException {
    final Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes");
    assertThat(kubernetesDir).isDirectoryContaining(p -> p.getFileName().endsWith("kubernetes.json")).isDirectoryContaining(p -> p.getFileName().endsWith("kubernetes.yml"));
    List<HasMetadata> kubernetesList = DeserializationUtil.deserializeAsList(kubernetesDir.resolve("kubernetes.yml"));
    assertThat(kubernetesList).filteredOn(i -> "Deployment".equals(i.getKind())).singleElement().satisfies(i -> {
        assertThat(i).isInstanceOfSatisfying(Deployment.class, d -> {
            assertThat(d.getMetadata()).satisfies(m -> {
                assertThat(m.getName()).isEqualTo("kubernetes-with-auto-postgres-binding");
            });
            assertThat(d.getSpec()).satisfies(deploymentSpec -> {
                assertThat(deploymentSpec.getTemplate()).satisfies(t -> {
                    assertThat(t.getSpec()).satisfies(podSpec -> {
                    });
                });
            });
        });
    });
    assertThat(kubernetesList).filteredOn(i -> "ServiceBinding".equals(i.getKind())).singleElement().satisfies(i -> {
        assertThat(i).isInstanceOfSatisfying(ServiceBinding.class, s -> {
            assertThat(s.getMetadata()).satisfies(m -> {
                assertThat(m.getName()).isEqualTo("kubernetes-with-auto-postgres-binding-postgresql");
            });
            assertThat(s.getSpec()).satisfies(spec -> {
                assertThat(spec.getApplication()).satisfies(a -> {
                    assertThat(a.getGroup()).isEqualTo("apps");
                    assertThat(a.getVersion()).isEqualTo("v1");
                    assertThat(a.getKind()).isEqualTo("Deployment");
                });
                assertThat(spec.getServices()).hasOnlyOneElementSatisfying(service -> {
                    assertThat(service.getGroup()).isEqualTo("postgres-operator.crunchydata.com");
                    assertThat(service.getVersion()).isEqualTo("v1beta1");
                    assertThat(service.getKind()).isEqualTo("PostgresCluster");
                    assertThat(service.getName()).isEqualTo("postgresql");
                });
            });
        });
    });
}
Also used : Path(java.nio.file.Path) Arrays(java.util.Arrays) AppArtifact(io.quarkus.bootstrap.model.AppArtifact) QuarkusProdModeTest(io.quarkus.test.QuarkusProdModeTest) Version(io.quarkus.builder.Version) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IOException(java.io.IOException) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Test(org.junit.jupiter.api.Test) List(java.util.List) ServiceBinding(io.dekorate.servicebinding.model.ServiceBinding) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) ProdBuildResults(io.quarkus.test.ProdBuildResults) ProdModeTestResults(io.quarkus.test.ProdModeTestResults) Path(java.nio.file.Path) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) QuarkusProdModeTest(io.quarkus.test.QuarkusProdModeTest) Test(org.junit.jupiter.api.Test)

Example 10 with Binding

use of io.fabric8.kubernetes.api.model.Binding in project dekorate by dekorateio.

the class ServiceBindingConfigGeneratorTest method shouldGenerateServiceBindingWithoutWritingToFileSystem.

@Test
public void shouldGenerateServiceBindingWithoutWritingToFileSystem() throws IOException {
    Path tempDir = Files.createTempDirectory("dekorate");
    WithProject withProject = new WithProject() {
    };
    withProject.setProject(FileProjectFactory.create(new File(".")).withDekorateOutputDir(tempDir.toAbsolutePath().toString()).withDekorateMetaDir(tempDir.toAbsolutePath().toString()));
    SessionWriter writer = new SimpleFileWriter(withProject.getProject(), false);
    Session session = Session.getSession();
    session.setWriter(writer);
    ServiceBindingConfigGenerator generator = new DefaultServiceBindingConfigGenerator(session.getConfigurationRegistry());
    final HashMap<String, Object>[] services = new HashMap[1];
    services[0] = new HashMap<String, Object>() {

        {
            put("group", "postgresql.dev");
            put("kind", "Database");
            put("name", "demo-database");
            put("id", "postgresDB");
        }
    };
    final HashMap<String, Object>[] customEnvVar = new HashMap[1];
    customEnvVar[0] = new HashMap<String, Object>() {

        {
            put("name", "foo");
            put("value", "bar");
            put("configmap", "baz");
        }
    };
    final HashMap<String, Object> bindingPath = new HashMap<String, Object>();
    bindingPath.put("secretPath", "/var");
    bindingPath.put("containerPath", ".spec");
    final HashMap<String, Object> application = new HashMap<String, Object>();
    application.put("group", "apps");
    application.put("kind", "Deployment");
    application.put("version", "v1");
    application.put("name", "servicebinding-test");
    Map<String, Object> map = new HashMap<String, Object>() {

        {
            put(ServiceBindingConfig.class.getName(), new HashMap<String, Object>() {

                {
                    put("name", "servicebinding-test-binding");
                    put("application", application);
                    put("services", services);
                    put("envVarPrefix", "postgres");
                    put("bindingPath", bindingPath);
                    put("customEnvVar", customEnvVar);
                }
            });
        }
    };
    generator.addPropertyConfiguration(map);
    final Map<String, String> result = session.close();
    KubernetesList list = session.getGeneratedResources().get("kubernetes");
    assertThat(list).isNotNull();
    assertThat(list.getItems()).filteredOn(i -> "ServiceBinding".equals(i.getKind())).hasOnlyOneElementSatisfying(item -> {
        assertThat(item).isInstanceOfSatisfying(ServiceBinding.class, s -> {
            assertThat(s.getSpec()).satisfies(spec -> {
                assertThat(spec.getEnvVarPrefix()).isEqualTo("postgres");
                assertThat(spec.getApplication().getKind()).isEqualTo("Deployment");
                assertThat(spec.getApplication().getResource()).isEqualTo("deployments");
                assertThat(spec.getApplication().getVersion()).isEqualTo("v1");
                assertThat(spec.getApplication().getName()).isEqualTo("servicebinding-test");
                assertThat(spec.getApplication().getGroup()).isEqualTo("apps");
                assertThat(spec.getApplication().getBindingPath().getContainerPath()).isEqualTo(".spec");
                assertThat(spec.getApplication().getBindingPath().getSecretPath()).isEqualTo("/var");
                assertThat(spec.getServices()[0].getGroup()).isEqualTo("postgresql.dev");
                assertThat(spec.getServices()[0].getName()).isEqualTo("demo-database");
                assertThat(spec.getServices()[0].getId()).isEqualTo("postgresDB");
                assertThat(spec.getServices()[0].getKind()).isEqualTo("Database");
                assertThat(spec.getCustomEnvVar()[0].getName()).isEqualTo("foo");
                assertThat(spec.getCustomEnvVar()[0].getValueFrom().getConfigMapKeyRef().getKey()).isEqualTo("bar");
                assertThat(spec.getCustomEnvVar()[0].getValueFrom().getConfigMapKeyRef().getName()).isEqualTo("baz");
            });
        });
    });
    assertThat(tempDir.resolve("kubernetes.json")).doesNotExist();
    assertThat(tempDir.resolve("kubernetes.yml")).doesNotExist();
    assertThat(result).hasSize(6);
}
Also used : Path(java.nio.file.Path) WithProject(io.dekorate.WithProject) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) Files(java.nio.file.Files) SimpleFileWriter(io.dekorate.processor.SimpleFileWriter) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IOException(java.io.IOException) HashMap(java.util.HashMap) File(java.io.File) Test(org.junit.jupiter.api.Test) FileProjectFactory(io.dekorate.project.FileProjectFactory) ServiceBinding(io.dekorate.servicebinding.model.ServiceBinding) Session(io.dekorate.Session) Map(java.util.Map) SessionWriter(io.dekorate.SessionWriter) Path(java.nio.file.Path) HashMap(java.util.HashMap) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) WithProject(io.dekorate.WithProject) SessionWriter(io.dekorate.SessionWriter) File(java.io.File) SimpleFileWriter(io.dekorate.processor.SimpleFileWriter) Session(io.dekorate.Session) Test(org.junit.jupiter.api.Test)

Aggregations

IOException (java.io.IOException)11 List (java.util.List)11 Test (org.junit.jupiter.api.Test)11 RoleBinding (io.fabric8.kubernetes.api.model.rbac.RoleBinding)10 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)8 ClusterRoleBinding (io.fabric8.kubernetes.api.model.rbac.ClusterRoleBinding)8 Subject (io.fabric8.kubernetes.api.model.rbac.Subject)8 ParallelTest (io.strimzi.test.annotations.ParallelTest)8 Arrays (java.util.Arrays)8 HashMap (java.util.HashMap)8 ServiceBinding (io.dekorate.servicebinding.model.ServiceBinding)7 File (java.io.File)7 Path (java.nio.file.Path)7 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)7 RoleRefBuilder (io.fabric8.kubernetes.api.model.rbac.RoleRefBuilder)6 SubjectBuilder (io.fabric8.kubernetes.api.model.rbac.SubjectBuilder)6 AppArtifact (io.quarkus.bootstrap.model.AppArtifact)6 Version (io.quarkus.builder.Version)6 ProdBuildResults (io.quarkus.test.ProdBuildResults)6 ProdModeTestResults (io.quarkus.test.ProdModeTestResults)6