first implementation without test

This commit is contained in:
ideahitme 2017-03-02 11:11:13 +01:00
parent 4e04f36c6f
commit ef76c7dc73
2 changed files with 65 additions and 1 deletions

View File

@ -14,4 +14,62 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package source
package source
import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/pkg/api/v1"
"k8s.io/client-go/pkg/apis/extensions/v1beta1"
"github.com/kubernetes-incubator/external-dns/endpoint"
)
// IngressSource is an implementation of Ingress for Kubernetes ingress objects.
// Ingress implementation will use the spec.rules.host value for the hostname
// Ingress annotations are ignored
type IngressSource struct {
Client kubernetes.Interface
}
// Endpoints returns endpoint objects for each service that should be processed.
func (sc *IngressSource) Endpoints() ([]endpoint.Endpoint, error) {
ingresses, err := sc.Client.Extensions().Ingresses(v1.NamespaceAll).List(v1.ListOptions{})
if err != nil {
return nil, err
}
endpoints := []endpoint.Endpoint{}
for _, ing := range ingresses.Items {
ingEndpoints := endpointsFromIngress(&ing)
endpoints = append(endpoints, ingEndpoints...)
}
return endpoints, nil
}
// endpointsFromIngress extracts the endpoints from a service object
func endpointsFromIngress(ing *v1beta1.Ingress) []endpoint.Endpoint {
var endpoints []endpoint.Endpoint
for _, rule := range ing.Spec.Rules {
if rule.Host == "" {
continue
}
for _, lb := range ing.Status.LoadBalancer.Ingress {
endpoint := endpoint.Endpoint{
DNSName: rule.Host,
}
if lb.IP != "" {
endpoint.Target = lb.IP
endpoints = append(endpoints, endpoint)
}
if lb.Hostname != "" {
endpoint.Target = lb.Hostname
endpoints = append(endpoints, endpoint)
}
}
}
return endpoints
}

View File

@ -15,3 +15,9 @@ limitations under the License.
*/
package source
import "testing"
func TestEndpoints(t *testing.T) {
}