use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition in project kubernetes-client by fabric8io.
the class CustomResourceDefinitionTest method testGet.
@Test
void testGet() {
server.expect().get().withPath("/apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions/sparkclusters.radanalytics.io").andReturn(200, customResourceDefinition).once();
CustomResourceDefinition crd = client.apiextensions().v1beta1().customResourceDefinitions().withName("sparkclusters.radanalytics.io").get();
assertNotNull(crd);
assertEquals("sparkclusters.radanalytics.io", crd.getMetadata().getName());
}
use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition in project kubernetes-client by fabric8io.
the class SerializationTest method asYamlWithDeserializedCRD.
@Test
void asYamlWithDeserializedCRD() throws Exception {
// Given
final String input = readYamlToString("/serialization/test-crd-schema.yml");
final CustomResourceDefinition crd = Serialization.unmarshal(input, CustomResourceDefinition.class);
// When
final String result = Serialization.asYaml(crd);
// Then
assertThat(result.trim()).isEqualTo(input.trim());
}
use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition in project kubernetes-client by fabric8io.
the class GenericKubernetesResourceExample method main.
public static void main(String[] args) throws Exception {
final ConfigBuilder configBuilder = new ConfigBuilder();
configBuilder.withWatchReconnectInterval(500);
configBuilder.withWatchReconnectLimit(5);
try (KubernetesClient client = new KubernetesClientBuilder().withConfig(configBuilder.build()).build()) {
String namespace = "default";
CustomResourceDefinition prometheousRuleCrd = client.apiextensions().v1beta1().customResourceDefinitions().load(GenericKubernetesResourceExample.class.getResourceAsStream("/prometheous-rule-crd.yml")).get();
client.apiextensions().v1beta1().customResourceDefinitions().createOrReplace(prometheousRuleCrd);
logger.info("Successfully created Prometheous custom resource definition");
// Creating Custom Resources Now:
ResourceDefinitionContext crdContext = CustomResourceDefinitionContext.fromCrd(prometheousRuleCrd);
client.load(GenericKubernetesResourceExample.class.getResourceAsStream("/prometheous-rule-cr.yml")).inNamespace(namespace).createOrReplace();
logger.info("Created Custom Resource successfully too");
// Listing all custom resources in given namespace:
NonNamespaceOperation<GenericKubernetesResource, GenericKubernetesResourceList, Resource<GenericKubernetesResource>> resourcesInNamespace = client.genericKubernetesResources(crdContext).inNamespace(namespace);
GenericKubernetesResourceList list = resourcesInNamespace.list();
List<GenericKubernetesResource> items = list.getItems();
logger.info("Custom Resources :- ");
for (GenericKubernetesResource customResource : items) {
ObjectMeta metadata = customResource.getMetadata();
final String name = metadata.getName();
logger.info(name);
}
// Watching custom resources now
logger.info("Watching custom resources now");
final CountDownLatch closeLatch = new CountDownLatch(1);
resourcesInNamespace.watch(new Watcher<GenericKubernetesResource>() {
@Override
public void eventReceived(Action action, GenericKubernetesResource resource) {
logger.info("{}: {}", action, resource);
}
@Override
public void onClose(WatcherException e) {
logger.debug("Watcher onClose");
closeLatch.countDown();
if (e != null) {
logger.error(e.getMessage(), e);
}
}
});
closeLatch.await(10, TimeUnit.MINUTES);
// Cleanup
logger.info("Deleting custom resources...");
resourcesInNamespace.withName("prometheus-example-rules").delete();
client.apiextensions().v1beta1().customResourceDefinitions().withName(prometheousRuleCrd.getMetadata().getName()).delete();
} catch (KubernetesClientException e) {
logger.error("Could not create resource: {}", e.getMessage(), e);
}
}
use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition in project kubernetes-client by fabric8io.
the class ListCustomResourceDefinitions method main.
public static void main(String[] args) {
try (KubernetesClient client = new KubernetesClientBuilder().build()) {
if (!client.supportsApiPath("/apis/apiextensions.k8s.io/v1beta1") && !client.supportsApiPath("/apis/apiextensions.k8s.io/v1")) {
System.out.println("WARNING this cluster does not support the API Group apiextensions.k8s.io");
return;
}
CustomResourceDefinitionList list = client.apiextensions().v1beta1().customResourceDefinitions().list();
if (list == null) {
System.out.println("ERROR no list returned!");
return;
}
List<CustomResourceDefinition> items = list.getItems();
for (CustomResourceDefinition item : items) {
System.out.println("CustomResourceDefinition " + item.getMetadata().getName() + " has version: " + item.getApiVersion());
}
} catch (KubernetesClientException e) {
System.out.println("Failed: " + e);
e.printStackTrace();
}
}
use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition in project kubernetes-client by fabric8io.
the class V1CustomResourceDefinitionTest method testGet.
@Test
void testGet() {
server.expect().get().withPath("/apis/apiextensions.k8s.io/v1/customresourcedefinitions/sparkclusters.radanalytics.io").andReturn(HttpURLConnection.HTTP_OK, customResourceDefinition).once();
CustomResourceDefinition crd = client.apiextensions().v1().customResourceDefinitions().withName("sparkclusters.radanalytics.io").get();
assertNotNull(crd);
assertEquals("sparkclusters.radanalytics.io", crd.getMetadata().getName());
}
Aggregations