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);
}
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();
}
}
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());
}
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;
}
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));
}
Aggregations