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);
}
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);
}
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());
}
}
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");
}
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;
}
}
Aggregations