Search in sources :

Example 1 with DomainStatusFields

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

the class MutationApi method domain.

private void domain(final MutationRequest mt) {
    // Collect old and new object
    Domain oldR = (Domain) mt.getAdmissionReview().getRequest().getOldObject();
    Domain newR = (Domain) mt.getAdmissionReview().getRequest().getObject();
    // Create default status
    DomainStatus defStatus = new DomainStatus().withState(DomainStatus.State.PENDING).withMessage("Waiting for DNS records").withDomainStatusFields(new DomainStatusFields(lbServiceIpProducer.get(), false));
    // Get OP
    AdmissionOperation op = getOperation(mt.getAdmissionReview());
    // Ensure status
    switch(op) {
        case // Always set the default status on new objects
        CREATE:
            patch(mt, true, "/status", newR.getStatus(), defStatus);
            break;
        case UPDATE:
            if (newR.getSpec() != null && !newR.getSpec().equals(oldR.getSpec())) {
                // On any change change, set default status
                patch(mt, true, "/status", newR.getStatus(), defStatus);
            } else {
                // Else make sure the old status is not removed
                patch(mt, false, "/status", newR.getStatus(), oldR.getStatus());
            }
            break;
        case DELETE:
            // Do nothing
            break;
    }
    if (newR.getSpec() != null) {
        // Set default TTL
        patch(mt, false, "/spec/dnsTTL", newR.getSpec().getDnsTTL(), 3600);
    }
}
Also used : AdmissionOperation(com.enonic.kubernetes.operator.api.AdmissionOperation) DomainStatusFields(com.enonic.kubernetes.client.v1.domain.DomainStatusFields) Domain(com.enonic.kubernetes.client.v1.domain.Domain) DomainStatus(com.enonic.kubernetes.client.v1.domain.DomainStatus)

Aggregations

Domain (com.enonic.kubernetes.client.v1.domain.Domain)1 DomainStatus (com.enonic.kubernetes.client.v1.domain.DomainStatus)1 DomainStatusFields (com.enonic.kubernetes.client.v1.domain.DomainStatusFields)1 AdmissionOperation (com.enonic.kubernetes.operator.api.AdmissionOperation)1