Search in sources :

Example 1 with Binding

use of io.fabric8.kubernetes.api.model.Binding in project che-server by eclipse-che.

the class UserPermissionConfiguratorTest method keepOtherClusterRoles.

@Test
public void keepOtherClusterRoles() throws InfrastructureException {
    // given - some other binding in place
    client.rbac().roleBindings().inNamespace(TEST_NAMESPACE_NAME).create(new RoleBindingBuilder().withNewMetadata().withName("othercr").endMetadata().withSubjects(new Subject("blabol", "blabol", "blabol", "blabol")).withNewRoleRef().withName("blabol").endRoleRef().build());
    // when
    configurator.configure(namespaceResolutionContext, TEST_NAMESPACE_NAME);
    // then
    var roleBindings = client.rbac().roleBindings().inNamespace(TEST_NAMESPACE_NAME);
    Assert.assertEquals(roleBindings.list().getItems().size(), 3);
}
Also used : RoleBindingBuilder(io.fabric8.kubernetes.api.model.rbac.RoleBindingBuilder) Subject(io.fabric8.kubernetes.api.model.rbac.Subject) Test(org.testng.annotations.Test)

Example 2 with Binding

use of io.fabric8.kubernetes.api.model.Binding in project che-server by eclipse-che.

the class UserPermissionConfiguratorTest method replaceExistingBindingsWithSameName.

@Test
public void replaceExistingBindingsWithSameName() throws InfrastructureException {
    // given - cr1 binding already exists
    client.rbac().roleBindings().inNamespace(TEST_NAMESPACE_NAME).create(new RoleBindingBuilder().withNewMetadata().withName("cr1").endMetadata().withSubjects(new Subject("blabol", "blabol", "blabol", "blabol")).withNewRoleRef().withName("blabol").endRoleRef().build());
    // when
    configurator.configure(namespaceResolutionContext, TEST_NAMESPACE_NAME);
    // then
    var roleBindings = client.rbac().roleBindings().inNamespace(TEST_NAMESPACE_NAME);
    Assert.assertEquals(roleBindings.list().getItems().size(), 2);
    var cr1 = roleBindings.withName("cr1").get();
    Assert.assertEquals(cr1.getRoleRef().getName(), "cr1");
    Assert.assertEquals(cr1.getSubjects().size(), 1);
    Assert.assertEquals(cr1.getSubjects().get(0).getName(), TEST_USERNAME);
    Assert.assertEquals(cr1.getSubjects().get(0).getNamespace(), TEST_NAMESPACE_NAME);
}
Also used : RoleBindingBuilder(io.fabric8.kubernetes.api.model.rbac.RoleBindingBuilder) Subject(io.fabric8.kubernetes.api.model.rbac.Subject) Test(org.testng.annotations.Test)

Example 3 with Binding

use of io.fabric8.kubernetes.api.model.Binding in project kubernetes-client by fabric8io.

the class BindingExample method main.

@SuppressWarnings("java:S106")
public static void main(String[] args) {
    final String podName = "binding-example-" + UUID.randomUUID();
    try (final KubernetesClient client = new KubernetesClientBuilder().build()) {
        final String namespace;
        if (client.getConfiguration().getNamespace() != null) {
            namespace = client.getConfiguration().getNamespace();
        } else if (client.getNamespace() != null) {
            namespace = client.getNamespace();
        } else {
            namespace = client.namespaces().list().getItems().stream().findFirst().orElseThrow(() -> new IllegalStateException("No namespace available")).getMetadata().getName();
        }
        client.pods().inNamespace(namespace).create(new PodBuilder().withMetadata(new ObjectMetaBuilder().withName(podName).build()).withSpec(new PodSpecBuilder().withSchedulerName("random-scheduler-name-which-does-not-exist").addNewContainer().withName(podName).withImage("nginx:latest").endContainer().build()).build());
        final Node firstNode = client.nodes().list().getItems().stream().findFirst().orElseThrow(() -> new IllegalStateException("No nodes available"));
        client.bindings().inNamespace(namespace).create(new BindingBuilder().withNewMetadata().withName(podName).endMetadata().withNewTarget().withKind(firstNode.getKind()).withApiVersion(firstNode.getApiVersion()).withName(firstNode.getMetadata().getName()).endTarget().build());
        System.out.printf("Successfully bound Pod %s to Node %s%n", podName, firstNode.getMetadata().getName());
    }
}
Also used : PodSpecBuilder(io.fabric8.kubernetes.api.model.PodSpecBuilder) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) BindingBuilder(io.fabric8.kubernetes.api.model.BindingBuilder) KubernetesClientBuilder(io.fabric8.kubernetes.client.KubernetesClientBuilder) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) Node(io.fabric8.kubernetes.api.model.Node) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder)

Example 4 with Binding

use of io.fabric8.kubernetes.api.model.Binding in project kubernetes-client by fabric8io.

the class BindingTest method createOK.

@DisplayName("create, with created response, should return created resource")
@Test
void createOK() {
    server.expect().post().withPath("/api/v1/namespaces/default/bindings").andReturn(201, "{\"metadata\": {\"name\": \"binding-name\"}}").once();
    // When
    final Binding result = client.bindings().inNamespace("default").create(new BindingBuilder().withNewMetadata().withName("binding-name").endMetadata().withNewTarget().withKind("Node").withApiVersion("v1").withName("node-name").endTarget().build());
    // Then
    assertThat(result).isNotNull().hasFieldOrPropertyWithValue("metadata.name", "binding-name");
}
Also used : Binding(io.fabric8.kubernetes.api.model.Binding) BindingBuilder(io.fabric8.kubernetes.api.model.BindingBuilder) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 5 with Binding

use of io.fabric8.kubernetes.api.model.Binding in project kaoto-backend by KaotoIO.

the class ClusterService method start.

public boolean start(final String input) {
    try {
        Yaml yaml = new Yaml(new Constructor(KameletBinding.class));
        KameletBinding binding = yaml.load(input);
        if (binding.getMetadata() == null) {
            binding.setMetadata(new ObjectMeta());
        }
        final var name = binding.getMetadata().getName();
        if (name == null || name.isEmpty()) {
            binding.getMetadata().setName("integration-" + System.currentTimeMillis());
        }
        return start(binding);
    } catch (ConstructorException e) {
        log.warn("Error starting the integration.", e);
        return false;
    }
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) Constructor(org.yaml.snakeyaml.constructor.Constructor) ConstructorException(org.yaml.snakeyaml.constructor.ConstructorException) Yaml(org.yaml.snakeyaml.Yaml) KameletBinding(io.kaoto.backend.model.deployment.kamelet.KameletBinding)

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