Search in sources :

Example 21 with CustomResourceDefinition

use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition in project kubernetes-client by fabric8io.

the class V1CustomResourceDefinitionTest method testCreate.

@Test
void testCreate() {
    server.expect().post().withPath("/apis/apiextensions.k8s.io/v1/customresourcedefinitions").andReturn(HttpURLConnection.HTTP_OK, customResourceDefinition).once();
    CustomResourceDefinition crd = client.apiextensions().v1().customResourceDefinitions().createOrReplace(customResourceDefinition);
    assertNotNull(crd);
    assertEquals("sparkclusters.radanalytics.io", crd.getMetadata().getName());
    // Assertion to test behavior in https://github.com/fabric8io/kubernetes-client/issues/1486
    assertNull(crd.getSpec().getVersions().get(0).getSchema().getOpenAPIV3Schema().getDependencies());
}
Also used : CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition) Test(org.junit.jupiter.api.Test)

Example 22 with CustomResourceDefinition

use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition in project yakc by manusa.

the class CustomResourceDefinitionV1IT method deleteCustomResourceDefinition.

@Test
@DisplayName("deleteCustomResourceDefinition, should delete existing CustomResourceDefinition")
void deleteCustomResourceDefinition() throws IOException {
    // When
    final CustomResourceDefinition result = KC.create(ApiextensionsV1Api.class).deleteCustomResourceDefinition(customResourceDefinitionName).get(// Swagger/OpenAPI is wrong
    CustomResourceDefinition.class);
    // Then
    assertThat(result).isNotNull();
    assertThat(result.getMetadata().getDeletionTimestamp()).isNotNull();
}
Also used : CustomResourceDefinition(com.marcnuri.yakc.model.io.k8s.apiextensionsapiserver.pkg.apis.apiextensions.v1.CustomResourceDefinition) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 23 with CustomResourceDefinition

use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition in project xp-operator by enonic.

the class CrudTest method v1xp7Config.

@Test
void v1xp7Config() throws IOException, URISyntaxException {
    EnonicKubernetesClient client = new DefaultEnonicKubernetesClient(server.getClient());
    // Create crd
    CustomResourceDefinition crd = client.k8s().apiextensions().v1().customResourceDefinitions().load(getClass().getResourceAsStream("/crds/configs.yaml")).get();
    client.k8s().apiextensions().v1().customResourceDefinitions().create(crd);
    // Create crd client
    MixedOperation<Xp7Config, Xp7Config.Xp7ConfigList, Resource<Xp7Config>> crdClient = client.enonic().v1().crds().xp7configs();
    // Create resource
    ObjectMetaBuilder metadataBuilder = new ObjectMetaBuilder().withNamespace("test").withName("test-name");
    Xp7Config resource = new Xp7Config().withSpec(new Xp7ConfigSpec().withData("test").withFile("test.cfg").withNodeGroup("test"));
    resource.setMetadata(metadataBuilder.build());
    assertCrd(resource, "/crud-config.json");
    // Send to server
    crdClient.create(resource);
    // List
    Xp7Config.Xp7ConfigList list = crdClient.list();
    assertNotNull(list);
    assertEquals(1, list.getItems().size());
    assertEqualsCrd(resource, list.getItems().get(0));
    assertEquals(resource, list.getItems().get(0));
    // Fetch from server
    Xp7Config get = crdClient.withName("test-name").get();
    assertNotNull(get);
    assertEquals(resource, get);
    // Test put
    resource.setMetadata(metadataBuilder.withLabels(Map.of("test2", "test2")).build());
    resource.setSpec(new Xp7ConfigSpec().withData("test2").withFile("test2.cfg").withNodeGroup("test2"));
    crdClient.withName("test-name").replace(resource);
    // Delete from server
    assertTrue(crdClient.withName("test-name").delete());
}
Also used : Xp7Config(com.enonic.kubernetes.client.v1.xp7config.Xp7Config) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition) Resource(io.fabric8.kubernetes.client.dsl.Resource) CustomResource(io.fabric8.kubernetes.client.CustomResource) Xp7ConfigSpec(com.enonic.kubernetes.client.v1.xp7config.Xp7ConfigSpec) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) Test(org.junit.jupiter.api.Test)

Example 24 with CustomResourceDefinition

use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition in project xp-operator by enonic.

the class CrudTest method assertContext.

