Fix k8s client (#379)
* Fix k8s client to use client-go * Fix Kubernetes Build Issue The client-go code requires you to vendor. I have done a hack here in the Makefile to vendor it to version 1.5. But looks like we will need to do this the 'right' way soon. * Convert v1 to api Objects in List Functions Also removed the endpoint controller which was not used for anything. The Watch functions may still need the same treatment. * Vendor client-go release-1.5 * Fix basic SRV feature This is actually not serving SRV records correctly, but this should get it to work as it did prior to the k8s client changes. Another fix will be needed to serve SRV records as defined in the spec. * Add additional output in test result Add the response to the test output. * Fix erroneous test data
This commit is contained in:
parent
775d26c5e2
commit
229c82c418
1339 changed files with 705368 additions and 77 deletions
|
@ -5,6 +5,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -17,13 +18,13 @@ import (
|
|||
"github.com/miekg/coredns/request"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
unversionedapi "k8s.io/kubernetes/pkg/api/unversioned"
|
||||
clientset_generated "k8s.io/kubernetes/pkg/client/clientset_generated/release_1_4"
|
||||
"k8s.io/kubernetes/pkg/client/restclient"
|
||||
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
|
||||
clientcmdapi "k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api"
|
||||
"k8s.io/kubernetes/pkg/labels"
|
||||
"k8s.io/client-go/1.5/pkg/api"
|
||||
unversionedapi "k8s.io/client-go/1.5/pkg/api/unversioned"
|
||||
"k8s.io/client-go/1.5/kubernetes"
|
||||
"k8s.io/client-go/1.5/rest"
|
||||
"k8s.io/client-go/1.5/tools/clientcmd"
|
||||
clientcmdapi "k8s.io/client-go/1.5/tools/clientcmd/api"
|
||||
"k8s.io/client-go/1.5/pkg/labels"
|
||||
)
|
||||
|
||||
// Kubernetes implements a middleware that connects to a Kubernetes cluster.
|
||||
|
@ -65,7 +66,7 @@ func (k *Kubernetes) Debug() string {
|
|||
return "debug"
|
||||
}
|
||||
|
||||
func (k *Kubernetes) getClientConfig() (*restclient.Config, error) {
|
||||
func (k *Kubernetes) getClientConfig() (*rest.Config, error) {
|
||||
// For a custom api server or running outside a k8s cluster
|
||||
// set URL in env.KUBERNETES_MASTER or set endpoint in Corefile
|
||||
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
|
||||
|
@ -75,7 +76,7 @@ func (k *Kubernetes) getClientConfig() (*restclient.Config, error) {
|
|||
if len(k.APIEndpoint) > 0 {
|
||||
clusterinfo.Server = k.APIEndpoint
|
||||
} else {
|
||||
cc, err := restclient.InClusterConfig()
|
||||
cc, err := rest.InClusterConfig()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -104,7 +105,7 @@ func (k *Kubernetes) InitKubeCache() error {
|
|||
return err
|
||||
}
|
||||
|
||||
kubeClient, err := clientset_generated.NewForConfig(config)
|
||||
kubeClient, err := kubernetes.NewForConfig(config)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to create kubernetes notification controller: %v", err)
|
||||
}
|
||||
|
@ -198,7 +199,7 @@ func (k *Kubernetes) Records(name string, exact bool) ([]msg.Service, error) {
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
k8sItems, err := k.Get(namespace, nsWildcard, serviceName, serviceWildcard)
|
||||
k8sItems, err := k.Get(namespace, nsWildcard, serviceName, serviceWildcard, typeName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -207,26 +208,22 @@ func (k *Kubernetes) Records(name string, exact bool) ([]msg.Service, error) {
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
records := k.getRecordsForServiceItems(k8sItems, nametemplate.NameValues{TypeName: typeName, ServiceName: serviceName, Namespace: namespace, Zone: zone})
|
||||
records := k.getRecordsForServiceItems(k8sItems, zone)
|
||||
return records, nil
|
||||
}
|
||||
|
||||
// TODO: assemble name from parts found in k8s data based on name template rather than reusing query string
|
||||
func (k *Kubernetes) getRecordsForServiceItems(serviceItems []*api.Service, values nametemplate.NameValues) []msg.Service {
|
||||
func (k *Kubernetes) getRecordsForServiceItems(serviceItems []*api.Service, zone string) []msg.Service {
|
||||
var records []msg.Service
|
||||
|
||||
for _, item := range serviceItems {
|
||||
clusterIP := item.Spec.ClusterIP
|
||||
|
||||
// Create records by constructing record name from template...
|
||||
//values.Namespace = item.Metadata.Namespace
|
||||
//values.ServiceName = item.Metadata.Name
|
||||
//s := msg.Service{Host: g.NameTemplate.GetRecordNameFromNameValues(values)}
|
||||
//records = append(records, s)
|
||||
|
||||
// Create records for each exposed port...
|
||||
for _, p := range item.Spec.Ports {
|
||||
s := msg.Service{Host: clusterIP, Port: int(p.Port)}
|
||||
key := k.NameTemplate.RecordNameFromNameValues(nametemplate.NameValues{TypeName: "svc", ServiceName: item.ObjectMeta.Name, Namespace: item.ObjectMeta.Namespace, Zone: zone})
|
||||
key = strings.Replace(key, ".", "/", -1)
|
||||
|
||||
for i, p := range item.Spec.Ports {
|
||||
s := msg.Service{Key: msg.Path(strconv.Itoa(i) + "." + key, "coredns"), Host: clusterIP, Port: int(p.Port)}
|
||||
records = append(records, s)
|
||||
}
|
||||
}
|
||||
|
@ -235,7 +232,16 @@ func (k *Kubernetes) getRecordsForServiceItems(serviceItems []*api.Service, valu
|
|||
}
|
||||
|
||||
// Get performs the call to the Kubernetes http API.
|
||||
func (k *Kubernetes) Get(namespace string, nsWildcard bool, servicename string, serviceWildcard bool) ([]*api.Service, error) {
|
||||
func (k *Kubernetes) Get(namespace string, nsWildcard bool, servicename string, serviceWildcard bool, typeName string) ([]*api.Service, error) {
|
||||
switch {
|
||||
case typeName == "pod":
|
||||
return nil, fmt.Errorf("pod not implemented")
|
||||
default:
|
||||
return k.getServices(namespace, nsWildcard, servicename, serviceWildcard)
|
||||
}
|
||||
}
|
||||
|
||||
func (k *Kubernetes) getServices(namespace string, nsWildcard bool, servicename string, serviceWildcard bool) ([]*api.Service, error) {
|
||||
serviceList := k.APIConn.ServiceList()
|
||||
|
||||
var resultItems []*api.Service
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue