Search in sources :

Example 41 with Version

use of io.fabric8.kubernetes.model.annotation.Version in project kubernetes-client by fabric8io.

the class KubernetesVersionFactoryTest method compareTo_nonKubernetesVersion_with_minor_should_be_less_than_version_without_minor.

@Test
void compareTo_nonKubernetesVersion_with_minor_should_be_less_than_version_without_minor() {
    // given
    Version skywalker = NonKubernetesVersion.FACTORY.create("skywalker");
    Version skywalker1 = NonKubernetesVersion.FACTORY.create("skywalker1");
    // when
    // then
    assertThat(skywalker1).isLessThan(skywalker);
}
Also used : NonKubernetesVersion(io.fabric8.kubernetes.client.utils.KubernetesVersionFactory.NonKubernetesVersion) KubernetesVersion(io.fabric8.kubernetes.client.utils.KubernetesVersionFactory.KubernetesVersion) Version(io.fabric8.kubernetes.client.utils.KubernetesVersionFactory.Version) Test(org.junit.jupiter.api.Test)

Example 42 with Version

use of io.fabric8.kubernetes.model.annotation.Version 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();
    }
}
Also used : CustomResourceDefinitionList(io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinitionList) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) KubernetesClientBuilder(io.fabric8.kubernetes.client.KubernetesClientBuilder) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 43 with Version

use of io.fabric8.kubernetes.model.annotation.Version in project kubernetes-client by fabric8io.

the class RouteTest method routeBuilderTest.

@Test
public void routeBuilderTest() {
    Route route = new RouteBuilder().withNewMetadata().withName("fabric8-maven-sample-zero-config").addToLabels("expose", "true").addToLabels("app", "fabric8-maven-sample-zero-config").addToLabels("provider", "fabric8").addToLabels("version", "3.5-SNAPSHOT").addToLabels("group", "io.fabric8").endMetadata().withNewSpec().withHost("www.example.com").withPath("/test").withNewPort().withNewTargetPort().withValue(8080).endTargetPort().endPort().withNewTo().withKind("Service").withName("fabric8-maven-sample-zero-config").withWeight(5).endTo().addToAlternateBackends(new RouteTargetReferenceBuilder().withName("test1").withKind("Service").withWeight(0).build()).addToAlternateBackends(new RouteTargetReferenceBuilder().withName("test2").withKind("Service").withWeight(0).build()).addToAlternateBackends(new RouteTargetReferenceBuilder().withName("test3").withKind("Service").withWeight(0).build()).withNewTls().withTermination("edge").withKey("$(perl -pe 's/\n/\\n/' example-test.key)").withCertificate("$(perl -pe 's/\n/\\n/' example-test.cert)").withCaCertificate("$(perl -pe 's/\n/\\n/' example-test.cert)").withDestinationCACertificate("$(perl -pe 's/\n/\\n/' example-test.cert)").withInsecureEdgeTerminationPolicy("Allow").endTls().withWildcardPolicy("Subdomain").endSpec().build();
    assertNotNull(route);
    assertEquals("fabric8-maven-sample-zero-config", route.getMetadata().getName());
    assertTrue(route.getMetadata().getLabels().get("expose").equals("true"));
    assertTrue(route.getMetadata().getLabels().get("app").equals("fabric8-maven-sample-zero-config"));
    assertTrue(route.getMetadata().getLabels().get("provider").equals("fabric8"));
    assertTrue(route.getMetadata().getLabels().get("version").equals("3.5-SNAPSHOT"));
    assertTrue(route.getMetadata().getLabels().get("group").equals("io.fabric8"));
    assertEquals("www.example.com", route.getSpec().getHost());
    assertEquals("/test", route.getSpec().getPath());
    assertNotNull(route.getSpec().getPort());
    assertEquals(8080, route.getSpec().getPort().getTargetPort().getIntVal().intValue());
    assertNotNull(route.getSpec().getTo());
    assertEquals("Service", route.getSpec().getTo().getKind());
    assertEquals("fabric8-maven-sample-zero-config", route.getSpec().getTo().getName());
    assertEquals("5", route.getSpec().getTo().getWeight().toString());
    assertNotNull(route.getSpec().getAlternateBackends());
    assertEquals(3, route.getSpec().getAlternateBackends().size());
    assertEquals(0, route.getSpec().getAlternateBackends().get(0).getWeight().intValue());
    assertEquals("Service", route.getSpec().getAlternateBackends().get(0).getKind());
    assertEquals(0, route.getSpec().getAlternateBackends().get(1).getWeight().intValue());
    assertEquals("Service", route.getSpec().getAlternateBackends().get(1).getKind());
    assertEquals(0, route.getSpec().getAlternateBackends().get(2).getWeight().intValue());
    assertEquals("Service", route.getSpec().getAlternateBackends().get(2).getKind());
    assertTrue(route.getSpec().getAlternateBackends().get(0).getName().startsWith("test"));
    assertTrue(route.getSpec().getAlternateBackends().get(1).getName().startsWith("test"));
    assertTrue(route.getSpec().getAlternateBackends().get(2).getName().startsWith("test"));
    assertNotNull(route.getSpec().getTls());
    assertEquals("edge", route.getSpec().getTls().getTermination());
    assertEquals("$(perl -pe 's/\n/\\n/' example-test.key)", route.getSpec().getTls().getKey());
    assertEquals("$(perl -pe 's/\n/\\n/' example-test.cert)", route.getSpec().getTls().getCertificate());
    assertEquals("$(perl -pe 's/\n/\\n/' example-test.cert)", route.getSpec().getTls().getCaCertificate());
    assertEquals("$(perl -pe 's/\n/\\n/' example-test.cert)", route.getSpec().getTls().getDestinationCACertificate());
    assertEquals("Allow", route.getSpec().getTls().getInsecureEdgeTerminationPolicy());
    assertEquals("Subdomain", route.getSpec().getWildcardPolicy());
}
Also used : RouteBuilder(io.fabric8.openshift.api.model.RouteBuilder) RouteTargetReferenceBuilder(io.fabric8.openshift.api.model.RouteTargetReferenceBuilder) Route(io.fabric8.openshift.api.model.Route) Test(org.junit.jupiter.api.Test)

Example 44 with Version

use of io.fabric8.kubernetes.model.annotation.Version in project kubernetes-client by fabric8io.

the class KubernetesAttributesExtractor method extract.

public AttributeSet extract(HasMetadata hasMetadata) {
    AttributeSet metadataAttributes = new AttributeSet();
    String apiVersion = hasMetadata.getApiVersion();
    String api = null;
    String version = null;
    if (!Utils.isNullOrEmpty(apiVersion)) {
        api = ApiVersionUtil.trimGroup(apiVersion);
        version = ApiVersionUtil.trimVersion(apiVersion);
        if (!api.equals(apiVersion)) {
            metadataAttributes = metadataAttributes.add(new Attribute(API, api));
        } else {
            api = null;
        }
        metadataAttributes = metadataAttributes.add(new Attribute(VERSION, version));
    }
    if (!Utils.isNullOrEmpty(hasMetadata.getMetadata().getName())) {
        metadataAttributes = metadataAttributes.add(new Attribute(NAME, hasMetadata.getMetadata().getName()));
        metadataAttributes = metadataAttributes.add(new Attribute(METADATA_NAME, hasMetadata.getMetadata().getName()));
    }
    if (!Utils.isNullOrEmpty(hasMetadata.getMetadata().getNamespace())) {
        metadataAttributes = metadataAttributes.add(new Attribute(NAMESPACE, hasMetadata.getMetadata().getNamespace()));
        metadataAttributes = metadataAttributes.add(new Attribute(METADATA_NAMESPACE, hasMetadata.getMetadata().getNamespace()));
    }
    if (hasMetadata.getMetadata().getLabels() != null) {
        for (Map.Entry<String, String> label : hasMetadata.getMetadata().getLabels().entrySet()) {
            metadataAttributes = metadataAttributes.add(new Attribute(LABEL_KEY_PREFIX + label.getKey(), label.getValue()));
        }
    }
    if (!(hasMetadata instanceof GenericKubernetesResource)) {
        metadataAttributes = metadataAttributes.add(new Attribute(PLURAL, hasMetadata.getPlural()));
    } else {
        Optional<CustomResourceDefinitionContext> context = findCrd(api, version);
        if (context.isPresent()) {
            metadataAttributes = metadataAttributes.add(new Attribute(PLURAL, context.get().getPlural()));
        }
    // else we shouldn't infer the plural without a crd registered - it will come from the path instead
    }
    return metadataAttributes;
}
Also used : CustomResourceDefinitionContext(io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext) AttributeSet(io.fabric8.mockwebserver.crud.AttributeSet) Attribute(io.fabric8.mockwebserver.crud.Attribute) HashMap(java.util.HashMap) Map(java.util.Map) GenericKubernetesResource(io.fabric8.kubernetes.api.model.GenericKubernetesResource)

Example 45 with Version

use of io.fabric8.kubernetes.model.annotation.Version in project kubernetes-client by fabric8io.

the class KubernetesAttributesExtractorTest method shouldHandleNamespacedPathWithResource.

@Test
void shouldHandleNamespacedPathWithResource() {
    KubernetesAttributesExtractor extractor = new KubernetesAttributesExtractor();
    AttributeSet attributes = extractor.fromPath("/api/v1/namespaces/myns/pods/mypod");
    AttributeSet expected = new AttributeSet();
    expected = expected.add(new Attribute("plural", "pods"));
    expected = expected.add(new Attribute("namespace", "myns"));
    expected = expected.add(new Attribute("name", "mypod"));
    expected = expected.add(new Attribute("version", "v1"));
    assertTrue(attributes.matches(expected));
    assertFalse(attributes.containsKey(KubernetesAttributesExtractor.API));
}
Also used : AttributeSet(io.fabric8.mockwebserver.crud.AttributeSet) Attribute(io.fabric8.mockwebserver.crud.Attribute) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)164 Map (java.util.Map)112 IOException (java.io.IOException)89 ArrayList (java.util.ArrayList)75 Version (io.fabric8.api.Version)74 File (java.io.File)74 HashMap (java.util.HashMap)71 Profile (io.fabric8.api.Profile)70 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)67 Pod (io.fabric8.kubernetes.api.model.Pod)65 List (java.util.List)65 Test (org.junit.Test)65 Vertx (io.vertx.core.Vertx)60 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)59 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)58 Checkpoint (io.vertx.junit5.Checkpoint)56 VertxExtension (io.vertx.junit5.VertxExtension)56 VertxTestContext (io.vertx.junit5.VertxTestContext)56 BeforeAll (org.junit.jupiter.api.BeforeAll)56 Reconciliation (io.strimzi.operator.common.Reconciliation)52