private void assertContext(final CustomResourceDefinition customResourceDefinition, final CustomResourceDefinitionContext customResourceDefinitionContext) {
    String version = null;
    for (CustomResourceDefinitionVersion v : customResourceDefinition.getSpec().getVersions()) {
        if (v.getName().equals(customResourceDefinitionContext.getVersion())) {
            version = v.getName();
        }
    }
    assertEquals(String.format("%s.%s", customResourceDefinition.getSpec().getNames().getPlural(), customResourceDefinition.getSpec().getGroup()), customResourceDefinitionContext.getName());
    assertEquals(customResourceDefinition.getSpec().getGroup(), customResourceDefinitionContext.getGroup());
    assertEquals(customResourceDefinition.getSpec().getScope(), customResourceDefinitionContext.getScope());
    assertEquals(customResourceDefinition.getSpec().getNames().getPlural(), customResourceDefinitionContext.getPlural());
    assertEquals(customResourceDefinition.getSpec().getVersions().get(0).getName(), customResourceDefinitionContext.getVersion());
    assertEquals(customResourceDefinition.getSpec().getNames().getKind(), customResourceDefinitionContext.getKind());
    assertEquals(version, customResourceDefinitionContext.getVersion());
}
Also used : CustomResourceDefinitionVersion(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinitionVersion)

Example 25 with CustomResourceDefinition

use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition in project xp-operator by enonic.

the class CrudTest method v1Domain.

@Test
void v1Domain() throws IOException, URISyntaxException {
    EnonicKubernetesClient client = new DefaultEnonicKubernetesClient(server.getClient());
    // Create crd
    CustomResourceDefinition crd = client.k8s().apiextensions().v1().customResourceDefinitions().load(getClass().getResourceAsStream("/crds/domains.yaml")).get();
    client.k8s().apiextensions().v1().customResourceDefinitions().create(crd);
    // Create crd client
    MixedOperation<Domain, Domain.DomainList, Resource<Domain>> crdClient = client.enonic().v1().crds().domains();
    // Create resource
    ObjectMetaBuilder metadataBuilder = new ObjectMetaBuilder().withName("test-name");
    Domain resource = new Domain().withSpec(new DomainSpec().withHost("test.host.com").withCdn(true).withDnsRecord(true).withDomainSpecCertificate(new DomainSpecCertificate().withAuthority(DomainSpecCertificate.Authority.SELF_SIGNED)));
    resource.setMetadata(metadataBuilder.build());
    assertCrd(resource, "/crud-domain.json");
    // Send to server
    crdClient.create(resource);
    // List
    Domain.DomainList list = crdClient.list();
    assertNotNull(list);
    assertEquals(1, list.getItems().size());
    assertEqualsCrd(resource, list.getItems().get(0));
    // Fetch from server
    Domain get = crdClient.withName("test-name").get();
    assertNotNull(get);
    assertEquals(resource, get);
    // Test put
    resource.setMetadata(metadataBuilder.withLabels(Map.of("test2", "test2")).build());
    resource.setSpec(resource.getSpec().withHost("new.host.com"));
    crdClient.withName("test-name").replace(resource);
    // Delete from server
    assertTrue(crdClient.withName("test-name").delete());
}
Also used : DomainSpec(com.enonic.kubernetes.client.v1.domain.DomainSpec) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition) Resource(io.fabric8.kubernetes.client.dsl.Resource) CustomResource(io.fabric8.kubernetes.client.CustomResource) DomainSpecCertificate(com.enonic.kubernetes.client.v1.domain.DomainSpecCertificate) Domain(com.enonic.kubernetes.client.v1.domain.Domain) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

CustomResourceDefinition (io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition)60 Test (org.junit.jupiter.api.Test)49 CustomResourceDefinition (io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition)30 Description (io.qameta.allure.Description)12 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)11 IOException (java.io.IOException)11 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)10 CustomResourceDefinitionBuilder (io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinitionBuilder)10 Resource (io.fabric8.kubernetes.client.dsl.Resource)10 CustomResourceDefinitionContext (io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext)10 ArrayList (java.util.ArrayList)10 BeforeEach (org.junit.jupiter.api.BeforeEach)10 CustomResource (io.fabric8.kubernetes.client.CustomResource)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)7 StartupEvent (io.quarkus.runtime.StartupEvent)7 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)6 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)6 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)6 ServiceAccount (io.fabric8.kubernetes.api.model.ServiceAccount)6