Skip to content

Commit 2866682

Browse files
ivankatliarchukmthemis-provenir
authored andcommitted
feat(source/istio): support version 1.25+ (kubernetes-sigs#5611)
* feat(source/istio): support version 1.22 Signed-off-by: ivan katliarchuk <[email protected]> * feat(source/istio): support version 1.22 Signed-off-by: ivan katliarchuk <[email protected]> * feat(source/istio): support version 1.22 Signed-off-by: ivan katliarchuk <[email protected]> * feat(source/istio): support version 1.22 Signed-off-by: ivan katliarchuk <[email protected]> * feat(source/istio): support version 1.22 Signed-off-by: ivan katliarchuk <[email protected]> * feat(source/istio): support version 1.22 Signed-off-by: ivan katliarchuk <[email protected]> * feat(source/istio): support version 1.22 Signed-off-by: ivan katliarchuk <[email protected]> * feat(source/istio): support version 1.25+ Co-authored-by: mthemis-provenir <[email protected]> --------- Signed-off-by: ivan katliarchuk <[email protected]> Co-authored-by: mthemis-provenir <[email protected]>
1 parent 68d735f commit 2866682

File tree

5 files changed

+124
-131
lines changed

5 files changed

+124
-131
lines changed

docs/sources/istio.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ It is meant to supplement the other provider-specific setup tutorials.
55

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

8-
* Manifest (for clusters without RBAC enabled)
9-
* Manifest (for clusters with RBAC enabled)
10-
* Update existing ExternalDNS Deployment
8+
**Note:** Currently supported versions are `1.25` and `1.26` with `v1beta1` stored version.
9+
10+
- [Support status of Istio releases](https://istio.io/latest/docs/releases/supported-releases/)
11+
12+
- Manifest (for clusters without RBAC enabled)
13+
- Manifest (for clusters with RBAC enabled)
14+
- Update existing ExternalDNS Deployment
1115

1216
## Manifest (for clusters without RBAC enabled)
1317

@@ -119,9 +123,9 @@ spec:
119123
120124
## Update existing ExternalDNS Deployment
121125
122-
* For clusters with running `external-dns`, you can just update the deployment.
123-
* With access to the `kube-system` namespace, update the existing `external-dns` deployment.
124-
* Add a parameter to the arguments of the container to create dns entries with `--source=istio-gateway`.
126+
- For clusters with running `external-dns`, you can just update the deployment.
127+
- With access to the `kube-system` namespace, update the existing `external-dns` deployment.
128+
- Add a parameter to the arguments of the container to create dns entries with `--source=istio-gateway`.
125129

126130
Execute the following command or update the argument.
127131

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

150154
```bash
151-
kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.6/samples/httpbin/httpbin.yaml
155+
kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.25/samples/httpbin/httpbin.yaml
152156
```
153157

154158
Otherwise:
155159

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

160164
### Using a Gateway as a source
@@ -320,13 +324,13 @@ EOF
320324

321325
## Debug ExternalDNS
322326

323-
* Look for the deployment pod to see the status
327+
- Look for the deployment pod to see the status
324328

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

329-
* Watch for the logs as follows
333+
- Watch for the logs as follows
330334

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

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

339-
* Successful executions will print the following
343+
- Successful executions will print the following
340344

341345
```console
342346
time="2020-01-17T06:08:08Z" level=info msg="Desired change: CREATE httpbin.example.com A"
@@ -345,7 +349,7 @@ time="2020-01-17T06:08:08Z" level=info msg="2 record(s) in zone example.com. wer
345349
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"
346350
```
347351

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

350354
```console
351355
source \"gateways\" in API group \"networking.istio.io\" at the cluster scope"

source/istio_gateway.go

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ import (
2424
"text/template"
2525

2626
log "github.com/sirupsen/logrus"
27-
networkingv1alpha3 "istio.io/client-go/pkg/apis/networking/v1alpha3"
27+
networkingv1beta1 "istio.io/client-go/pkg/apis/networking/v1beta1"
2828
istioclient "istio.io/client-go/pkg/clientset/versioned"
2929
istioinformers "istio.io/client-go/pkg/informers/externalversions"
30-
networkingv1alpha3informer "istio.io/client-go/pkg/informers/externalversions/networking/v1alpha3"
30+
networkingv1beta1informer "istio.io/client-go/pkg/informers/externalversions/networking/v1beta1"
3131
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3232
"k8s.io/apimachinery/pkg/labels"
3333
kubeinformers "k8s.io/client-go/informers"
@@ -57,7 +57,7 @@ type gatewaySource struct {
5757
combineFQDNAnnotation bool
5858
ignoreHostnameAnnotation bool
5959
serviceInformer coreinformers.ServiceInformer
60-
gatewayInformer networkingv1alpha3informer.GatewayInformer
60+
gatewayInformer networkingv1beta1informer.GatewayInformer
6161
}
6262

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

8686
// Add default resource event handlers to properly initialize informer.
87-
serviceInformer.Informer().AddEventHandler(
87+
_, _ = serviceInformer.Informer().AddEventHandler(
8888
cache.ResourceEventHandlerFuncs{
8989
AddFunc: func(obj interface{}) {
9090
log.Debug("service added")
9191
},
9292
},
9393
)
9494

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

141141
var endpoints []*endpoint.Endpoint
142142

143+
log.Debugf("Found %d gateways in namespace %s", len(gateways), sc.namespace)
144+
143145
for _, gateway := range gateways {
144146
// Check controller annotation to see if we are responsible.
145147
controller, ok := gateway.Annotations[controllerAnnotationKey]
146148
if ok && controller != controllerAnnotationValue {
147-
log.Debugf("Skipping gateway %s/%s because controller value does not match, found: %s, required: %s",
148-
gateway.Namespace, gateway.Name, controller, controllerAnnotationValue)
149+
log.Debugf("Skipping gateway %s/%s,%s because controller value does not match, found: %s, required: %s",
150+
gateway.Namespace, gateway.APIVersion, gateway.Name, controller, controllerAnnotationValue)
149151
continue
150152
}
151153

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

173+
log.Debugf("Processing gateway '%s/%s.%s' and hosts %q", gateway.Namespace, gateway.APIVersion, gateway.Name, strings.Join(gwHostnames, ","))
174+
171175
if len(gwHostnames) == 0 {
172176
log.Debugf("No hostnames could be generated from gateway %s/%s", gateway.Namespace, gateway.Name)
173177
continue
@@ -183,10 +187,11 @@ func (sc *gatewaySource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, e
183187
continue
184188
}
185189

186-
log.Debugf("Endpoints generated from gateway: %s/%s: %v", gateway.Namespace, gateway.Name, gwEndpoints)
190+
log.Debugf("Endpoints generated from %q '%s/%s.%s': %q", gateway.Kind, gateway.Namespace, gateway.APIVersion, gateway.Name, gwEndpoints)
187191
endpoints = append(endpoints, gwEndpoints...)
188192
}
189193

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

201-
sc.gatewayInformer.Informer().AddEventHandler(eventHandlerFunc(handler))
206+
_, _ = sc.gatewayInformer.Informer().AddEventHandler(eventHandlerFunc(handler))
202207
}
203208

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

216-
var filteredList []*networkingv1alpha3.Gateway
221+
var filteredList []*networkingv1beta1.Gateway
217222

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

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

254-
func (sc *gatewaySource) targetsFromGateway(ctx context.Context, gateway *networkingv1alpha3.Gateway) (endpoint.Targets, error) {
259+
func (sc *gatewaySource) targetsFromGateway(ctx context.Context, gateway *networkingv1beta1.Gateway) (endpoint.Targets, error) {
255260
targets := annotations.TargetsFromTargetAnnotation(gateway.Annotations)
256261
if len(targets) > 0 {
257262
return targets, nil
@@ -266,22 +271,21 @@ func (sc *gatewaySource) targetsFromGateway(ctx context.Context, gateway *networ
266271
}
267272

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

273-
resource := fmt.Sprintf("gateway/%s/%s", gateway.Namespace, gateway.Name)
274-
275-
ttl := annotations.TTLFromAnnotations(gateway.Annotations, resource)
278+
targets, err := sc.targetsFromGateway(ctx, gateway)
279+
if err != nil {
280+
return nil, err
281+
}
276282

277-
targets := annotations.TargetsFromTargetAnnotation(gateway.Annotations)
278283
if len(targets) == 0 {
279-
targets, err = sc.targetsFromGateway(ctx, gateway)
280-
if err != nil {
281-
return nil, err
282-
}
284+
return endpoints, nil
283285
}
284286

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

287291
for _, host := range hostnames {
@@ -291,7 +295,7 @@ func (sc *gatewaySource) endpointsFromGateway(ctx context.Context, hostnames []s
291295
return endpoints, nil
292296
}
293297

294-
func (sc *gatewaySource) hostNamesFromGateway(gateway *networkingv1alpha3.Gateway) ([]string, error) {
298+
func (sc *gatewaySource) hostNamesFromGateway(gateway *networkingv1beta1.Gateway) ([]string, error) {
295299
var hostnames []string
296300
for _, server := range gateway.Spec.Servers {
297301
for _, host := range server.Hosts {

source/istio_gateway_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import (
2424
"github.com/stretchr/testify/assert"
2525
"github.com/stretchr/testify/require"
2626
"github.com/stretchr/testify/suite"
27-
networkingv1alpha3api "istio.io/api/networking/v1alpha3"
28-
networkingv1alpha3 "istio.io/client-go/pkg/apis/networking/v1alpha3"
27+
networkingv1alpha3api "istio.io/api/networking/v1beta1"
28+
networkingv1alpha3 "istio.io/client-go/pkg/apis/networking/v1beta1"
2929
istiofake "istio.io/client-go/pkg/clientset/versioned/fake"
3030
v1 "k8s.io/api/core/v1"
3131
networkv1 "k8s.io/api/networking/v1"
@@ -1494,7 +1494,7 @@ func testGatewayEndpoints(t *testing.T) {
14941494
fakeIstioClient := istiofake.NewSimpleClientset()
14951495
for _, config := range ti.configItems {
14961496
gatewayCfg := config.Config()
1497-
_, err := fakeIstioClient.NetworkingV1alpha3().Gateways(ti.targetNamespace).Create(context.Background(), gatewayCfg, metav1.CreateOptions{})
1497+
_, err := fakeIstioClient.NetworkingV1beta1().Gateways(ti.targetNamespace).Create(context.Background(), gatewayCfg, metav1.CreateOptions{})
14981498
require.NoError(t, err)
14991499
}
15001500

0 commit comments

Comments
 (0)