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