dariuszSki / ziti-agent-wh

Apache License 2.0
0 stars 0 forks source link

configure cluster DNS #19

Closed qrkourier closed 4 months ago

qrkourier commented 4 months ago

Each tproxy sidecar needs cluster DNS configuration to effect precedence:

  1. Ziti DNS
  2. Cluster DNS

For the MVP we can find and inject the coredns or kube-dns ClusterIP by the common label selector: k8s-app=kube-dns

e.g.,

kubectl --namespace kube-system \
get services --selector=k8s-app=kube-dns \
--output go-template='{{range .items}}{{ .spec.clusterIP }}{{"\n"}}{{end}}'
dariuszSki commented 4 months ago

Added this and it can be overwritten by the env var

if len(clusterDnsServiceIP) == 0 {
    dnsService, err := kClient.CoreV1().Services("kube-system").Get(context.TODO(), "kube-dns", metav1.GetOptions{})
    if err != nil {
        klog.Error(err)
    }
    if len(dnsService.Spec.ClusterIP) != 0 {
        clusterDnsServiceIP = dnsService.Spec.ClusterIP
        klog.Infof(fmt.Sprintf("Looked up DNS SVC ClusterIP and is %s", dnsService.Spec.ClusterIP))
    } else {
        klog.Info("Looked up DNS SVC ClusterIP and is not found")
    }
}