Search in sources :

Example 1 with Domain

use of com.enonic.kubernetes.client.v1.domain.Domain in project xp-operator by enonic.

the class AdmissionApi method domain.

private void domain(final AdmissionReview admissionReview) {
    AdmissionOperation op = getOperation(admissionReview);
    if (op == AdmissionOperation.DELETE) {
        return;
    }
    Domain newDomain = (Domain) admissionReview.getRequest().getObject();
    // Check spec
    Preconditions.checkState(newDomain.getSpec() != null, "'spec' cannot be null");
    Preconditions.checkState(newDomain.getSpec().getHost() != null, "'spec.host' cannot be null");
    Validator.dns1123("spec.host", newDomain.getSpec().getHost());
    Preconditions.checkState(newDomain.getSpec().getDnsRecord() != null, "'spec.dnsRecord' cannot be null");
    if (newDomain.getSpec().getDnsRecord()) {
        Preconditions.checkState(newDomain.getSpec().getCdn() != null, "'spec.cdn' cannot be null if dnsRecord = true");
    }
    if (newDomain.getSpec().getDomainSpecCertificate() != null) {
        Preconditions.checkState(newDomain.getSpec().getDomainSpecCertificate().getAuthority() != null, "'spec.certificate.authority' cannot be null");
        switch(newDomain.getSpec().getDomainSpecCertificate().getAuthority()) {
            case CUSTOM:
                Preconditions.checkState(newDomain.getSpec().getDomainSpecCertificate().getIdentifier() != null, "'spec.certificate.identifier' cannot be null when authority is CUSTOM");
            case CLUSTER_ISSUER:
                Preconditions.checkState(newDomain.getSpec().getDomainSpecCertificate().getIdentifier() != null, "'spec.certificate.identifier' cannot be null when authority is CLUSTER_ISSUER");
        }
    }
    // Check status
    Preconditions.checkState(newDomain.getStatus() != null, "'status' cannot be null");
    Preconditions.checkState(newDomain.getStatus().getMessage() != null, "'status.message' cannot be null");
    Preconditions.checkState(newDomain.getStatus().getState() != null, "'status.state' cannot be null");
    Preconditions.checkState(newDomain.getStatus().getDomainStatusFields() != null, "'status.fields' cannot be null");
    Preconditions.checkState(newDomain.getStatus().getDomainStatusFields().getDnsRecordCreated() != null, "'status.fields.dnsRecordCreated' cannot be null");
    Preconditions.checkState(newDomain.getStatus().getDomainStatusFields().getPublicIps() != null, "'status.fields.publicIps' cannot be null");
    if (op == AdmissionOperation.UPDATE) {
        Domain oldDomain = (Domain) admissionReview.getRequest().getOldObject();
        Preconditions.checkState(oldDomain.getSpec().getHost().equals(newDomain.getSpec().getHost()), "'spec.host' cannot be changed");
    }
}
Also used : AdmissionOperation(com.enonic.kubernetes.operator.api.AdmissionOperation) Domain(com.enonic.kubernetes.client.v1.domain.Domain)

Example 2 with Domain

use of com.enonic.kubernetes.client.v1.domain.Domain 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)

Example 3 with Domain

use of com.enonic.kubernetes.client.v1.domain.Domain in project legacy-jclouds-examples by jclouds.

the class CreateDomains method createDomains.

private void createDomains() throws TimeoutException {
    System.out.println("Create Domains");
    Record createMXRecord = Record.builder().name(NAME).type("MX").data("mail." + NAME).priority(11235).build();
    Record createARecord = Record.builder().name(NAME).type("A").data("10.0.0.1").build();
    Set<Record> createRecords = ImmutableSet.of(createMXRecord, createARecord);
    CreateSubdomain createSubdomain1 = CreateSubdomain.builder().name("dev." + NAME).email("jclouds@" + NAME).comment("Hello dev subdomain").build();
    CreateSubdomain createSubdomain2 = CreateSubdomain.builder().name("test." + NAME).email("jclouds@" + NAME).comment("Hello test subdomain").build();
    Set<CreateSubdomain> createSubdomains = ImmutableSet.of(createSubdomain1, createSubdomain2);
    CreateDomain createDomain1 = CreateDomain.builder().name(NAME).email("jclouds@" + NAME).ttl(600000).comment("Hello Domain").subdomains(createSubdomains).records(createRecords).build();
    CreateDomain createDomain2 = CreateDomain.builder().name(ALT_NAME).email("jclouds@" + ALT_NAME).ttl(600000).comment("Hello Domain").build();
    Set<CreateDomain> createDomains = ImmutableSet.of(createDomain1, createDomain2);
    Map<String, Domain> domains = DomainFunctions.toDomainMap(awaitComplete(dnsApi, dnsApi.getDomainApi().create(createDomains)));
    System.out.println("  " + domains.get(NAME));
    System.out.println("  " + domains.get(ALT_NAME));
}
Also used : CreateSubdomain(org.jclouds.rackspace.clouddns.v1.domain.CreateSubdomain) CreateDomain(org.jclouds.rackspace.clouddns.v1.domain.CreateDomain) Record(org.jclouds.rackspace.clouddns.v1.domain.Record) CreateDomain(org.jclouds.rackspace.clouddns.v1.domain.CreateDomain) Domain(org.jclouds.rackspace.clouddns.v1.domain.Domain)

