Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions docs/sources/istio.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ It is meant to supplement the other provider-specific setup tutorials.

**Note:** Using the Istio Gateway source requires Istio >=1.0.0.

* Manifest (for clusters without RBAC enabled)
* Manifest (for clusters with RBAC enabled)
* Update existing ExternalDNS Deployment
**Note:** Currently supported versions are `1.25` and `1.26` with `v1beta1` stored version.

- [Support status of Istio releases](https://istio.io/latest/docs/releases/supported-releases/)

- Manifest (for clusters without RBAC enabled)
- Manifest (for clusters with RBAC enabled)
- Update existing ExternalDNS Deployment

## Manifest (for clusters without RBAC enabled)

Expand Down Expand Up @@ -119,9 +123,9 @@ spec:

## Update existing ExternalDNS Deployment

* For clusters with running `external-dns`, you can just update the deployment.
* With access to the `kube-system` namespace, update the existing `external-dns` deployment.
* Add a parameter to the arguments of the container to create dns entries with `--source=istio-gateway`.
- For clusters with running `external-dns`, you can just update the deployment.
- With access to the `kube-system` namespace, update the existing `external-dns` deployment.
- Add a parameter to the arguments of the container to create dns entries with `--source=istio-gateway`.

Execute the following command or update the argument.

Expand All @@ -148,13 +152,13 @@ The following are relevant snippets from that tutorial.
With automatic sidecar injection:

```bash
kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.6/samples/httpbin/httpbin.yaml
kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.25/samples/httpbin/httpbin.yaml
```

Otherwise:

```bash
kubectl apply -f <(istioctl kube-inject -f https://raw.githubusercontent.com/istio/istio/release-1.6/samples/httpbin/httpbin.yaml)
kubectl apply -f <(istioctl kube-inject -f https://raw.githubusercontent.com/istio/istio/release-1.25/samples/httpbin/httpbin.yaml)
```

### Using a Gateway as a source
Expand Down Expand Up @@ -320,13 +324,13 @@ EOF

## Debug ExternalDNS

* Look for the deployment pod to see the status
- Look for the deployment pod to see the status

```console$ kubectl get pods | grep external-dns
external-dns-6b84999479-4knv9 1/1 Running 0 3h29m
```

* Watch for the logs as follows
- Watch for the logs as follows

```console
kubectl logs -f external-dns-6b84999479-4knv9
Expand All @@ -336,7 +340,7 @@ At this point, you can `create` or `update` any `Istio Gateway` object with `hos

> **ATTENTION**: Make sure to specify those whose account is related to the DNS record.

* Successful executions will print the following
- Successful executions will print the following

```console
time="2020-01-17T06:08:08Z" level=info msg="Desired change: CREATE httpbin.example.com A"
Expand All @@ -345,7 +349,7 @@ time="2020-01-17T06:08:08Z" level=info msg="2 record(s) in zone example.com. wer
time="2020-01-17T06:09:08Z" level=info msg="All records are already up to date, there are no changes for the matching hosted zones"
```

* If there's any problem around `clusterrole`, you would see the errors showing wrong permissions:
- If there's any problem around `clusterrole`, you would see the errors showing wrong permissions:

```console
source \"gateways\" in API group \"networking.istio.io\" at the cluster scope"
Expand Down
2 changes: 0 additions & 2 deletions registry/txt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package registry

import (
"context"
"fmt"
"reflect"
"strings"
"testing"
Expand Down Expand Up @@ -1511,7 +1510,6 @@ func TestNewTXTScheme(t *testing.T) {
assert.Nil(t, ctx.Value(provider.RecordsContextKey))
}
err := r.ApplyChanges(ctx, changes)
fmt.Println(err)
require.NoError(t, err)
}

Expand Down
56 changes: 30 additions & 26 deletions source/istio_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import (
"text/template"

log "github.com/sirupsen/logrus"
networkingv1alpha3 "istio.io/client-go/pkg/apis/networking/v1alpha3"
networkingv1beta1 "istio.io/client-go/pkg/apis/networking/v1beta1"
istioclient "istio.io/client-go/pkg/clientset/versioned"
istioinformers "istio.io/client-go/pkg/informers/externalversions"
networkingv1alpha3informer "istio.io/client-go/pkg/informers/externalversions/networking/v1alpha3"
networkingv1beta1informer "istio.io/client-go/pkg/informers/externalversions/networking/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
kubeinformers "k8s.io/client-go/informers"
Expand Down Expand Up @@ -57,7 +57,7 @@ type gatewaySource struct {
combineFQDNAnnotation bool
ignoreHostnameAnnotation bool
serviceInformer coreinformers.ServiceInformer
gatewayInformer networkingv1alpha3informer.GatewayInformer
gatewayInformer networkingv1beta1informer.GatewayInformer
}

// NewIstioGatewaySource creates a new gatewaySource with the given config.
Expand All @@ -81,18 +81,18 @@ func NewIstioGatewaySource(
informerFactory := kubeinformers.NewSharedInformerFactoryWithOptions(kubeClient, 0, kubeinformers.WithNamespace(namespace))
serviceInformer := informerFactory.Core().V1().Services()
istioInformerFactory := istioinformers.NewSharedInformerFactory(istioClient, 0)
gatewayInformer := istioInformerFactory.Networking().V1alpha3().Gateways()
gatewayInformer := istioInformerFactory.Networking().V1beta1().Gateways()

// Add default resource event handlers to properly initialize informer.
serviceInformer.Informer().AddEventHandler(
_, _ = serviceInformer.Informer().AddEventHandler(
cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
log.Debug("service added")
},
},
)

gatewayInformer.Informer().AddEventHandler(
_, _ = gatewayInformer.Informer().AddEventHandler(
cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
log.Debug("gateway added")
Expand Down Expand Up @@ -127,7 +127,7 @@ func NewIstioGatewaySource(
// Endpoints returns endpoint objects for each host-target combination that should be processed.
// Retrieves all gateway resources in the source's namespace(s).
func (sc *gatewaySource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error) {
gwList, err := sc.istioClient.NetworkingV1alpha3().Gateways(sc.namespace).List(ctx, metav1.ListOptions{})
gwList, err := sc.istioClient.NetworkingV1beta1().Gateways(sc.namespace).List(ctx, metav1.ListOptions{})
if err != nil {
return nil, err
}
Expand All @@ -140,12 +140,14 @@ func (sc *gatewaySource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, e

var endpoints []*endpoint.Endpoint

log.Debugf("Found %d gateways in namespace %s", len(gateways), sc.namespace)

for _, gateway := range gateways {
// Check controller annotation to see if we are responsible.
controller, ok := gateway.Annotations[controllerAnnotationKey]
if ok && controller != controllerAnnotationValue {
log.Debugf("Skipping gateway %s/%s because controller value does not match, found: %s, required: %s",
gateway.Namespace, gateway.Name, controller, controllerAnnotationValue)
log.Debugf("Skipping gateway %s/%s,%s because controller value does not match, found: %s, required: %s",
gateway.Namespace, gateway.APIVersion, gateway.Name, controller, controllerAnnotationValue)
continue
}

Expand All @@ -168,6 +170,8 @@ func (sc *gatewaySource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, e
}
}

log.Debugf("Processing gateway '%s/%s.%s' and hosts %q", gateway.Namespace, gateway.APIVersion, gateway.Name, strings.Join(gwHostnames, ","))

if len(gwHostnames) == 0 {
log.Debugf("No hostnames could be generated from gateway %s/%s", gateway.Namespace, gateway.Name)
continue
Expand All @@ -183,10 +187,11 @@ func (sc *gatewaySource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, e
continue
}

log.Debugf("Endpoints generated from gateway: %s/%s: %v", gateway.Namespace, gateway.Name, gwEndpoints)
log.Debugf("Endpoints generated from %q '%s/%s.%s': %q", gateway.Kind, gateway.Namespace, gateway.APIVersion, gateway.Name, gwEndpoints)
endpoints = append(endpoints, gwEndpoints...)
}

// TODO: sort on endpoint creation
for _, ep := range endpoints {
sort.Sort(ep.Targets)
}
Expand All @@ -198,11 +203,11 @@ func (sc *gatewaySource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, e
func (sc *gatewaySource) AddEventHandler(ctx context.Context, handler func()) {
log.Debug("Adding event handler for Istio Gateway")

sc.gatewayInformer.Informer().AddEventHandler(eventHandlerFunc(handler))
_, _ = sc.gatewayInformer.Informer().AddEventHandler(eventHandlerFunc(handler))
}

// filterByAnnotations filters a list of configs by a given annotation selector.
func (sc *gatewaySource) filterByAnnotations(gateways []*networkingv1alpha3.Gateway) ([]*networkingv1alpha3.Gateway, error) {
func (sc *gatewaySource) filterByAnnotations(gateways []*networkingv1beta1.Gateway) ([]*networkingv1beta1.Gateway, error) {
selector, err := annotations.ParseFilter(sc.annotationFilter)
if err != nil {
return nil, err
Expand All @@ -213,7 +218,7 @@ func (sc *gatewaySource) filterByAnnotations(gateways []*networkingv1alpha3.Gate
return gateways, nil
}

var filteredList []*networkingv1alpha3.Gateway
var filteredList []*networkingv1beta1.Gateway

for _, gw := range gateways {
// include if the annotations match the selector
Expand All @@ -225,7 +230,7 @@ func (sc *gatewaySource) filterByAnnotations(gateways []*networkingv1alpha3.Gate
return filteredList, nil
}

func (sc *gatewaySource) targetsFromIngress(ctx context.Context, ingressStr string, gateway *networkingv1alpha3.Gateway) (endpoint.Targets, error) {
func (sc *gatewaySource) targetsFromIngress(ctx context.Context, ingressStr string, gateway *networkingv1beta1.Gateway) (endpoint.Targets, error) {
namespace, name, err := ParseIngress(ingressStr)
if err != nil {
return nil, fmt.Errorf("failed to parse Ingress annotation on Gateway (%s/%s): %w", gateway.Namespace, gateway.Name, err)
Expand All @@ -251,7 +256,7 @@ func (sc *gatewaySource) targetsFromIngress(ctx context.Context, ingressStr stri
return targets, nil
}

func (sc *gatewaySource) targetsFromGateway(ctx context.Context, gateway *networkingv1alpha3.Gateway) (endpoint.Targets, error) {
func (sc *gatewaySource) targetsFromGateway(ctx context.Context, gateway *networkingv1beta1.Gateway) (endpoint.Targets, error) {
targets := annotations.TargetsFromTargetAnnotation(gateway.Annotations)
if len(targets) > 0 {
return targets, nil
Expand All @@ -266,32 +271,31 @@ func (sc *gatewaySource) targetsFromGateway(ctx context.Context, gateway *networ
}

// endpointsFromGatewayConfig extracts the endpoints from an Istio Gateway Config object
func (sc *gatewaySource) endpointsFromGateway(ctx context.Context, hostnames []string, gateway *networkingv1alpha3.Gateway) ([]*endpoint.Endpoint, error) {
func (sc *gatewaySource) endpointsFromGateway(ctx context.Context, hostnames []string, gateway *networkingv1beta1.Gateway) ([]*endpoint.Endpoint, error) {
var endpoints []*endpoint.Endpoint
var err error

resource := fmt.Sprintf("gateway/%s/%s", gateway.Namespace, gateway.Name)

ttl := annotations.TTLFromAnnotations(gateway.Annotations, resource)
targets, err := sc.targetsFromGateway(ctx, gateway)
if err != nil {
return nil, err
}

targets := annotations.TargetsFromTargetAnnotation(gateway.Annotations)
if len(targets) == 0 {
targets, err = sc.targetsFromGateway(ctx, gateway)
if err != nil {
return nil, err
}
return endpoints, nil
}

resource := fmt.Sprintf("gateway/%s/%s", gateway.Namespace, gateway.Name)
ttl := annotations.TTLFromAnnotations(gateway.Annotations, resource)
providerSpecific, setIdentifier := annotations.ProviderSpecificAnnotations(gateway.Annotations)

for _, host := range hostnames {
endpoints = append(endpoints, endpointsForHostname(host, targets, ttl, providerSpecific, setIdentifier, resource)...)
endpoints = append(endpoints, EndpointsForHostname(host, targets, ttl, providerSpecific, setIdentifier, resource)...)
}

return endpoints, nil
}

func (sc *gatewaySource) hostNamesFromGateway(gateway *networkingv1alpha3.Gateway) ([]string, error) {
func (sc *gatewaySource) hostNamesFromGateway(gateway *networkingv1beta1.Gateway) ([]string, error) {
var hostnames []string
for _, server := range gateway.Spec.Servers {
for _, host := range server.Hosts {
Expand Down
6 changes: 3 additions & 3 deletions source/istio_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
networkingv1alpha3api "istio.io/api/networking/v1alpha3"
networkingv1alpha3 "istio.io/client-go/pkg/apis/networking/v1alpha3"
networkingv1alpha3api "istio.io/api/networking/v1beta1"
networkingv1alpha3 "istio.io/client-go/pkg/apis/networking/v1beta1"
istiofake "istio.io/client-go/pkg/clientset/versioned/fake"
v1 "k8s.io/api/core/v1"
networkv1 "k8s.io/api/networking/v1"
Expand Down Expand Up @@ -1494,7 +1494,7 @@ func testGatewayEndpoints(t *testing.T) {
fakeIstioClient := istiofake.NewSimpleClientset()
for _, config := range ti.configItems {
gatewayCfg := config.Config()
_, err := fakeIstioClient.NetworkingV1alpha3().Gateways(ti.targetNamespace).Create(context.Background(), gatewayCfg, metav1.CreateOptions{})
_, err := fakeIstioClient.NetworkingV1beta1().Gateways(ti.targetNamespace).Create(context.Background(), gatewayCfg, metav1.CreateOptions{})
require.NoError(t, err)
}

Expand Down
Loading
Loading