Move to logging package (#191)
* Updating comment to remove references to Caddy * Updating README to mark TODO items complete * Changing all debug print statements over to use logging package
This commit is contained in:
parent
3f4ec783d2
commit
3ba86f2421
9 changed files with 40 additions and 53 deletions
|
@ -1,4 +1,4 @@
|
|||
// Package caddy implements the CoreDNS web server as a service
|
||||
// Package core implements the CoreDNS web server as a service
|
||||
// in your own Go programs.
|
||||
//
|
||||
// To use this package, follow a few simple steps:
|
||||
|
@ -7,10 +7,10 @@
|
|||
// 2. Call LoadCorefile() to get the Corefile (it
|
||||
// might have been piped in as part of a restart).
|
||||
// You should pass in your own Corefile loader.
|
||||
// 3. Call caddy.Start() to start CoreDNS, caddy.Stop()
|
||||
// to stop it, or caddy.Restart() to restart it.
|
||||
// 3. Call core.Start() to start CoreDNS, core.Stop()
|
||||
// to stop it, or core.Restart() to restart it.
|
||||
//
|
||||
// You should use caddy.Wait() to wait for all CoreDNS servers
|
||||
// You should use core.Wait() to wait for all CoreDNS servers
|
||||
// to quit before your process exits.
|
||||
package core
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ package setup
|
|||
import (
|
||||
//"crypto/tls"
|
||||
//"crypto/x509"
|
||||
"fmt"
|
||||
"log"
|
||||
//"io/ioutil"
|
||||
//"net"
|
||||
//"net/http"
|
||||
|
@ -27,7 +27,7 @@ const (
|
|||
|
||||
// Kubernetes sets up the kubernetes middleware.
|
||||
func Kubernetes(c *Controller) (middleware.Middleware, error) {
|
||||
fmt.Println("controller %v", c)
|
||||
log.Printf("[debug] controller %v\n", c)
|
||||
// TODO: Determine if subzone support required
|
||||
|
||||
kubernetes, err := kubernetesParse(c)
|
||||
|
@ -115,6 +115,5 @@ func kubernetesParse(c *Controller) (kubernetes.Kubernetes, error) {
|
|||
return k8s, nil
|
||||
}
|
||||
}
|
||||
fmt.Println("here before return")
|
||||
return kubernetes.Kubernetes{}, nil
|
||||
}
|
||||
|
|
|
@ -255,7 +255,7 @@ TBD:
|
|||
* Do wildcards search across namespaces? (Yes)
|
||||
* Initial implementation assumes that a namespace maps to the first DNS label
|
||||
below the zone managed by the kubernetes middleware. This assumption may
|
||||
need to be revised.
|
||||
need to be revised. (Template scheme for record names removes this assumption.)
|
||||
|
||||
|
||||
## TODO
|
||||
|
@ -280,12 +280,13 @@ TBD:
|
|||
* Calculate SRV priority based on number of instances running.
|
||||
(See SkyDNS README.md)
|
||||
* Functional work
|
||||
* Implement wildcard-based lookup. Minimally support `*`, consider `?` as well.
|
||||
* Note from Miek on PR 181: "SkyDNS also supports the word `any`.
|
||||
* (done) ~~Implement wildcard-based lookup. Minimally support `*`, consider `?` as well.~~
|
||||
* (done) ~~Note from Miek on PR 181: "SkyDNS also supports the word `any`.~~
|
||||
* Implement SkyDNS-style synthetic zones such as "svc" to group k8s objects. (This
|
||||
should be optional behavior.) Also look at "pod" synthetic zones.
|
||||
* Implement test cases for SkyDNS equivalent functionality.
|
||||
* SkyDNS functionality, as listed in SkyDNS README: https://github.com/kubernetes/kubernetes/blob/release-1.2/cluster/addons/dns/README.md
|
||||
* Expose pods and srv objects.
|
||||
* A records in form of `pod-ip-address.my-namespace.cluster.local`.
|
||||
For example, a pod with ip `1.2.3.4` in the namespace `default`
|
||||
with a dns name of `cluster.local` would have an entry:
|
||||
|
|
|
@ -2,6 +2,7 @@ package kubernetes
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/miekg/coredns/middleware"
|
||||
|
||||
|
@ -10,7 +11,7 @@ import (
|
|||
)
|
||||
|
||||
func (k Kubernetes) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||
fmt.Printf("[debug] here entering ServeDNS: ctx:%v dnsmsg:%v\n", ctx, r)
|
||||
log.Printf("[debug] here entering ServeDNS: ctx:%v dnsmsg:%v\n", ctx, r)
|
||||
|
||||
state := middleware.State{W: w, Req: r}
|
||||
if state.QClass() != dns.ClassINET {
|
||||
|
|
|
@ -2,7 +2,7 @@ package k8sclient
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
@ -55,7 +55,7 @@ func (c *K8sConnector) GetResourceList() (*ResourceList, error) {
|
|||
err := parseJson(url, resources)
|
||||
// TODO: handle no response from k8s
|
||||
if err != nil {
|
||||
fmt.Printf("[ERROR] Response from kubernetes API for GetResourceList() is: %v\n", err)
|
||||
log.Printf("[ERROR] Response from kubernetes API for GetResourceList() is: %v\n", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ func (c *K8sConnector) GetNamespaceList() (*NamespaceList, error) {
|
|||
url := makeURL([]string{c.baseURL, apiBase, apiNamespaces})
|
||||
err := parseJson(url, namespaces)
|
||||
if err != nil {
|
||||
fmt.Printf("[ERROR] Response from kubernetes API for GetNamespaceList() is: %v\n", err)
|
||||
log.Printf("[ERROR] Response from kubernetes API for GetNamespaceList() is: %v\n", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,7 @@ func (c *K8sConnector) GetServiceList() (*ServiceList, error) {
|
|||
err := parseJson(url, services)
|
||||
// TODO: handle no response from k8s
|
||||
if err != nil {
|
||||
fmt.Printf("[ERROR] Response from kubernetes API for GetServiceList() is: %v\n", err)
|
||||
log.Printf("[ERROR] Response from kubernetes API for GetServiceList() is: %v\n", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -98,7 +98,7 @@ func (c *K8sConnector) GetServicesByNamespace() (map[string][]ServiceItem, error
|
|||
k8sServiceList, err := c.GetServiceList()
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("[ERROR] Getting service list produced error: %v", err)
|
||||
log.Printf("[ERROR] Getting service list produced error: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ package kubernetes
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/miekg/coredns/middleware"
|
||||
|
@ -62,20 +62,9 @@ func (g Kubernetes) Records(name string, exact bool) ([]msg.Service, error) {
|
|||
typeName string
|
||||
)
|
||||
|
||||
fmt.Println("[debug] enter Records('", name, "', ", exact, ")")
|
||||
log.Printf("[debug] enter Records('%v', '%v')\n", name, exact)
|
||||
zone, serviceSegments := g.getZoneForName(name)
|
||||
|
||||
/*
|
||||
// For initial implementation, assume namespace is first serviceSegment
|
||||
// and service name is remaining segments.
|
||||
serviceSegLen := len(serviceSegments)
|
||||
if serviceSegLen >= 2 {
|
||||
namespace = serviceSegments[serviceSegLen-1]
|
||||
serviceName = strings.Join(serviceSegments[:serviceSegLen-1], ".")
|
||||
}
|
||||
// else we are looking up the zone. So handle the NS, SOA records etc.
|
||||
*/
|
||||
|
||||
// TODO: Implementation above globbed together segments for the serviceName if
|
||||
// multiple segments remained. Determine how to do similar globbing using
|
||||
// the template-based implementation.
|
||||
|
@ -85,22 +74,22 @@ func (g Kubernetes) Records(name string, exact bool) ([]msg.Service, error) {
|
|||
|
||||
if namespace == "" {
|
||||
err := errors.New("Parsing query string did not produce a namespace value. Assuming wildcard namespace.")
|
||||
fmt.Printf("[WARN] %v\n", err)
|
||||
log.Printf("[WARN] %v\n", err)
|
||||
namespace = util.WildcardStar
|
||||
}
|
||||
|
||||
if serviceName == "" {
|
||||
err := errors.New("Parsing query string did not produce a serviceName value. Assuming wildcard serviceName.")
|
||||
fmt.Printf("[WARN] %v\n", err)
|
||||
log.Printf("[WARN] %v\n", err)
|
||||
serviceName = util.WildcardStar
|
||||
}
|
||||
|
||||
fmt.Println("[debug] exact: ", exact)
|
||||
fmt.Println("[debug] zone: ", zone)
|
||||
fmt.Println("[debug] servicename: ", serviceName)
|
||||
fmt.Println("[debug] namespace: ", namespace)
|
||||
fmt.Println("[debug] typeName: ", typeName)
|
||||
fmt.Println("[debug] APIconn: ", g.APIConn)
|
||||
log.Printf("[debug] exact: %v\n", exact)
|
||||
log.Printf("[debug] zone: %v\n", zone)
|
||||
log.Printf("[debug] servicename: %v\n", serviceName)
|
||||
log.Printf("[debug] namespace: %v\n", namespace)
|
||||
log.Printf("[debug] typeName: %v\n", typeName)
|
||||
log.Printf("[debug] APIconn: %v\n", g.APIConn)
|
||||
|
||||
nsWildcard := util.SymbolContainsWildcard(namespace)
|
||||
serviceWildcard := util.SymbolContainsWildcard(serviceName)
|
||||
|
@ -108,14 +97,14 @@ func (g Kubernetes) Records(name string, exact bool) ([]msg.Service, error) {
|
|||
// Abort if the namespace does not contain a wildcard, and namespace is not published per CoreFile
|
||||
// Case where namespace contains a wildcard is handled in Get(...) method.
|
||||
if (!nsWildcard) && (g.Namespaces != nil && !util.StringInSlice(namespace, *g.Namespaces)) {
|
||||
fmt.Printf("[debug] Namespace '%v' is not published by Corefile\n", namespace)
|
||||
log.Printf("[debug] Namespace '%v' is not published by Corefile\n", namespace)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
k8sItems, err := g.Get(namespace, nsWildcard, serviceName, serviceWildcard)
|
||||
fmt.Println("[debug] k8s items:", k8sItems)
|
||||
log.Printf("[debug] k8s items: %v\n", k8sItems)
|
||||
if err != nil {
|
||||
fmt.Printf("[ERROR] Got error while looking up ServiceItems. Error is: %v\n", err)
|
||||
log.Printf("[ERROR] Got error while looking up ServiceItems. Error is: %v\n", err)
|
||||
return nil, err
|
||||
}
|
||||
if k8sItems == nil {
|
||||
|
@ -133,7 +122,7 @@ func (g Kubernetes) getRecordsForServiceItems(serviceItems []k8sc.ServiceItem, v
|
|||
|
||||
for _, item := range serviceItems {
|
||||
clusterIP := item.Spec.ClusterIP
|
||||
fmt.Println("[debug] clusterIP:", clusterIP)
|
||||
log.Printf("[debug] clusterIP: %v\n", clusterIP)
|
||||
|
||||
// Create records by constructing record name from template...
|
||||
//values.Namespace = item.Metadata.Namespace
|
||||
|
@ -143,13 +132,13 @@ func (g Kubernetes) getRecordsForServiceItems(serviceItems []k8sc.ServiceItem, v
|
|||
|
||||
// Create records for each exposed port...
|
||||
for _, p := range item.Spec.Ports {
|
||||
fmt.Println("[debug] port:", p.Port)
|
||||
log.Printf("[debug] port: %v\n", p.Port)
|
||||
s := msg.Service{Host: clusterIP, Port: p.Port}
|
||||
records = append(records, s)
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("[debug] records from getRecordsForServiceItems(): %v\n", records)
|
||||
log.Printf("[debug] records from getRecordsForServiceItems(): %v\n", records)
|
||||
return records
|
||||
}
|
||||
|
||||
|
@ -158,7 +147,7 @@ func (g Kubernetes) Get(namespace string, nsWildcard bool, servicename string, s
|
|||
serviceList, err := g.APIConn.GetServiceList()
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("[ERROR] Getting service list produced error: %v", err)
|
||||
log.Printf("[ERROR] Getting service list produced error: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -169,7 +158,7 @@ func (g Kubernetes) Get(namespace string, nsWildcard bool, servicename string, s
|
|||
// If namespace has a wildcard, filter results against Corefile namespace list.
|
||||
// (Namespaces without a wildcard were filtered before the call to this function.)
|
||||
if nsWildcard && (g.Namespaces != nil && !util.StringInSlice(item.Metadata.Namespace, *g.Namespaces)) {
|
||||
fmt.Printf("[debug] Namespace '%v' is not published by Corefile\n", item.Metadata.Namespace)
|
||||
log.Printf("[debug] Namespace '%v' is not published by Corefile\n", item.Metadata.Namespace)
|
||||
continue
|
||||
}
|
||||
resultItems = append(resultItems, item)
|
||||
|
|
|
@ -2,7 +2,7 @@ package nametemplate
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/miekg/coredns/middleware/kubernetes/util"
|
||||
|
@ -65,7 +65,6 @@ type NameTemplate struct {
|
|||
|
||||
func (t *NameTemplate) SetTemplate(s string) error {
|
||||
var err error
|
||||
fmt.Println()
|
||||
|
||||
t.Element = map[string]int{}
|
||||
|
||||
|
@ -83,10 +82,10 @@ func (t *NameTemplate) SetTemplate(s string) error {
|
|||
if !elementPositionSet {
|
||||
if strings.Contains(v, "{") {
|
||||
err = errors.New("Record name template contains the unknown symbol '" + v + "'")
|
||||
fmt.Printf("[debug] %v\n", err)
|
||||
log.Printf("[debug] %v\n", err)
|
||||
return err
|
||||
} else {
|
||||
fmt.Printf("[debug] Template string has static element '%v'\n", v)
|
||||
log.Printf("[debug] Template string has static element '%v'\n", v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package nametemplate
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
@ -21,7 +20,6 @@ var exampleTemplates = map[string][]int{
|
|||
}
|
||||
|
||||
func TestSetTemplate(t *testing.T) {
|
||||
fmt.Printf("\n")
|
||||
for s, expectedValue := range exampleTemplates {
|
||||
|
||||
n := new(NameTemplate)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package kubernetes
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
@ -24,7 +24,7 @@ func NormalizeZoneList(zones []string) []string {
|
|||
for _, z := range zones {
|
||||
zoneConflict, _ := subzoneConflict(filteredZones, z)
|
||||
if zoneConflict {
|
||||
fmt.Printf("[WARN] new zone '%v' from Corefile conflicts with existing zones: %v\n Ignoring zone '%v'\n", z, filteredZones, z)
|
||||
log.Printf("[WARN] new zone '%v' from Corefile conflicts with existing zones: %v\n Ignoring zone '%v'\n", z, filteredZones, z)
|
||||
} else {
|
||||
filteredZones = append(filteredZones, z)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue