use of io.fabric8.kubernetes.api.model.BindingBuilder 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.BindingBuilder 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");
}
Aggregations