Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 15 additions & 54 deletions src/dns/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,20 +258,14 @@ impl Store {
// Insert an alias for a stripped search domain.
add_alias(Alias {
name: stripped_name.clone(),
stripped: Some(Stripped {
name: stripped_name.clone(),
search_domain: search_domain.clone(),
}),
stripped: Some(stripped_name.clone()),
});

// If the name can be expanded to a k8s FQDN, add that as well.
for kube_fqdn in self.to_kube_fqdns(&stripped_name, &namespaced_domain) {
add_alias(Alias {
name: kube_fqdn,
stripped: Some(Stripped {
name: stripped_name.clone(),
search_domain: search_domain.clone(),
}),
stripped: Some(stripped_name.clone()),
});
}
}
Expand Down Expand Up @@ -678,31 +672,14 @@ impl Resolver for Store {

// If the service was found by stripping off one of the search domains, create a
// CNAME record to map to the appropriate canonical name.
if let Some(stripped) = service_match.alias.stripped {
if service_match.name.is_wildcard() {
// The match is a wildcard...

// Create a CNAME record that maps from the wildcard with the search domain to
// the wildcard without it.
let cname_record_name = service_match
.name
.clone()
.append_domain(&stripped.search_domain)
.unwrap();
let canonical_name = service_match.name;
records.push(cname_record(cname_record_name, canonical_name));

// For wildcards, continue using the original requested hostname for IP records.
} else {
// The match is NOT a wildcard...

// Create a CNAME record to map from the requested name -> stripped name.
let canonical_name = stripped.name;
records.push(cname_record(requested_name.clone(), canonical_name.clone()));

// Also use the stripped name as the IP record name.
ip_record_name = canonical_name;
}
if let Some(stripped) = service_match.alias.stripped
&& !service_match.name.is_wildcard()
{
// Create a CNAME record to map from the requested name -> stripped name.
records.push(cname_record(requested_name.clone(), stripped.clone()));

// Also use the stripped name as the IP record name.
ip_record_name = stripped;
}

access_log(request, Some(&client), "success", records.len());
Expand Down Expand Up @@ -743,7 +720,7 @@ struct Alias {

/// If `Some`, indicates that this alias was generated from the requested host that
/// was stripped of
stripped: Option<Stripped>,
stripped: Option<Name>,
}

impl Display for Alias {
Expand All @@ -752,16 +729,6 @@ impl Display for Alias {
}
}

/// Created for an alias generated by stripping a search domain from the requested host.
#[derive(Debug)]
struct Stripped {
/// The requested hostname with the `search_domain` removed.
name: Name,

/// The search domain that was removed from the requested host to generate `name`.
search_domain: Name,
}

/// Returned when a server was successfully found for the requested hostname.
#[derive(Debug)]
struct ServerMatch {
Expand Down Expand Up @@ -1329,16 +1296,10 @@ mod tests {
Case {
name: "success: wild card with search domain returns A record correctly",
host: "foo.svc.mesh.company.net.ns1.svc.cluster.local.",
expect_records: vec![
cname(
n("*.svc.mesh.company.net.ns1.svc.cluster.local."),
n("*.svc.mesh.company.net."),
),
a(
n("foo.svc.mesh.company.net.ns1.svc.cluster.local."),
ipv4("10.1.2.3"),
),
],
expect_records: vec![a(
n("foo.svc.mesh.company.net.ns1.svc.cluster.local."),
ipv4("10.1.2.3"),
)],
..Default::default()
},
Case {
Expand Down