config: add dns_lookup_family option to customize DNS IP resolution (#1436)

This commit is contained in:
Caleb Doxsey 2020-09-21 15:32:37 -06:00 committed by GitHub
parent 0537dd63d4
commit 54d37e62e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 365 additions and 288 deletions

39
config/validate.go Normal file
View file

@ -0,0 +1,39 @@
package config
import (
"fmt"
"strings"
envoy_config_cluster_v3 "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
)
// DNSLookupFamily values.
const (
DNSLookupFamilyAuto = "AUTO"
DNSLookupFamilyV4Only = "V4_ONLY"
DNSLookupFamilyV6Only = "V6_ONLY"
)
// AllDNSLookupFamilies are all the available DNSLookupFamily values.
var AllDNSLookupFamilies = []string{DNSLookupFamilyV6Only, DNSLookupFamilyV4Only, DNSLookupFamilyAuto}
// ValidateDNSLookupFamily validates the value to confirm its one of the available DNS lookup families.
func ValidateDNSLookupFamily(value string) error {
switch value {
case "", DNSLookupFamilyAuto, DNSLookupFamilyV4Only, DNSLookupFamilyV6Only:
return nil
}
return fmt.Errorf("unknown dns_lookup_family: %s, known families are: %s", value, strings.Join(AllDNSLookupFamilies, ", "))
}
// GetEnvoyDNSLookupFamily gets the envoy DNS lookup family.
func GetEnvoyDNSLookupFamily(value string) envoy_config_cluster_v3.Cluster_DnsLookupFamily {
switch value {
case DNSLookupFamilyV4Only:
return envoy_config_cluster_v3.Cluster_V4_ONLY
case DNSLookupFamilyV6Only:
return envoy_config_cluster_v3.Cluster_V6_ONLY
}
return envoy_config_cluster_v3.Cluster_AUTO
}