use of io.fabric8.kubernetes.examples.crds.Dummy in project kubernetes-client by fabric8io.
the class CustomResourceCreateDemoTypeless method main.
public static void main(String[] args) {
try (final KubernetesClient k8s = new KubernetesClientBuilder().build()) {
// Create Custom Resource Context
ResourceDefinitionContext context = new ResourceDefinitionContext.Builder().withGroup("demo.fabric8.io").withKind("Dummy").withPlural("dummies").withNamespaced(true).withVersion("v1").build();
// Load from Yaml
Resource<GenericKubernetesResource> dummyObject = k8s.genericKubernetesResources(context).load(CustomResourceCreateDemoTypeless.class.getResourceAsStream("/test-customresource.yaml"));
// Create Custom Resource
dummyObject.create();
}
}
use of io.fabric8.kubernetes.examples.crds.Dummy in project kubernetes-client by fabric8io.
the class InformTest method testInformGeneric.
@Test
void testInformGeneric() throws InterruptedException {
// Given
GenericKubernetesResource dummy = new GenericKubernetesResource();
dummy.setMetadata(new ObjectMetaBuilder().withName("one").withNamespace("test").build());
dummy.setKind("dummy");
dummy.setApiVersion("demos.fabric8.io/v1");
GenericKubernetesResourceList list = new GenericKubernetesResourceList();
list.setMetadata(new ListMetaBuilder().withResourceVersion("1").build());
list.setItems(Arrays.asList(dummy));
server.expect().withPath("/apis/demos.fabric8.io/v1/namespaces/test/dummies?labelSelector=my-label").andReturn(HttpURLConnection.HTTP_OK, list).once();
server.expect().withPath("/apis/demos.fabric8.io/v1/namespaces/test/dummies?labelSelector=my-label&resourceVersion=1&allowWatchBookmarks=true&watch=true").andUpgradeToWebSocket().open().waitFor(EVENT_WAIT_PERIOD_MS).andEmit(new WatchEvent(dummy, "DELETED")).done().once();
final CountDownLatch deleteLatch = new CountDownLatch(1);
final CountDownLatch addLatch = new CountDownLatch(1);
final ResourceEventHandler<GenericKubernetesResource> handler = new ResourceEventHandler<GenericKubernetesResource>() {
@Override
public void onAdd(GenericKubernetesResource obj) {
addLatch.countDown();
}
@Override
public void onDelete(GenericKubernetesResource obj, boolean deletedFinalStateUnknown) {
deleteLatch.countDown();
}
@Override
public void onUpdate(GenericKubernetesResource oldObj, GenericKubernetesResource newObj) {
}
};
// When
CustomResourceDefinitionContext context = new CustomResourceDefinitionContext.Builder().withKind("Dummy").withScope("Namespaced").withVersion("v1").withGroup("demos.fabric8.io").withPlural("dummies").build();
SharedIndexInformer<GenericKubernetesResource> informer = client.genericKubernetesResources(context).withLabel("my-label").inform(handler);
assertTrue(deleteLatch.await(10, TimeUnit.SECONDS));
assertTrue(addLatch.await(10, TimeUnit.SECONDS));
informer.stop();
}
use of io.fabric8.kubernetes.examples.crds.Dummy in project styx by spotify.
the class KubernetesPodEventTranslatorTest method errorExitCodeOnTerminationLoggingButK8sFallback.
@Test
public void errorExitCodeOnTerminationLoggingButK8sFallback() {
Pod pod = podWithTerminationLogging();
setTerminated(pod, "Failed", 17, "{\"workflow_id\":\"dummy\"}");
assertGeneratesEventsAndTransitions(RunState.State.SUBMITTED, pod, Event.started(WFI), Event.terminate(WFI, Optional.of(17)));
}
use of io.fabric8.kubernetes.examples.crds.Dummy in project styx by spotify.
the class KubernetesCleanupTest method deleteExpiredKubernetesTestNamespaces.
@Test
public void deleteExpiredKubernetesTestNamespaces() {
System.setProperty("styx.test.namespace", "dummy");
System.setProperty("styx.scheduler.port", "18080");
var schedulerConfig = ConfigFactory.load(SCHEDULER_SERVICE_NAME);
var k8s = StyxScheduler.getKubernetesClient(schedulerConfig, "default");
var expiredNamespaces = retry(() -> k8s.namespaces().list()).getItems().stream().filter(ns -> isExpiredTestNamespace(ns.getMetadata().getName(), NOW)).collect(toList());
for (final Namespace namespace : expiredNamespaces) {
var name = namespace.getMetadata().getName();
log.info("Deleting expired k8s test namespace: {}", name);
// Forcibly delete any lingering pods to allow kubernetes to remove the namespace
retry(() -> k8s.inNamespace(name).pods().withGracePeriod(0).delete());
// Skip namespace delete request if it is already terminating
if (namespace.getStatus().getPhase().equalsIgnoreCase("Terminating")) {
log.debug("Namespace already terminating");
continue;
}
try {
retry(() -> k8s.namespaces().delete(namespace));
} catch (Exception e) {
log.error("Failed to delete expired test namespace: {}", name, e);
}
}
}
use of io.fabric8.kubernetes.examples.crds.Dummy in project jkube-integration-tests by jkubeio.
the class SimpleK8sITCase method assertThatShouldApplyResources.
final Pod assertThatShouldApplyResources() throws Exception {
final Pod pod = awaitPod(this).logContains("Started Application in", 40).getKubernetesResource();
awaitService(this, pod.getMetadata().getNamespace()).assertExposed().assertIsNodePort().assertPorts(hasSize(1)).assertPort("http", 8080, true).assertNodePortResponse("http", equalTo("Hello world!")).assertNodePortResponse("http", containsString("This is a dummy file which should be copied inside Dockerfile"), "static-file");
return pod;
}
Aggregations