/
istio_config.go
1177 lines (1068 loc) · 50.8 KB
/
istio_config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package business
import (
"context"
"encoding/json"
"fmt"
"strings"
"sync"
extentions_v1alpha1 "istio.io/client-go/pkg/apis/extensions/v1alpha1"
networking_v1alpha3 "istio.io/client-go/pkg/apis/networking/v1alpha3"
networking_v1beta1 "istio.io/client-go/pkg/apis/networking/v1beta1"
security_v1beta1 "istio.io/client-go/pkg/apis/security/v1beta1"
"istio.io/client-go/pkg/apis/telemetry/v1alpha1"
api_errors "k8s.io/apimachinery/pkg/api/errors"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
api_types "k8s.io/apimachinery/pkg/types"
k8s_networking_v1 "sigs.k8s.io/gateway-api/apis/v1"
k8s_networking_v1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
k8s_networking_v1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
"github.com/kiali/kiali/config"
"github.com/kiali/kiali/kubernetes"
"github.com/kiali/kiali/kubernetes/cache"
"github.com/kiali/kiali/log"
"github.com/kiali/kiali/models"
"github.com/kiali/kiali/observability"
)
const allResources string = "*"
type IstioConfigService struct {
userClients map[string]kubernetes.ClientInterface
config config.Config
kialiCache cache.KialiCache
businessLayer *Layer
controlPlaneMonitor ControlPlaneMonitor
}
type IstioConfigCriteria struct {
IncludeGateways bool
IncludeK8sGateways bool
IncludeK8sGRPCRoutes bool
IncludeK8sHTTPRoutes bool
IncludeK8sReferenceGrants bool
IncludeK8sTCPRoutes bool
IncludeK8sTLSRoutes bool
IncludeVirtualServices bool
IncludeDestinationRules bool
IncludeServiceEntries bool
IncludeSidecars bool
IncludeAuthorizationPolicies bool
IncludePeerAuthentications bool
IncludeWorkloadEntries bool
IncludeWorkloadGroups bool
IncludeRequestAuthentications bool
IncludeEnvoyFilters bool
IncludeWasmPlugins bool
IncludeTelemetry bool
LabelSelector string
WorkloadSelector string
}
func (icc IstioConfigCriteria) Include(resource string) bool {
// Flag used to skip object that are not used in a query when a WorkloadSelector is present
isWorkloadSelector := icc.WorkloadSelector != ""
switch resource {
case kubernetes.Gateways:
return icc.IncludeGateways
case kubernetes.K8sGateways:
return icc.IncludeK8sGateways
case kubernetes.K8sGRPCRoutes:
return icc.IncludeK8sGRPCRoutes
case kubernetes.K8sHTTPRoutes:
return icc.IncludeK8sHTTPRoutes
case kubernetes.K8sReferenceGrants:
return icc.IncludeK8sReferenceGrants
case kubernetes.K8sTCPRoutes:
return icc.IncludeK8sTCPRoutes
case kubernetes.K8sTLSRoutes:
return icc.IncludeK8sTLSRoutes
case kubernetes.VirtualServices:
return icc.IncludeVirtualServices && !isWorkloadSelector
case kubernetes.DestinationRules:
return icc.IncludeDestinationRules && !isWorkloadSelector
case kubernetes.ServiceEntries:
return icc.IncludeServiceEntries && !isWorkloadSelector
case kubernetes.Sidecars:
return icc.IncludeSidecars
case kubernetes.AuthorizationPolicies:
return icc.IncludeAuthorizationPolicies
case kubernetes.PeerAuthentications:
return icc.IncludePeerAuthentications
case kubernetes.WorkloadEntries:
return icc.IncludeWorkloadEntries && !isWorkloadSelector
case kubernetes.WorkloadGroups:
return icc.IncludeWorkloadGroups && !isWorkloadSelector
case kubernetes.RequestAuthentications:
return icc.IncludeRequestAuthentications
case kubernetes.EnvoyFilters:
return icc.IncludeEnvoyFilters
case kubernetes.WasmPlugins:
return icc.IncludeWasmPlugins
case kubernetes.Telemetries:
return icc.IncludeTelemetry
}
return false
}
// IstioConfig types used in the IstioConfig New Page Form
// networking.istio.io
var newNetworkingConfigTypes = []string{
kubernetes.Sidecars,
kubernetes.Gateways,
kubernetes.ServiceEntries,
}
// gateway.networking.k8s.io
var newK8sNetworkingConfigTypes = []string{
kubernetes.K8sGateways,
kubernetes.K8sReferenceGrants,
}
// security.istio.io
var newSecurityConfigTypes = []string{
kubernetes.AuthorizationPolicies,
kubernetes.PeerAuthentications,
kubernetes.RequestAuthentications,
}
// GetIstioConfigMap returns a map of Istio config objects list per cluster
// @TODO this method should replace GetIstioConfigList
func (in *IstioConfigService) GetIstioConfigMap(ctx context.Context, namespace string, criteria IstioConfigCriteria) (models.IstioConfigMap, error) {
istioConfigMap := models.IstioConfigMap{}
for cluster := range in.userClients {
var (
singleClusterConfigList *models.IstioConfigList
err error
)
if namespace == meta_v1.NamespaceAll {
singleClusterConfigList, err = in.GetIstioConfigList(ctx, cluster, criteria)
if err != nil {
return nil, err
}
} else {
singleClusterConfigList, err = in.GetIstioConfigListForNamespace(ctx, cluster, namespace, criteria)
if err != nil {
return nil, err
}
}
istioConfigMap[cluster] = *singleClusterConfigList
}
return istioConfigMap, nil
}
func (in *IstioConfigService) GetIstioConfigListForNamespace(ctx context.Context, cluster, namespace string, criteria IstioConfigCriteria) (*models.IstioConfigList, error) {
// Check if user has access to the namespace (RBAC) in cache scenarios and/or
// if namespace is accessible from Kiali (Deployment.AccessibleNamespaces)
if _, err := in.businessLayer.Namespace.GetClusterNamespace(ctx, namespace, cluster); err != nil {
// Check if the namespace exists on the cluster in multi-cluster mode.
// TODO: Remove this once other business methods stop looping over all clusters.
if (api_errors.IsNotFound(err) || api_errors.IsForbidden(err)) && len(in.userClients) > 1 {
return &models.IstioConfigList{}, nil
}
return nil, err
}
istioConfigs, err := in.getIstioConfigList(ctx, cluster, namespace, criteria)
if err != nil {
return nil, err
}
return istioConfigs, nil
}
func (in *IstioConfigService) getIstioConfigList(ctx context.Context, cluster string, namespace string, criteria IstioConfigCriteria) (*models.IstioConfigList, error) {
var end observability.EndFunc
_, end = observability.StartSpan(ctx, "GetIstioConfigListForNamespace",
observability.Attribute("package", "business"),
)
defer end()
istioConfigList := &models.IstioConfigList{
DestinationRules: []*networking_v1beta1.DestinationRule{},
EnvoyFilters: []*networking_v1alpha3.EnvoyFilter{},
Gateways: []*networking_v1beta1.Gateway{},
VirtualServices: []*networking_v1beta1.VirtualService{},
ServiceEntries: []*networking_v1beta1.ServiceEntry{},
Sidecars: []*networking_v1beta1.Sidecar{},
WorkloadEntries: []*networking_v1beta1.WorkloadEntry{},
WorkloadGroups: []*networking_v1beta1.WorkloadGroup{},
WasmPlugins: []*extentions_v1alpha1.WasmPlugin{},
Telemetries: []*v1alpha1.Telemetry{},
K8sGateways: []*k8s_networking_v1.Gateway{},
K8sGRPCRoutes: []*k8s_networking_v1alpha2.GRPCRoute{},
K8sHTTPRoutes: []*k8s_networking_v1.HTTPRoute{},
K8sReferenceGrants: []*k8s_networking_v1beta1.ReferenceGrant{},
K8sTCPRoutes: []*k8s_networking_v1alpha2.TCPRoute{},
K8sTLSRoutes: []*k8s_networking_v1alpha2.TLSRoute{},
AuthorizationPolicies: []*security_v1beta1.AuthorizationPolicy{},
PeerAuthentications: []*security_v1beta1.PeerAuthentication{},
RequestAuthentications: []*security_v1beta1.RequestAuthentication{},
}
kubeCache, err := in.kialiCache.GetKubeCache(cluster)
if err != nil {
return nil, fmt.Errorf("K8s Cache [%s] is not found or is not accessible for Kiali", cluster)
}
userClient := in.userClients[cluster]
if userClient == nil {
return nil, fmt.Errorf("K8s Client [%s] is not found or is not accessible for Kiali", cluster)
}
if !kubeCache.Client().IsIstioAPI() {
log.Infof("Cluster [%s] does not have Istio API installed", cluster)
// Return empty object here since there are no istio config objects in the cluster
// and returning nil would cause nil pointer dereference in the caller.
return istioConfigList, nil
}
isWorkloadSelector := criteria.WorkloadSelector != ""
workloadSelector := ""
if isWorkloadSelector {
workloadSelector = criteria.WorkloadSelector
}
if criteria.Include(kubernetes.DestinationRules) {
istioConfigList.DestinationRules, err = kubeCache.GetDestinationRules(namespace, criteria.LabelSelector)
if err != nil {
return nil, err
}
}
if criteria.Include(kubernetes.EnvoyFilters) {
istioConfigList.EnvoyFilters, err = kubeCache.GetEnvoyFilters(namespace, criteria.LabelSelector)
if err != nil {
return nil, err
}
if isWorkloadSelector {
istioConfigList.EnvoyFilters = kubernetes.FilterEnvoyFiltersBySelector(workloadSelector, istioConfigList.EnvoyFilters)
}
}
if criteria.Include(kubernetes.Gateways) {
istioConfigList.Gateways, err = kubeCache.GetGateways(namespace, criteria.LabelSelector)
if err != nil {
return nil, err
}
if isWorkloadSelector {
istioConfigList.Gateways = kubernetes.FilterGatewaysBySelector(workloadSelector, istioConfigList.Gateways)
}
}
if userClient.IsGatewayAPI() && criteria.Include(kubernetes.K8sGateways) {
istioConfigList.K8sGateways, err = kubeCache.GetK8sGateways(namespace, criteria.LabelSelector)
if err != nil {
return nil, err
}
}
if userClient.IsExpGatewayAPI() && criteria.Include(kubernetes.K8sGRPCRoutes) {
istioConfigList.K8sGRPCRoutes, err = kubeCache.GetK8sGRPCRoutes(namespace, criteria.LabelSelector)
if err != nil {
return nil, err
}
}
if userClient.IsGatewayAPI() && criteria.Include(kubernetes.K8sHTTPRoutes) {
istioConfigList.K8sHTTPRoutes, err = kubeCache.GetK8sHTTPRoutes(namespace, criteria.LabelSelector)
if err != nil {
return nil, err
}
}
if userClient.IsGatewayAPI() && criteria.Include(kubernetes.K8sReferenceGrants) {
istioConfigList.K8sReferenceGrants, err = kubeCache.GetK8sReferenceGrants(namespace, criteria.LabelSelector)
if err != nil {
return nil, err
}
}
if userClient.IsExpGatewayAPI() && criteria.Include(kubernetes.K8sTCPRoutes) {
istioConfigList.K8sTCPRoutes, err = kubeCache.GetK8sTCPRoutes(namespace, criteria.LabelSelector)
if err != nil {
return nil, err
}
}
if userClient.IsExpGatewayAPI() && criteria.Include(kubernetes.K8sTLSRoutes) {
istioConfigList.K8sTLSRoutes, err = kubeCache.GetK8sTLSRoutes(namespace, criteria.LabelSelector)
if err != nil {
return nil, err
}
}
if criteria.Include(kubernetes.ServiceEntries) {
istioConfigList.ServiceEntries, err = kubeCache.GetServiceEntries(namespace, criteria.LabelSelector)
if err != nil {
return nil, err
}
}
if criteria.Include(kubernetes.Sidecars) {
var err error
istioConfigList.Sidecars, err = kubeCache.GetSidecars(namespace, criteria.LabelSelector)
if err != nil {
return nil, err
}
if isWorkloadSelector {
istioConfigList.Sidecars = kubernetes.FilterSidecarsBySelector(workloadSelector, istioConfigList.Sidecars)
}
}
if criteria.Include(kubernetes.VirtualServices) {
istioConfigList.VirtualServices, err = kubeCache.GetVirtualServices(namespace, criteria.LabelSelector)
if err != nil {
return nil, err
}
}
if criteria.Include(kubernetes.WorkloadEntries) {
istioConfigList.WorkloadEntries, err = kubeCache.GetWorkloadEntries(namespace, criteria.LabelSelector)
if err != nil {
return nil, err
}
}
if criteria.Include(kubernetes.WorkloadGroups) {
istioConfigList.WorkloadGroups, err = kubeCache.GetWorkloadGroups(namespace, criteria.LabelSelector)
if err != nil {
return nil, err
}
}
if criteria.Include(kubernetes.WasmPlugins) {
istioConfigList.WasmPlugins, err = kubeCache.GetWasmPlugins(namespace, criteria.LabelSelector)
if err != nil {
return nil, err
}
}
if criteria.Include(kubernetes.Telemetries) {
istioConfigList.Telemetries, err = kubeCache.GetTelemetries(namespace, criteria.LabelSelector)
if err != nil {
return nil, err
}
}
if criteria.Include(kubernetes.AuthorizationPolicies) {
istioConfigList.AuthorizationPolicies, err = kubeCache.GetAuthorizationPolicies(namespace, criteria.LabelSelector)
if err != nil {
return nil, err
}
if isWorkloadSelector {
istioConfigList.AuthorizationPolicies = kubernetes.FilterAuthorizationPoliciesBySelector(workloadSelector, istioConfigList.AuthorizationPolicies)
}
}
if criteria.Include(kubernetes.PeerAuthentications) {
istioConfigList.PeerAuthentications, err = kubeCache.GetPeerAuthentications(namespace, criteria.LabelSelector)
if err != nil {
return nil, err
}
if isWorkloadSelector {
istioConfigList.PeerAuthentications = kubernetes.FilterPeerAuthenticationsBySelector(workloadSelector, istioConfigList.PeerAuthentications)
}
}
if criteria.Include(kubernetes.RequestAuthentications) {
istioConfigList.RequestAuthentications, err = kubeCache.GetRequestAuthentications(namespace, criteria.LabelSelector)
if err != nil {
return nil, err
}
if isWorkloadSelector {
istioConfigList.RequestAuthentications = kubernetes.FilterRequestAuthenticationsBySelector(workloadSelector, istioConfigList.RequestAuthentications)
}
}
return istioConfigList, nil
}
func (in *IstioConfigService) GetIstioConfigList(ctx context.Context, cluster string, criteria IstioConfigCriteria) (*models.IstioConfigList, error) {
var end observability.EndFunc
ctx, end = observability.StartSpan(ctx, "GetIstioConfigList",
observability.Attribute("package", "business"),
)
defer end()
istioConfigs, err := in.getIstioConfigList(ctx, cluster, meta_v1.NamespaceAll, criteria)
if err != nil {
return nil, err
}
// Filter out namespaces that the user doesn't have access to.
namespaces, err := in.businessLayer.Namespace.GetClusterNamespaces(ctx, cluster)
if err != nil {
return nil, err
}
namespaceNames := make([]string, 0, len(namespaces))
for _, namespace := range namespaces {
namespaceNames = append(namespaceNames, namespace.Name)
}
return &models.IstioConfigList{
AuthorizationPolicies: kubernetes.FilterByNamespaces(istioConfigs.AuthorizationPolicies, namespaceNames),
DestinationRules: kubernetes.FilterByNamespaces(istioConfigs.DestinationRules, namespaceNames),
EnvoyFilters: kubernetes.FilterByNamespaces(istioConfigs.EnvoyFilters, namespaceNames),
Gateways: kubernetes.FilterByNamespaces(istioConfigs.Gateways, namespaceNames),
K8sGateways: kubernetes.FilterByNamespaces(istioConfigs.K8sGateways, namespaceNames),
K8sGRPCRoutes: kubernetes.FilterByNamespaces(istioConfigs.K8sGRPCRoutes, namespaceNames),
K8sHTTPRoutes: kubernetes.FilterByNamespaces(istioConfigs.K8sHTTPRoutes, namespaceNames),
K8sReferenceGrants: kubernetes.FilterByNamespaces(istioConfigs.K8sReferenceGrants, namespaceNames),
K8sTCPRoutes: kubernetes.FilterByNamespaces(istioConfigs.K8sTCPRoutes, namespaceNames),
K8sTLSRoutes: kubernetes.FilterByNamespaces(istioConfigs.K8sTLSRoutes, namespaceNames),
PeerAuthentications: kubernetes.FilterByNamespaces(istioConfigs.PeerAuthentications, namespaceNames),
RequestAuthentications: kubernetes.FilterByNamespaces(istioConfigs.RequestAuthentications, namespaceNames),
ServiceEntries: kubernetes.FilterByNamespaces(istioConfigs.ServiceEntries, namespaceNames),
Sidecars: kubernetes.FilterByNamespaces(istioConfigs.Sidecars, namespaceNames),
Telemetries: kubernetes.FilterByNamespaces(istioConfigs.Telemetries, namespaceNames),
VirtualServices: kubernetes.FilterByNamespaces(istioConfigs.VirtualServices, namespaceNames),
WasmPlugins: kubernetes.FilterByNamespaces(istioConfigs.WasmPlugins, namespaceNames),
WorkloadEntries: kubernetes.FilterByNamespaces(istioConfigs.WorkloadEntries, namespaceNames),
WorkloadGroups: kubernetes.FilterByNamespaces(istioConfigs.WorkloadGroups, namespaceNames),
}, nil
}
// GetIstioConfigDetails returns a specific Istio configuration object.
// It uses following parameters:
// - "namespace": namespace where configuration is stored
// - "objectType": type of the configuration
// - "object": name of the configuration
func (in *IstioConfigService) GetIstioConfigDetails(ctx context.Context, cluster, namespace, objectType, object string) (models.IstioConfigDetails, error) {
var end observability.EndFunc
ctx, end = observability.StartSpan(ctx, "GetIstioConfigDetails",
observability.Attribute("package", "business"),
observability.Attribute("cluster", cluster),
observability.Attribute("namespace", namespace),
observability.Attribute("objectType", objectType),
observability.Attribute("object", object),
)
defer end()
var err error
istioConfigDetail := models.IstioConfigDetails{}
istioConfigDetail.Namespace = models.Namespace{Name: namespace}
istioConfigDetail.ObjectType = objectType
if _, ok := in.userClients[cluster]; !ok {
return istioConfigDetail, fmt.Errorf("Cluster [%s] is not found or is not accessible for Kiali", cluster)
}
// Check if user has access to the namespace (RBAC) in cache scenarios and/or
// if namespace is accessible from Kiali (Deployment.AccessibleNamespaces)
if _, err := in.businessLayer.Namespace.GetClusterNamespace(ctx, namespace, cluster); err != nil {
return istioConfigDetail, err
}
var wg sync.WaitGroup
wg.Add(1)
go func(ctx context.Context) {
defer wg.Done()
canCreate, canUpdate, canDelete := getPermissions(ctx, in.userClients[cluster], cluster, namespace, objectType)
istioConfigDetail.Permissions = models.ResourcePermissions{
Create: canCreate,
Update: canUpdate,
Delete: canDelete,
}
}(ctx)
getOpts := meta_v1.GetOptions{}
switch objectType {
case kubernetes.DestinationRules:
istioConfigDetail.DestinationRule, err = in.userClients[cluster].Istio().NetworkingV1beta1().DestinationRules(namespace).Get(ctx, object, getOpts)
if err == nil {
istioConfigDetail.DestinationRule.Kind = kubernetes.DestinationRuleType
istioConfigDetail.DestinationRule.APIVersion = kubernetes.ApiNetworkingVersionV1Beta1
}
case kubernetes.EnvoyFilters:
istioConfigDetail.EnvoyFilter, err = in.userClients[cluster].Istio().NetworkingV1alpha3().EnvoyFilters(namespace).Get(ctx, object, getOpts)
if err == nil {
istioConfigDetail.EnvoyFilter.Kind = kubernetes.EnvoyFilterType
istioConfigDetail.EnvoyFilter.APIVersion = kubernetes.ApiNetworkingVersionV1Alpha3
}
case kubernetes.Gateways:
istioConfigDetail.Gateway, err = in.userClients[cluster].Istio().NetworkingV1beta1().Gateways(namespace).Get(ctx, object, getOpts)
if err == nil {
istioConfigDetail.Gateway.Kind = kubernetes.GatewayType
istioConfigDetail.Gateway.APIVersion = kubernetes.ApiNetworkingVersionV1Beta1
}
case kubernetes.K8sGateways:
istioConfigDetail.K8sGateway, err = in.userClients[cluster].GatewayAPI().GatewayV1().Gateways(namespace).Get(ctx, object, getOpts)
if err == nil {
istioConfigDetail.K8sGateway.Kind = kubernetes.K8sActualGatewayType
istioConfigDetail.K8sGateway.APIVersion = kubernetes.K8sApiNetworkingVersionV1
}
case kubernetes.K8sGRPCRoutes:
istioConfigDetail.K8sGRPCRoute, err = in.userClients[cluster].GatewayAPI().GatewayV1alpha2().GRPCRoutes(namespace).Get(ctx, object, getOpts)
if err == nil {
istioConfigDetail.K8sGRPCRoute.Kind = kubernetes.K8sActualGRPCRouteType
istioConfigDetail.K8sGRPCRoute.APIVersion = kubernetes.K8sApiNetworkingVersionV1Alpha2
}
case kubernetes.K8sHTTPRoutes:
istioConfigDetail.K8sHTTPRoute, err = in.userClients[cluster].GatewayAPI().GatewayV1().HTTPRoutes(namespace).Get(ctx, object, getOpts)
if err == nil {
istioConfigDetail.K8sHTTPRoute.Kind = kubernetes.K8sActualHTTPRouteType
istioConfigDetail.K8sHTTPRoute.APIVersion = kubernetes.K8sApiNetworkingVersionV1
}
case kubernetes.K8sReferenceGrants:
istioConfigDetail.K8sReferenceGrant, err = in.userClients[cluster].GatewayAPI().GatewayV1beta1().ReferenceGrants(namespace).Get(ctx, object, getOpts)
if err == nil {
istioConfigDetail.K8sReferenceGrant.Kind = kubernetes.K8sActualReferenceGrantType
istioConfigDetail.K8sReferenceGrant.APIVersion = kubernetes.K8sApiNetworkingVersionV1Beta1
}
case kubernetes.K8sTCPRoutes:
istioConfigDetail.K8sTCPRoute, err = in.userClients[cluster].GatewayAPI().GatewayV1alpha2().TCPRoutes(namespace).Get(ctx, object, getOpts)
if err == nil {
istioConfigDetail.K8sTCPRoute.Kind = kubernetes.K8sActualTCPRouteType
istioConfigDetail.K8sTCPRoute.APIVersion = kubernetes.K8sApiNetworkingVersionV1Alpha2
}
case kubernetes.K8sTLSRoutes:
istioConfigDetail.K8sTLSRoute, err = in.userClients[cluster].GatewayAPI().GatewayV1alpha2().TLSRoutes(namespace).Get(ctx, object, getOpts)
if err == nil {
istioConfigDetail.K8sTLSRoute.Kind = kubernetes.K8sActualTLSRouteType
istioConfigDetail.K8sTLSRoute.APIVersion = kubernetes.K8sApiNetworkingVersionV1Alpha2
}
case kubernetes.ServiceEntries:
istioConfigDetail.ServiceEntry, err = in.userClients[cluster].Istio().NetworkingV1beta1().ServiceEntries(namespace).Get(ctx, object, getOpts)
if err == nil {
istioConfigDetail.ServiceEntry.Kind = kubernetes.ServiceEntryType
istioConfigDetail.ServiceEntry.APIVersion = kubernetes.ApiNetworkingVersionV1Beta1
}
case kubernetes.Sidecars:
istioConfigDetail.Sidecar, err = in.userClients[cluster].Istio().NetworkingV1beta1().Sidecars(namespace).Get(ctx, object, getOpts)
if err == nil {
istioConfigDetail.Sidecar.Kind = kubernetes.SidecarType
istioConfigDetail.Sidecar.APIVersion = kubernetes.ApiNetworkingVersionV1Beta1
}
case kubernetes.VirtualServices:
istioConfigDetail.VirtualService, err = in.userClients[cluster].Istio().NetworkingV1beta1().VirtualServices(namespace).Get(ctx, object, getOpts)
if err == nil {
istioConfigDetail.VirtualService.Kind = kubernetes.VirtualServiceType
istioConfigDetail.VirtualService.APIVersion = kubernetes.ApiNetworkingVersionV1Beta1
}
case kubernetes.WorkloadEntries:
istioConfigDetail.WorkloadEntry, err = in.userClients[cluster].Istio().NetworkingV1beta1().WorkloadEntries(namespace).Get(ctx, object, getOpts)
if err == nil {
istioConfigDetail.WorkloadEntry.Kind = kubernetes.WorkloadEntryType
istioConfigDetail.WorkloadEntry.APIVersion = kubernetes.ApiNetworkingVersionV1Beta1
}
case kubernetes.WorkloadGroups:
istioConfigDetail.WorkloadGroup, err = in.userClients[cluster].Istio().NetworkingV1beta1().WorkloadGroups(namespace).Get(ctx, object, getOpts)
if err == nil {
istioConfigDetail.WorkloadGroup.Kind = kubernetes.WorkloadGroupType
istioConfigDetail.WorkloadGroup.APIVersion = kubernetes.ApiNetworkingVersionV1Beta1
}
case kubernetes.WasmPlugins:
istioConfigDetail.WasmPlugin, err = in.userClients[cluster].Istio().ExtensionsV1alpha1().WasmPlugins(namespace).Get(ctx, object, getOpts)
if err == nil {
istioConfigDetail.WasmPlugin.Kind = kubernetes.WasmPluginType
istioConfigDetail.WasmPlugin.APIVersion = kubernetes.ApiExtensionV1Alpha1
}
case kubernetes.Telemetries:
istioConfigDetail.Telemetry, err = in.userClients[cluster].Istio().TelemetryV1alpha1().Telemetries(namespace).Get(ctx, object, getOpts)
if err == nil {
istioConfigDetail.Telemetry.Kind = kubernetes.TelemetryType
istioConfigDetail.Telemetry.APIVersion = kubernetes.ApiTelemetryV1Alpha1
}
case kubernetes.AuthorizationPolicies:
istioConfigDetail.AuthorizationPolicy, err = in.userClients[cluster].Istio().SecurityV1beta1().AuthorizationPolicies(namespace).Get(ctx, object, getOpts)
if err == nil {
istioConfigDetail.AuthorizationPolicy.Kind = kubernetes.AuthorizationPoliciesType
istioConfigDetail.AuthorizationPolicy.APIVersion = kubernetes.ApiSecurityVersion
}
case kubernetes.PeerAuthentications:
istioConfigDetail.PeerAuthentication, err = in.userClients[cluster].Istio().SecurityV1beta1().PeerAuthentications(namespace).Get(ctx, object, getOpts)
if err == nil {
istioConfigDetail.PeerAuthentication.Kind = kubernetes.PeerAuthenticationsType
istioConfigDetail.PeerAuthentication.APIVersion = kubernetes.ApiSecurityVersion
}
case kubernetes.RequestAuthentications:
istioConfigDetail.RequestAuthentication, err = in.userClients[cluster].Istio().SecurityV1beta1().RequestAuthentications(namespace).Get(ctx, object, getOpts)
if err == nil {
istioConfigDetail.RequestAuthentication.Kind = kubernetes.RequestAuthenticationsType
istioConfigDetail.RequestAuthentication.APIVersion = kubernetes.ApiSecurityVersion
}
default:
err = fmt.Errorf("object type not found: %v", objectType)
}
wg.Wait()
return istioConfigDetail, err
}
// GetIstioAPI provides the Kubernetes API that manages this Istio resource type
// or empty string if it's not managed
func GetIstioAPI(resourceType string) bool {
return kubernetes.ResourceTypesToAPI[resourceType] != ""
}
// DeleteIstioConfigDetail deletes the given Istio resource
func (in *IstioConfigService) DeleteIstioConfigDetail(ctx context.Context, cluster, namespace, resourceType, name string) error {
var err error
delOpts := meta_v1.DeleteOptions{}
userClient := in.userClients[cluster]
if userClient == nil {
return fmt.Errorf("K8s Client [%s] is not found or is not accessible for Kiali", cluster)
}
kubeCache, err := in.kialiCache.GetKubeCache(cluster)
if err != nil {
return err
}
switch resourceType {
case kubernetes.DestinationRules:
err = userClient.Istio().NetworkingV1beta1().DestinationRules(namespace).Delete(ctx, name, delOpts)
case kubernetes.EnvoyFilters:
err = userClient.Istio().NetworkingV1alpha3().EnvoyFilters(namespace).Delete(ctx, name, delOpts)
case kubernetes.Gateways:
err = userClient.Istio().NetworkingV1beta1().Gateways(namespace).Delete(ctx, name, delOpts)
case kubernetes.K8sGateways:
err = userClient.GatewayAPI().GatewayV1().Gateways(namespace).Delete(ctx, name, delOpts)
case kubernetes.K8sGRPCRoutes:
err = userClient.GatewayAPI().GatewayV1alpha2().GRPCRoutes(namespace).Delete(ctx, name, delOpts)
case kubernetes.K8sHTTPRoutes:
err = userClient.GatewayAPI().GatewayV1().HTTPRoutes(namespace).Delete(ctx, name, delOpts)
case kubernetes.K8sReferenceGrants:
err = userClient.GatewayAPI().GatewayV1beta1().ReferenceGrants(namespace).Delete(ctx, name, delOpts)
case kubernetes.K8sTCPRoutes:
err = userClient.GatewayAPI().GatewayV1alpha2().TCPRoutes(namespace).Delete(ctx, name, delOpts)
case kubernetes.K8sTLSRoutes:
err = userClient.GatewayAPI().GatewayV1alpha2().TLSRoutes(namespace).Delete(ctx, name, delOpts)
case kubernetes.ServiceEntries:
err = userClient.Istio().NetworkingV1beta1().ServiceEntries(namespace).Delete(ctx, name, delOpts)
case kubernetes.Sidecars:
err = userClient.Istio().NetworkingV1beta1().Sidecars(namespace).Delete(ctx, name, delOpts)
case kubernetes.VirtualServices:
err = userClient.Istio().NetworkingV1beta1().VirtualServices(namespace).Delete(ctx, name, delOpts)
case kubernetes.WorkloadEntries:
err = userClient.Istio().NetworkingV1beta1().WorkloadEntries(namespace).Delete(ctx, name, delOpts)
case kubernetes.WorkloadGroups:
err = userClient.Istio().NetworkingV1beta1().WorkloadGroups(namespace).Delete(ctx, name, delOpts)
case kubernetes.AuthorizationPolicies:
err = userClient.Istio().SecurityV1beta1().AuthorizationPolicies(namespace).Delete(ctx, name, delOpts)
case kubernetes.PeerAuthentications:
err = userClient.Istio().SecurityV1beta1().PeerAuthentications(namespace).Delete(ctx, name, delOpts)
case kubernetes.RequestAuthentications:
err = userClient.Istio().SecurityV1beta1().RequestAuthentications(namespace).Delete(ctx, name, delOpts)
case kubernetes.WasmPlugins:
err = userClient.Istio().ExtensionsV1alpha1().WasmPlugins(namespace).Delete(ctx, name, delOpts)
case kubernetes.Telemetries:
err = userClient.Istio().TelemetryV1alpha1().Telemetries(namespace).Delete(ctx, name, delOpts)
default:
err = fmt.Errorf("object type not found: %v", resourceType)
}
if err != nil {
return err
}
if in.config.ExternalServices.Istio.IstioAPIEnabled {
// Refreshing the istio cache in case something has changed with the registry services. Not sure if this is really needed.
if err := in.controlPlaneMonitor.RefreshIstioCache(ctx); err != nil {
log.Errorf("Error while refreshing Istio cache: %s", err)
}
}
// We need to refresh the kube cache though at least until waiting for the object to be updated is implemented.
kubeCache.Refresh(namespace)
return nil
}
func (in *IstioConfigService) UpdateIstioConfigDetail(ctx context.Context, cluster, namespace, resourceType, name, jsonPatch string) (models.IstioConfigDetails, error) {
istioConfigDetail := models.IstioConfigDetails{}
istioConfigDetail.Namespace = models.Namespace{Name: namespace}
istioConfigDetail.ObjectType = resourceType
patchOpts := meta_v1.PatchOptions{}
patchType := api_types.MergePatchType
bytePatch := []byte(jsonPatch)
userClient := in.userClients[cluster]
if userClient == nil {
return istioConfigDetail, fmt.Errorf("K8s Client [%s] is not found or is not accessible for Kiali", cluster)
}
kubeCache, err := in.kialiCache.GetKubeCache(cluster)
if err != nil {
return istioConfigDetail, nil
}
switch resourceType {
case kubernetes.DestinationRules:
istioConfigDetail.DestinationRule = &networking_v1beta1.DestinationRule{}
istioConfigDetail.DestinationRule, err = userClient.Istio().NetworkingV1beta1().DestinationRules(namespace).Patch(ctx, name, patchType, bytePatch, patchOpts)
case kubernetes.EnvoyFilters:
istioConfigDetail.EnvoyFilter = &networking_v1alpha3.EnvoyFilter{}
istioConfigDetail.EnvoyFilter, err = userClient.Istio().NetworkingV1alpha3().EnvoyFilters(namespace).Patch(ctx, name, patchType, bytePatch, patchOpts)
case kubernetes.Gateways:
istioConfigDetail.Gateway = &networking_v1beta1.Gateway{}
istioConfigDetail.Gateway, err = userClient.Istio().NetworkingV1beta1().Gateways(namespace).Patch(ctx, name, patchType, bytePatch, patchOpts)
case kubernetes.K8sGateways:
istioConfigDetail.K8sGateway = &k8s_networking_v1.Gateway{}
istioConfigDetail.K8sGateway, err = userClient.GatewayAPI().GatewayV1().Gateways(namespace).Patch(ctx, name, patchType, bytePatch, patchOpts)
case kubernetes.K8sGRPCRoutes:
istioConfigDetail.K8sGRPCRoute = &k8s_networking_v1alpha2.GRPCRoute{}
istioConfigDetail.K8sGRPCRoute, err = userClient.GatewayAPI().GatewayV1alpha2().GRPCRoutes(namespace).Patch(ctx, name, patchType, bytePatch, patchOpts)
case kubernetes.K8sHTTPRoutes:
istioConfigDetail.K8sHTTPRoute = &k8s_networking_v1.HTTPRoute{}
istioConfigDetail.K8sHTTPRoute, err = userClient.GatewayAPI().GatewayV1().HTTPRoutes(namespace).Patch(ctx, name, patchType, bytePatch, patchOpts)
case kubernetes.K8sReferenceGrants:
istioConfigDetail.K8sReferenceGrant = &k8s_networking_v1beta1.ReferenceGrant{}
fixedPatch := strings.Replace(jsonPatch, "\"group\":null", "\"group\":\"\"", -1)
istioConfigDetail.K8sReferenceGrant, err = userClient.GatewayAPI().GatewayV1beta1().ReferenceGrants(namespace).Patch(ctx, name, patchType, []byte(fixedPatch), patchOpts)
case kubernetes.K8sTCPRoutes:
istioConfigDetail.K8sTCPRoute = &k8s_networking_v1alpha2.TCPRoute{}
istioConfigDetail.K8sTCPRoute, err = userClient.GatewayAPI().GatewayV1alpha2().TCPRoutes(namespace).Patch(ctx, name, patchType, bytePatch, patchOpts)
case kubernetes.K8sTLSRoutes:
istioConfigDetail.K8sTLSRoute = &k8s_networking_v1alpha2.TLSRoute{}
istioConfigDetail.K8sTLSRoute, err = userClient.GatewayAPI().GatewayV1alpha2().TLSRoutes(namespace).Patch(ctx, name, patchType, bytePatch, patchOpts)
case kubernetes.ServiceEntries:
istioConfigDetail.ServiceEntry = &networking_v1beta1.ServiceEntry{}
istioConfigDetail.ServiceEntry, err = userClient.Istio().NetworkingV1beta1().ServiceEntries(namespace).Patch(ctx, name, patchType, bytePatch, patchOpts)
case kubernetes.Sidecars:
istioConfigDetail.Sidecar = &networking_v1beta1.Sidecar{}
istioConfigDetail.Sidecar, err = userClient.Istio().NetworkingV1beta1().Sidecars(namespace).Patch(ctx, name, patchType, bytePatch, patchOpts)
case kubernetes.VirtualServices:
istioConfigDetail.VirtualService = &networking_v1beta1.VirtualService{}
istioConfigDetail.VirtualService, err = userClient.Istio().NetworkingV1beta1().VirtualServices(namespace).Patch(ctx, name, patchType, bytePatch, patchOpts)
case kubernetes.WorkloadEntries:
istioConfigDetail.WorkloadEntry = &networking_v1beta1.WorkloadEntry{}
istioConfigDetail.WorkloadEntry, err = userClient.Istio().NetworkingV1beta1().WorkloadEntries(namespace).Patch(ctx, name, patchType, bytePatch, patchOpts)
case kubernetes.WorkloadGroups:
istioConfigDetail.WorkloadGroup = &networking_v1beta1.WorkloadGroup{}
istioConfigDetail.WorkloadGroup, err = userClient.Istio().NetworkingV1beta1().WorkloadGroups(namespace).Patch(ctx, name, patchType, bytePatch, patchOpts)
case kubernetes.AuthorizationPolicies:
istioConfigDetail.AuthorizationPolicy = &security_v1beta1.AuthorizationPolicy{}
istioConfigDetail.AuthorizationPolicy, err = userClient.Istio().SecurityV1beta1().AuthorizationPolicies(namespace).Patch(ctx, name, patchType, bytePatch, patchOpts)
case kubernetes.PeerAuthentications:
istioConfigDetail.PeerAuthentication = &security_v1beta1.PeerAuthentication{}
istioConfigDetail.PeerAuthentication, err = userClient.Istio().SecurityV1beta1().PeerAuthentications(namespace).Patch(ctx, name, patchType, bytePatch, patchOpts)
case kubernetes.RequestAuthentications:
istioConfigDetail.RequestAuthentication = &security_v1beta1.RequestAuthentication{}
istioConfigDetail.RequestAuthentication, err = userClient.Istio().SecurityV1beta1().RequestAuthentications(namespace).Patch(ctx, name, patchType, bytePatch, patchOpts)
case kubernetes.WasmPlugins:
istioConfigDetail.WasmPlugin = &extentions_v1alpha1.WasmPlugin{}
istioConfigDetail.WasmPlugin, err = userClient.Istio().ExtensionsV1alpha1().WasmPlugins(namespace).Patch(ctx, name, patchType, bytePatch, patchOpts)
case kubernetes.Telemetries:
istioConfigDetail.Telemetry = &v1alpha1.Telemetry{}
istioConfigDetail.Telemetry, err = userClient.Istio().TelemetryV1alpha1().Telemetries(namespace).Patch(ctx, name, patchType, bytePatch, patchOpts)
default:
err = fmt.Errorf("object type not found: %v", resourceType)
}
if err != nil {
return istioConfigDetail, err
}
// We need to refresh the kube cache though at least until waiting for the object to be updated is implemented.
kubeCache.Refresh(namespace)
return istioConfigDetail, err
}
func (in *IstioConfigService) CreateIstioConfigDetail(ctx context.Context, cluster, namespace, resourceType string, body []byte) (models.IstioConfigDetails, error) {
istioConfigDetail := models.IstioConfigDetails{}
istioConfigDetail.Namespace = models.Namespace{Name: namespace}
istioConfigDetail.ObjectType = resourceType
createOpts := meta_v1.CreateOptions{}
userClient := in.userClients[cluster]
if userClient == nil {
return istioConfigDetail, fmt.Errorf("K8s Client [%s] is not found or is not accessible for Kiali", cluster)
}
kubeCache, err := in.kialiCache.GetKubeCache(cluster)
if err != nil {
return istioConfigDetail, nil
}
switch resourceType {
case kubernetes.DestinationRules:
istioConfigDetail.DestinationRule = &networking_v1beta1.DestinationRule{}
err = json.Unmarshal(body, istioConfigDetail.DestinationRule)
if err != nil {
return istioConfigDetail, api_errors.NewBadRequest(err.Error())
}
istioConfigDetail.DestinationRule, err = userClient.Istio().NetworkingV1beta1().DestinationRules(namespace).Create(ctx, istioConfigDetail.DestinationRule, createOpts)
case kubernetes.EnvoyFilters:
istioConfigDetail.EnvoyFilter = &networking_v1alpha3.EnvoyFilter{}
err = json.Unmarshal(body, istioConfigDetail.EnvoyFilter)
if err != nil {
return istioConfigDetail, api_errors.NewBadRequest(err.Error())
}
istioConfigDetail.EnvoyFilter, err = userClient.Istio().NetworkingV1alpha3().EnvoyFilters(namespace).Create(ctx, istioConfigDetail.EnvoyFilter, createOpts)
case kubernetes.Gateways:
istioConfigDetail.Gateway = &networking_v1beta1.Gateway{}
err = json.Unmarshal(body, istioConfigDetail.Gateway)
if err != nil {
return istioConfigDetail, api_errors.NewBadRequest(err.Error())
}
istioConfigDetail.Gateway, err = userClient.Istio().NetworkingV1beta1().Gateways(namespace).Create(ctx, istioConfigDetail.Gateway, createOpts)
case kubernetes.K8sGateways:
istioConfigDetail.K8sGateway = &k8s_networking_v1.Gateway{}
err = json.Unmarshal(body, istioConfigDetail.K8sGateway)
if err != nil {
return istioConfigDetail, api_errors.NewBadRequest(err.Error())
}
istioConfigDetail.K8sGateway, err = userClient.GatewayAPI().GatewayV1().Gateways(namespace).Create(ctx, istioConfigDetail.K8sGateway, createOpts)
case kubernetes.K8sHTTPRoutes:
istioConfigDetail.K8sHTTPRoute = &k8s_networking_v1.HTTPRoute{}
err = json.Unmarshal(body, istioConfigDetail.K8sHTTPRoute)
if err != nil {
return istioConfigDetail, api_errors.NewBadRequest(err.Error())
}
istioConfigDetail.K8sHTTPRoute, err = userClient.GatewayAPI().GatewayV1().HTTPRoutes(namespace).Create(ctx, istioConfigDetail.K8sHTTPRoute, createOpts)
case kubernetes.K8sReferenceGrants:
istioConfigDetail.K8sReferenceGrant = &k8s_networking_v1beta1.ReferenceGrant{}
err = json.Unmarshal(body, istioConfigDetail.K8sReferenceGrant)
if err != nil {
return istioConfigDetail, api_errors.NewBadRequest(err.Error())
}
istioConfigDetail.K8sReferenceGrant, err = userClient.GatewayAPI().GatewayV1beta1().ReferenceGrants(namespace).Create(ctx, istioConfigDetail.K8sReferenceGrant, createOpts)
case kubernetes.ServiceEntries:
istioConfigDetail.ServiceEntry = &networking_v1beta1.ServiceEntry{}
err = json.Unmarshal(body, istioConfigDetail.ServiceEntry)
if err != nil {
return istioConfigDetail, api_errors.NewBadRequest(err.Error())
}
istioConfigDetail.ServiceEntry, err = userClient.Istio().NetworkingV1beta1().ServiceEntries(namespace).Create(ctx, istioConfigDetail.ServiceEntry, createOpts)
case kubernetes.Sidecars:
istioConfigDetail.Sidecar = &networking_v1beta1.Sidecar{}
err = json.Unmarshal(body, istioConfigDetail.Sidecar)
if err != nil {
return istioConfigDetail, api_errors.NewBadRequest(err.Error())
}
istioConfigDetail.Sidecar, err = userClient.Istio().NetworkingV1beta1().Sidecars(namespace).Create(ctx, istioConfigDetail.Sidecar, createOpts)
case kubernetes.VirtualServices:
istioConfigDetail.VirtualService = &networking_v1beta1.VirtualService{}
err = json.Unmarshal(body, istioConfigDetail.VirtualService)
if err != nil {
return istioConfigDetail, api_errors.NewBadRequest(err.Error())
}
istioConfigDetail.VirtualService, err = userClient.Istio().NetworkingV1beta1().VirtualServices(namespace).Create(ctx, istioConfigDetail.VirtualService, createOpts)
case kubernetes.WorkloadEntries:
istioConfigDetail.WorkloadEntry = &networking_v1beta1.WorkloadEntry{}
err = json.Unmarshal(body, istioConfigDetail.WorkloadEntry)
if err != nil {
return istioConfigDetail, api_errors.NewBadRequest(err.Error())
}
istioConfigDetail.WorkloadEntry, err = userClient.Istio().NetworkingV1beta1().WorkloadEntries(namespace).Create(ctx, istioConfigDetail.WorkloadEntry, createOpts)
case kubernetes.WorkloadGroups:
istioConfigDetail.WorkloadGroup = &networking_v1beta1.WorkloadGroup{}
err = json.Unmarshal(body, istioConfigDetail.WorkloadGroup)
if err != nil {
return istioConfigDetail, api_errors.NewBadRequest(err.Error())
}
istioConfigDetail.WorkloadGroup, err = userClient.Istio().NetworkingV1beta1().WorkloadGroups(namespace).Create(ctx, istioConfigDetail.WorkloadGroup, createOpts)
case kubernetes.WasmPlugins:
istioConfigDetail.WasmPlugin = &extentions_v1alpha1.WasmPlugin{}
err = json.Unmarshal(body, istioConfigDetail.WasmPlugin)
if err != nil {
return istioConfigDetail, api_errors.NewBadRequest(err.Error())
}
istioConfigDetail.WasmPlugin, err = userClient.Istio().ExtensionsV1alpha1().WasmPlugins(namespace).Create(ctx, istioConfigDetail.WasmPlugin, createOpts)
case kubernetes.Telemetries:
istioConfigDetail.Telemetry = &v1alpha1.Telemetry{}
err = json.Unmarshal(body, istioConfigDetail.Telemetry)
if err != nil {
return istioConfigDetail, api_errors.NewBadRequest(err.Error())
}
istioConfigDetail.Telemetry, err = userClient.Istio().TelemetryV1alpha1().Telemetries(namespace).Create(ctx, istioConfigDetail.Telemetry, createOpts)
case kubernetes.AuthorizationPolicies:
istioConfigDetail.AuthorizationPolicy = &security_v1beta1.AuthorizationPolicy{}
err = json.Unmarshal(body, istioConfigDetail.AuthorizationPolicy)
if err != nil {
return istioConfigDetail, api_errors.NewBadRequest(err.Error())
}
istioConfigDetail.AuthorizationPolicy, err = userClient.Istio().SecurityV1beta1().AuthorizationPolicies(namespace).Create(ctx, istioConfigDetail.AuthorizationPolicy, createOpts)
case kubernetes.PeerAuthentications:
istioConfigDetail.PeerAuthentication = &security_v1beta1.PeerAuthentication{}
err = json.Unmarshal(body, istioConfigDetail.PeerAuthentication)
if err != nil {
return istioConfigDetail, api_errors.NewBadRequest(err.Error())
}
istioConfigDetail.PeerAuthentication, err = userClient.Istio().SecurityV1beta1().PeerAuthentications(namespace).Create(ctx, istioConfigDetail.PeerAuthentication, createOpts)
case kubernetes.RequestAuthentications:
istioConfigDetail.RequestAuthentication = &security_v1beta1.RequestAuthentication{}
err = json.Unmarshal(body, istioConfigDetail.RequestAuthentication)
if err != nil {
return istioConfigDetail, api_errors.NewBadRequest(err.Error())
}
istioConfigDetail.RequestAuthentication, err = userClient.Istio().SecurityV1beta1().RequestAuthentications(namespace).Create(ctx, istioConfigDetail.RequestAuthentication, createOpts)
default:
err = fmt.Errorf("object type not found: %v", resourceType)
}
if in.config.ExternalServices.Istio.IstioAPIEnabled {
// Refreshing the istio cache in case something has changed with the registry services. Not sure if this is really needed.
if err := in.controlPlaneMonitor.RefreshIstioCache(ctx); err != nil {
log.Errorf("Error while refreshing Istio cache: %s", err)
}
}
// We need to refresh the kube cache though at least until waiting for the object to be updated is implemented.
kubeCache.Refresh(namespace)
return istioConfigDetail, err
}
func (in *IstioConfigService) IsGatewayAPI(cluster string) bool {
return in.userClients[cluster].IsGatewayAPI()
}
func (in *IstioConfigService) GatewayAPIClasses(cluster string) []config.GatewayAPIClass {
return kubernetes.GatewayAPIClasses(in.IsAmbientEnabled(cluster))
}
func (in *IstioConfigService) IsAmbientEnabled(cluster string) bool {
return in.kialiCache.IsAmbientEnabled(cluster)
}
func (in *IstioConfigService) GetIstioConfigPermissions(ctx context.Context, namespaces []string, cluster string) models.IstioConfigPermissions {
var end observability.EndFunc
ctx, end = observability.StartSpan(ctx, "GetIstioConfigPermissions",
observability.Attribute("package", "business"),
observability.Attribute("namespaces", namespaces),
)
defer end()
istioConfigPermissions := make(models.IstioConfigPermissions, len(namespaces))
k8s, ok := in.userClients[cluster]
if !ok {
log.Errorf("Cluster %s doesn't exist ", cluster)
return nil
}
if len(namespaces) > 0 {
networkingPermissions := make(models.IstioConfigPermissions, len(namespaces))
k8sNetworkingPermissions := make(models.IstioConfigPermissions, len(namespaces))
securityPermissions := make(models.IstioConfigPermissions, len(namespaces))
wg := sync.WaitGroup{}
// We will query 2 times per namespace (networking.istio.io and security.istio.io)
wg.Add(len(namespaces) * 3)
for _, ns := range namespaces {
networkingRP := make(models.ResourcesPermissions, len(newNetworkingConfigTypes))
k8sNetworkingRP := make(models.ResourcesPermissions, len(newK8sNetworkingConfigTypes))
securityRP := make(models.ResourcesPermissions, len(newSecurityConfigTypes))
networkingPermissions[ns] = &networkingRP
k8sNetworkingPermissions[ns] = &k8sNetworkingRP
securityPermissions[ns] = &securityRP
/*
We can optimize this logic.
Instead of query all editable objects of networking.istio.io and security.istio.io we can query
only one per API, that will save several queries to the backend.
Synced with:
https://github.com/kiali/kiali-operator/blob/master/roles/default/kiali-deploy/templates/kubernetes/role.yaml#L62
*/
go func(ctx context.Context, namespace string, wg *sync.WaitGroup, networkingPermissions *models.ResourcesPermissions) {
defer wg.Done()
canCreate, canUpdate, canDelete := getPermissionsApi(ctx, k8s, cluster, namespace, kubernetes.NetworkingGroupVersionV1Beta1.Group, allResources)
for _, rs := range newNetworkingConfigTypes {
networkingRP[rs] = &models.ResourcePermissions{
Create: canCreate,
Update: canUpdate,
Delete: canDelete,
}
}
}(ctx, ns, &wg, &networkingRP)
go func(ctx context.Context, namespace string, wg *sync.WaitGroup, k8sNetworkingPermissions *models.ResourcesPermissions) {
defer wg.Done()
canCreate, canUpdate, canDelete := getPermissionsApi(ctx, k8s, cluster, namespace, kubernetes.K8sNetworkingGroupVersionV1.Group, allResources)
for _, rs := range newK8sNetworkingConfigTypes {
k8sNetworkingRP[rs] = &models.ResourcePermissions{
Create: canCreate && in.userClients[cluster].IsGatewayAPI(),
Update: canUpdate && in.userClients[cluster].IsGatewayAPI(),
Delete: canDelete && in.userClients[cluster].IsGatewayAPI(),
}
}
}(ctx, ns, &wg, &k8sNetworkingRP)
go func(ctx context.Context, namespace string, wg *sync.WaitGroup, securityPermissions *models.ResourcesPermissions) {