Example 4 with Domain

use of com.enonic.kubernetes.client.v1.domain.Domain in project legacy-jclouds-examples by jclouds.

the class ListRecords method main.

/**
 * To get a username and API key see http://www.jclouds.org/documentation/quickstart/rackspace/
 *
 * The first argument (args[0]) must be your username
 * The second argument (args[1]) must be your API key
 */
public static void main(String[] args) {
    ListRecords listRecords = new ListRecords();
    try {
        listRecords.init(args);
        Domain domain = listRecords.getDomain();
        listRecords.listRecords(domain);
        listRecords.listRecordsByNameAndType(domain);
        listRecords.listRecordsByType(domain);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        listRecords.close();
    }
}
Also used : Domain(org.jclouds.rackspace.clouddns.v1.domain.Domain)

Example 5 with Domain

use of com.enonic.kubernetes.client.v1.domain.Domain in project legacy-jclouds-examples by jclouds.

the class UpdateRecords method main.

/**
 * To get a username and API key see http://www.jclouds.org/documentation/quickstart/rackspace/
 *
 * The first argument (args[0]) must be your username
 * The second argument (args[1]) must be your API key
 */
public static void main(String[] args) {
    UpdateRecords updateRecords = new UpdateRecords();
    try {
        updateRecords.init(args);
        Domain domain = updateRecords.getDomain();
        updateRecords.updateRecord(domain);
        updateRecords.updateRecords(domain);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        updateRecords.close();
    }
}
Also used : Domain(org.jclouds.rackspace.clouddns.v1.domain.Domain) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

Domain (org.jclouds.rackspace.clouddns.v1.domain.Domain)9 Domain (com.enonic.kubernetes.client.v1.domain.Domain)4 DomainStatus (com.enonic.kubernetes.client.v1.domain.DomainStatus)2 AdmissionOperation (com.enonic.kubernetes.operator.api.AdmissionOperation)2 TimeoutException (java.util.concurrent.TimeoutException)2 Record (org.jclouds.rackspace.clouddns.v1.domain.Record)2 UpdateDomain (org.jclouds.rackspace.clouddns.v1.domain.UpdateDomain)2 DnsRecordServiceWrapper (com.enonic.kubernetes.apis.cloudflare.DnsRecordServiceWrapper)1 DnsRecord (com.enonic.kubernetes.apis.cloudflare.service.model.DnsRecord)1 ImmutableDnsRecord (com.enonic.kubernetes.apis.cloudflare.service.model.ImmutableDnsRecord)1 DohServiceWrapper (com.enonic.kubernetes.apis.doh.DohServiceWrapper)1 DohAnswer (com.enonic.kubernetes.apis.doh.service.DohAnswer)1 DomainSpec (com.enonic.kubernetes.client.v1.domain.DomainSpec)1 DomainSpecCertificate (com.enonic.kubernetes.client.v1.domain.DomainSpecCertificate)1 DomainStatusFields (com.enonic.kubernetes.client.v1.domain.DomainStatusFields)1 Configuration.cfgIfBool (com.enonic.kubernetes.common.Configuration.cfgIfBool)1 Configuration.cfgStr (com.enonic.kubernetes.common.Configuration.cfgStr)1 RunnableListExecutor (com.enonic.kubernetes.common.functions.RunnableListExecutor)1 Clients (com.enonic.kubernetes.kubernetes.Clients)1 Informers (com.enonic.kubernetes.kubernetes.Informers)1