Search in sources :

Example 6 with Dummy

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();
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) ResourceDefinitionContext(io.fabric8.kubernetes.client.dsl.base.ResourceDefinitionContext) KubernetesClientBuilder(io.fabric8.kubernetes.client.KubernetesClientBuilder) KubernetesClientBuilder(io.fabric8.kubernetes.client.KubernetesClientBuilder) GenericKubernetesResource(io.fabric8.kubernetes.api.model.GenericKubernetesResource)

Example 7 with Dummy

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();
}
Also used : ResourceEventHandler(io.fabric8.kubernetes.client.informers.ResourceEventHandler) CustomResourceDefinitionContext(io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext) ListMetaBuilder(io.fabric8.kubernetes.api.model.ListMetaBuilder) ListMetaBuilder(io.fabric8.kubernetes.api.model.ListMetaBuilder) PodListBuilder(io.fabric8.kubernetes.api.model.PodListBuilder) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) GenericKubernetesResourceList(io.fabric8.kubernetes.api.model.GenericKubernetesResourceList) WatchEvent(io.fabric8.kubernetes.api.model.WatchEvent) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) CountDownLatch(java.util.concurrent.CountDownLatch) GenericKubernetesResource(io.fabric8.kubernetes.api.model.GenericKubernetesResource) Test(org.junit.jupiter.api.Test)

Example 8 with Dummy

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)));
}
Also used : Pod(io.fabric8.kubernetes.api.model.Pod) Test(org.junit.Test)

Example 9 with Dummy

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);
        }
    }
}
Also used : TestNamespaces.isExpiredTestNamespace(com.spotify.styx.e2e_tests.TestNamespaces.isExpiredTestNamespace) StyxScheduler(com.spotify.styx.StyxScheduler) Logger(org.slf4j.Logger) WaitStrategies.exponentialWait(com.github.rholder.retry.WaitStrategies.exponentialWait) RetryerBuilder(com.github.rholder.retry.RetryerBuilder) RetryException(com.github.rholder.retry.RetryException) LoggerFactory(org.slf4j.LoggerFactory) Callable(java.util.concurrent.Callable) Test(org.junit.Test) Instant(java.time.Instant) ExecutionException(java.util.concurrent.ExecutionException) Collectors.toList(java.util.stream.Collectors.toList) Namespace(io.fabric8.kubernetes.api.model.Namespace) StopStrategies.stopAfterDelay(com.github.rholder.retry.StopStrategies.stopAfterDelay) ConfigFactory(com.typesafe.config.ConfigFactory) SCHEDULER_SERVICE_NAME(com.spotify.styx.e2e_tests.EndToEndTestBase.SCHEDULER_SERVICE_NAME) SECONDS(java.util.concurrent.TimeUnit.SECONDS) TestNamespaces.isExpiredTestNamespace(com.spotify.styx.e2e_tests.TestNamespaces.isExpiredTestNamespace) Namespace(io.fabric8.kubernetes.api.model.Namespace) RetryException(com.github.rholder.retry.RetryException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 10 with Dummy

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;
}
Also used : PodAssertion.awaitPod(org.eclipse.jkube.integrationtests.assertions.PodAssertion.awaitPod) Pod(io.fabric8.kubernetes.api.model.Pod)

Aggregations

Test (org.junit.jupiter.api.Test)16 Test (org.junit.Test)12 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)8 Pod (io.fabric8.kubernetes.api.model.Pod)7 HashMap (java.util.HashMap)7 Map (java.util.Map)7 Secret (io.fabric8.kubernetes.api.model.Secret)6 List (java.util.List)6 GenericKubernetesResource (io.fabric8.kubernetes.api.model.GenericKubernetesResource)5 KubernetesClientBuilder (io.fabric8.kubernetes.client.KubernetesClientBuilder)5 Resource (io.fabric8.kubernetes.client.dsl.Resource)5 Date (java.util.Date)5 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)4 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)4 KubernetesVersion (io.strimzi.operator.KubernetesVersion)4 PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)4 ClusterOperatorConfig (io.strimzi.operator.cluster.ClusterOperatorConfig)4 KafkaVersionTestUtils (io.strimzi.operator.cluster.KafkaVersionTestUtils)4 ResourceUtils (io.strimzi.operator.cluster.ResourceUtils)4 ResourceOperatorSupplier (io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier)4