Search in sources :

Example 1 with DohAnswer

use of com.enonic.kubernetes.apis.doh.service.DohAnswer in project xp-operator by enonic.

the class OperatorDomainDns method lookupDomain.

private void lookupDomain(final Domain domain) {
    // We do not expect dns records
    if (!domain.getSpec().getDnsRecord()) {
        updateStatus(domain, DomainStatus.State.READY, "OK", false);
        return;
    }
    List<String> ourIps = ips.get();
    // Try to find a records
    List<DohAnswer> aRecords = doh.query("A", domain.getSpec().getHost()).answers();
    if (aRecords.size() > 0) {
        List<String> matches = new LinkedList<>();
        for (DohAnswer r : aRecords) {
            for (String ip : ourIps) {
                if (ip.equals(r.data())) {
                    matches.add(r.data());
                }
            }
        }
        if (matches.size() == ips.get().size()) {
            updateStatus(domain, DomainStatus.State.READY, "External A records match", true);
        } else {
            updateStatus(domain, DomainStatus.State.ERROR, "External A records do not match", false);
        }
        return;
    }
    List<DohAnswer> cnameRecords = doh.query("CNAME", domain.getSpec().getHost()).answers();
    if (cnameRecords.size() == 1) {
        String cnameDomain = cnameRecords.get(0).data();
        boolean realDomainExists = searchers.domain().stream().filter(d -> d.getSpec().getHost().equals(cnameDomain)).count() == 1;
        if (realDomainExists) {
            updateStatus(domain, DomainStatus.State.READY, "External CNAME record matches", true);
        } else {
            updateStatus(domain, DomainStatus.State.ERROR, "External CNAME record does not match", true);
        }
    }
    // No records were found
    updateStatus(domain, DomainStatus.State.ERROR, "No External record found", false);
}
Also used : DohAnswer(com.enonic.kubernetes.apis.doh.service.DohAnswer) LinkedList(java.util.LinkedList)

Aggregations

DohAnswer (com.enonic.kubernetes.apis.doh.service.DohAnswer)1 LinkedList (java.util.LinkedList)1