Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/koordinator-sh/client-java
Java client library for Koordinator
https://github.com/koordinator-sh/client-java
Last synced: about 2 months ago
JSON representation
Java client library for Koordinator
- Host: GitHub
- URL: https://github.com/koordinator-sh/client-java
- Owner: koordinator-sh
- License: apache-2.0
- Created: 2023-07-18T08:45:17.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-07-18T12:32:44.000Z (over 1 year ago)
- Last Synced: 2023-07-18T14:33:50.748Z (over 1 year ago)
- Homepage: https://koordinator.sh
- Size: 4.88 KB
- Stars: 0
- Watchers: 4
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Koordinator Java Client
Java client for the [Koordinator](https://koordinator.sh/) API.
## Usage
Add this dependency to your project's POM:
```xml
sh.koordinator
client-java
1.3.0```
**Note that this package has not been uploaded to the maven official repository. Currently, you should manually download this repo and package it to use.**
You should also add the dependency of Kubernetes official java SDK:
```xml
io.kubernetes
client-java
16.0.2```
### Manually package
At first generate the JAR by executing:
mvn package
Then manually install the following JARs:
* target/client-java-1.3.0.jar
## Getting Started
```java
package sh.koordinator.scheduling.models;import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;import io.kubernetes.client.custom.Quantity;
import io.kubernetes.client.openapi.ApiClient;
import io.kubernetes.client.openapi.models.V1Container;
import io.kubernetes.client.openapi.models.V1ObjectMeta;
import io.kubernetes.client.openapi.models.V1PodSpec;
import io.kubernetes.client.openapi.models.V1PodTemplateSpec;
import io.kubernetes.client.openapi.models.V1ResourceRequirements;
import io.kubernetes.client.util.Config;
import io.kubernetes.client.util.generic.GenericKubernetesApi;
import io.kubernetes.client.util.generic.KubernetesApiResponse;
import org.junit.Test;
import sh.koordinator.scheduling.models.V1alpha1ReservationSpec.AllocatePolicyEnum;public class V1alpha1ReservationTest {
private static final String API_GROUP = "scheduling.koordinator.sh";
private static final String API_VERSION = "v1alpha1";
private static final String RESOURCE_PLURAL = "reservations";
private static final String API_VERSION_DETAIL = API_GROUP + "/" + API_VERSION;
private static final String API_KIND = "Reservation";@Test
public void testCreateReservation() throws IOException {
ApiClient apiClient = Config.defaultClient();
GenericKubernetesApi reservationClient = new GenericKubernetesApi<>(
V1alpha1Reservation.class,
V1alpha1ReservationList.class,
API_GROUP,
API_VERSION,
RESOURCE_PLURAL,
apiClient);
V1ObjectMeta objectMeta = new V1ObjectMeta().name("test-reservation");
V1alpha1ReservationSpecOwners owners = new V1alpha1ReservationSpecOwners()
.labelSelector(
new V1alpha1ReservationSpecLabelSelector()
.matchLabels(
new HashMap(){{
put("app", "test");
}}
)
);
List containerList = new ArrayList<>(
Collections.singletonList(
new V1Container()
.name("main")
.resources(
new V1ResourceRequirements()
.limits(
new HashMap() {{
put("cpu", Quantity.fromString("2"));
put("memory", Quantity.fromString("4Gi"));
}}
)
)
)
);
V1alpha1ReservationSpec reservationSpec = new V1alpha1ReservationSpec()
.allocateOnce(false)
.addOwnersItem(owners)
.allocatePolicy(AllocatePolicyEnum.RESTRICTED)
.template(new V1PodTemplateSpec().spec(new V1PodSpec().containers(containerList)));
V1alpha1Reservation reservation = new V1alpha1Reservation()
.apiVersion(API_VERSION_DETAIL)
.kind(API_KIND)
.metadata(objectMeta)
.spec(reservationSpec);
KubernetesApiResponse response = reservationClient.create(reservation);
System.out.println(response.getStatus());
System.out.println(response.getObject());
assert reservation.getMetadata() != null;
reservationClient.delete(reservation.getMetadata().getName());
}
}
```