-
Notifications
You must be signed in to change notification settings - Fork 490
/
types.go
361 lines (313 loc) · 13.2 KB
/
types.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
package kubernetes
import (
"time"
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_v1beta "istio.io/client-go/pkg/apis/security/v1beta1"
"istio.io/client-go/pkg/apis/telemetry/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
k8s_networking_v1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
)
const (
// Kubernetes Controllers
ConfigMapType = "ConfigMap"
CronJobType = "CronJob"
DaemonSetType = "DaemonSet"
DeploymentType = "Deployment"
DeploymentConfigType = "DeploymentConfig"
EndpointsType = "Endpoints"
JobType = "Job"
PodType = "Pod"
ReplicationControllerType = "ReplicationController"
ReplicaSetType = "ReplicaSet"
ServiceType = "Service"
StatefulSetType = "StatefulSet"
// Networking
DestinationRules = "destinationrules"
DestinationRuleType = "DestinationRule"
Gateways = "gateways"
GatewayType = "Gateway"
EnvoyFilters = "envoyfilters"
EnvoyFilterType = "EnvoyFilter"
Sidecars = "sidecars"
SidecarType = "Sidecar"
ServiceEntries = "serviceentries"
ServiceEntryType = "ServiceEntry"
VirtualServices = "virtualservices"
VirtualServiceType = "VirtualService"
WorkloadEntries = "workloadentries"
WorkloadEntryType = "WorkloadEntry"
WorkloadGroups = "workloadgroups"
WorkloadGroupType = "WorkloadGroup"
WasmPlugins = "wasmplugins"
WasmPluginType = "WasmPlugin"
Telemetries = "telemetries"
TelemetryType = "Telemetry"
// K8s Networking
K8sGateways = "k8sgateways"
K8sGatewayType = "K8sGateway"
// K8sActualGatewayType There is a naming conflict between Istio and K8s Gateways, keeping here an actual type to show in YAML editor
K8sActualGatewayType = "Gateway"
K8sHTTPRoutes = "k8shttproutes"
K8sHTTPRouteType = "K8sHTTPRoute"
// K8sActualHTTPRouteType There is a naming conflict between Istio and K8s Gateways, keeping here an actual type to show in YAML editor
K8sActualHTTPRouteType = "HTTPRoute"
// Authorization PeerAuthentications
AuthorizationPolicies = "authorizationpolicies"
AuthorizationPoliciesType = "AuthorizationPolicy"
// Peer Authentications
PeerAuthentications = "peerauthentications"
PeerAuthenticationsType = "PeerAuthentication"
// Request Authentications
RequestAuthentications = "requestauthentications"
RequestAuthenticationsType = "RequestAuthentication"
)
var (
NetworkingGroupVersionV1Alpha3 = schema.GroupVersion{
Group: "networking.istio.io",
Version: "v1alpha3",
}
ApiNetworkingVersionV1Alpha3 = NetworkingGroupVersionV1Alpha3.Group + "/" + NetworkingGroupVersionV1Alpha3.Version
K8sNetworkingGroupVersionV1Alpha2 = schema.GroupVersion{
Group: "gateway.networking.k8s.io",
Version: "v1alpha2",
}
K8sApiNetworkingVersionV1Alpha2 = K8sNetworkingGroupVersionV1Alpha2.Group + "/" + K8sNetworkingGroupVersionV1Alpha2.Version
K8sNetworkingGroupVersionV1Beta1 = schema.GroupVersion{
Group: "gateway.networking.k8s.io",
Version: "v1beta1",
}
K8sApiNetworkingVersionV1Beta1 = K8sNetworkingGroupVersionV1Beta1.Group + "/" + K8sNetworkingGroupVersionV1Beta1.Version
NetworkingGroupVersionV1Beta1 = schema.GroupVersion{
Group: "networking.istio.io",
Version: "v1beta1",
}
ApiNetworkingVersionV1Beta1 = NetworkingGroupVersionV1Beta1.Group + "/" + NetworkingGroupVersionV1Beta1.Version
SecurityGroupVersion = schema.GroupVersion{
Group: "security.istio.io",
Version: "v1beta1",
}
ApiSecurityVersion = SecurityGroupVersion.Group + "/" + SecurityGroupVersion.Version
ExtensionGroupVersionV1Alpha1 = schema.GroupVersion{
Group: "extensions.istio.io",
Version: "v1alpha1",
}
ApiExtensionV1Alpha1 = ExtensionGroupVersionV1Alpha1.Group + "/" + ExtensionGroupVersionV1Alpha1.Version
TelemetryGroupV1Alpha1 = schema.GroupVersion{
Group: "telemetry.istio.io",
Version: "v1alpha1",
}
ApiTelemetryV1Alpha1 = TelemetryGroupV1Alpha1.Group + "/" + TelemetryGroupV1Alpha1.Version
PluralType = map[string]string{
// Networking
Gateways: GatewayType,
VirtualServices: VirtualServiceType,
DestinationRules: DestinationRuleType,
ServiceEntries: ServiceEntryType,
Sidecars: SidecarType,
WorkloadEntries: WorkloadEntryType,
WorkloadGroups: WorkloadGroupType,
EnvoyFilters: EnvoyFilterType,
WasmPlugins: WasmPluginType,
Telemetries: TelemetryType,
// K8s Networking Gateways
K8sGateways: K8sGatewayType,
K8sHTTPRoutes: K8sHTTPRouteType,
// Security
AuthorizationPolicies: AuthorizationPoliciesType,
PeerAuthentications: PeerAuthenticationsType,
RequestAuthentications: RequestAuthenticationsType,
}
ResourceTypesToAPI = map[string]string{
DestinationRules: NetworkingGroupVersionV1Beta1.Group,
EnvoyFilters: NetworkingGroupVersionV1Alpha3.Group,
Gateways: NetworkingGroupVersionV1Beta1.Group,
ServiceEntries: NetworkingGroupVersionV1Beta1.Group,
Sidecars: NetworkingGroupVersionV1Beta1.Group,
VirtualServices: NetworkingGroupVersionV1Beta1.Group,
WorkloadEntries: NetworkingGroupVersionV1Beta1.Group,
WorkloadGroups: NetworkingGroupVersionV1Beta1.Group,
WasmPlugins: ExtensionGroupVersionV1Alpha1.Group,
Telemetries: TelemetryGroupV1Alpha1.Group,
K8sGateways: K8sNetworkingGroupVersionV1Beta1.Group,
K8sHTTPRoutes: K8sNetworkingGroupVersionV1Beta1.Group,
AuthorizationPolicies: SecurityGroupVersion.Group,
PeerAuthentications: SecurityGroupVersion.Group,
RequestAuthentications: SecurityGroupVersion.Group,
}
)
type IstioMeshConfig struct {
DisableMixerHttpReports bool `yaml:"disableMixerHttpReports,omitempty"`
DiscoverySelectors []*metav1.LabelSelector `yaml:"discoverySelectors,omitempty"`
EnableAutoMtls *bool `yaml:"enableAutoMtls,omitempty"`
}
// MTLSDetails is a wrapper to group all Istio objects related to non-local mTLS configurations
type MTLSDetails struct {
DestinationRules []*networking_v1beta1.DestinationRule `json:"destinationrules"`
MeshPeerAuthentications []*security_v1beta.PeerAuthentication `json:"meshpeerauthentications"`
PeerAuthentications []*security_v1beta.PeerAuthentication `json:"peerauthentications"`
EnabledAutoMtls bool `json:"enabledautomtls"`
}
// RBACDetails is a wrapper for objects related to Istio RBAC (Role Based Access Control)
type RBACDetails struct {
AuthorizationPolicies []*security_v1beta.AuthorizationPolicy `json:"authorizationpolicies"`
}
type ProxyStatus struct {
pilot string
SyncStatus
}
// SyncStatus is the synchronization status between Pilot and a given Envoy
type SyncStatus struct {
ClusterID string `json:"cluster_id,omitempty"`
ProxyID string `json:"proxy,omitempty"`
ProxyVersion string `json:"proxy_version,omitempty"`
IstioVersion string `json:"istio_version,omitempty"`
ClusterSent string `json:"cluster_sent,omitempty"`
ClusterAcked string `json:"cluster_acked,omitempty"`
ListenerSent string `json:"listener_sent,omitempty"`
ListenerAcked string `json:"listener_acked,omitempty"`
RouteSent string `json:"route_sent,omitempty"`
RouteAcked string `json:"route_acked,omitempty"`
EndpointSent string `json:"endpoint_sent,omitempty"`
EndpointAcked string `json:"endpoint_acked,omitempty"`
}
// RegistryConfiguration will hold the Istio configuration required for Kiali validations
// Resources not used (i.e. EnvoyFilters) are not added, those will require update them in the future
type RegistryConfiguration struct {
// Networking
DestinationRules []*networking_v1beta1.DestinationRule
EnvoyFilters []*networking_v1alpha3.EnvoyFilter
Gateways []*networking_v1beta1.Gateway
ServiceEntries []*networking_v1beta1.ServiceEntry
Sidecars []*networking_v1beta1.Sidecar
VirtualServices []*networking_v1beta1.VirtualService
WorkloadEntries []*networking_v1beta1.WorkloadEntry
WorkloadGroups []*networking_v1beta1.WorkloadGroup
WasmPlugins []*extentions_v1alpha1.WasmPlugin
Telemetries []*v1alpha1.Telemetry
// K8s Networking Gateways
K8sGateways []*k8s_networking_v1beta1.Gateway
K8sHTTPRoutes []*k8s_networking_v1beta1.HTTPRoute
// Security
AuthorizationPolicies []*security_v1beta.AuthorizationPolicy
PeerAuthentications []*security_v1beta.PeerAuthentication
RequestAuthentications []*security_v1beta.RequestAuthentication
}
type RegistryEndpoint struct {
pilot string
IstioEndpoint
}
type IstioEndpoint struct {
Service string `json:"svc"`
Endpoints []struct {
Service IstioService `json:"service,omitempty"`
ServicePort struct {
Name string `json:"name,omitempty"`
Port uint32 `json:"port,omitempty"`
Protocol string `json:"protocol,omitempty"`
} `json:"servicePort,omitempty"`
Endpoint struct {
Labels map[string]string `json:"Labels,omitempty"`
Address string `json:"Address,omitempty"`
ServicePortName string `json:"ServicePortName,omitempty"`
// EnvoyEndpoint is not mapped into the model
ServiceAccount string `json:"ServiceAccount,omitempty"`
Network string `json:"Network,omitempty"`
Locality struct {
Label string `json:"Label,omitempty"`
ClusterID string `json:"ClusterID,omitempty"`
} `json:"Locality,omitempty"`
EndpointPort uint32 `json:"EndpointPort,omitempty"`
LbWeight uint32 `json:"LbWeight,omitempty"`
TLSMode string `json:"TLSMode,omitempty"`
Namespace string `json:"Namespace,omitempty"`
WorkloadName string `json:"WorkloadName,omitempty"`
HostName string `json:"HostName,omitempty"`
SubDomain string `json:"SubDomain,omitempty"`
// TunnelAbility and DiscoverabilityPolicy are not mapped into the model
} `json:"endpoint"`
} `json:"ep"`
}
type RegistryService struct {
pilot string
IstioService
}
// Mapped from https://github.com/istio/istio/blob/master/pilot/pkg/model/service.go
// It's a helper to fetch the /debug/registryz results before to parse it to the Kiali's Service model
// Not all fields from /debug/registryz are mapped, only those needed by Kiali
// There may be differences between Istio 1.11.x and 1.12.x to be addressed case by case in the mapping
type IstioService struct {
Attributes struct {
// ServiceRegistry values:
// Kubernetes: is a service registry backed by k8s API server
// External: is a service registry for externally provided ServiceEntries
// Federation: special case when registry is provided from a federated environment
ServiceRegistry string `json:"ServiceRegistry,omitempty"`
Name string `json:"Name,omitempty"`
Namespace string `json:"Namespace,omitempty"`
Labels map[string]string `json:"Labels,omitempty"`
// UID is present in Istio 1.11.x but not in 1.12.x
UID string `json:"UID,omitempty"`
// ExportTo key values:
// ".": Private implies namespace local config
// "*": Public implies config is visible to all
// "~": None implies service is visible to no one. Used for services only
ExportTo map[string]bool `json:"ExportTo,omitempty"`
LabelSelectors map[string]string `json:"LabelSelectors,omitempty"`
// ClusterExternalAddresses and ClusterExternalPorts are not mapped into the model
// Kiali won't use it yet and these attributes changes between Istio 1.11.x and Istio 1.12.x and may bring conflicts
} `json:"Attributes,omitempty"`
Ports []struct {
Name string `json:"name,omitempty"`
Port int `json:"port"`
Protocol string `json:"protocol,omitempty"`
} `json:"ports"`
ServiceAccounts []string `json:"serviceAccounts,omitempty"`
CreationTime time.Time `json:"creationTime,omitempty"`
Hostname string `json:"hostname"`
// Address is present in Istio 1.11.x but not in 1.12.x
Address string `json:"address,omitempty"`
AutoAllocatedAddress string `json:"autoAllocatedAddress,omitempty"`
// ClusterVIPs defined in Istio 1.11.x
ClusterVIPs11 map[string]string `json:"cluster-vips,omitempty"`
// ClusterVIPs defined in Istio 1.12.x
ClusterVIPs12 struct {
Addresses map[string][]string `json:"Addresses,omitempty"`
} `json:"clusterVIPs,omitempty"`
// Resolution values, as the debug endpoint doesn't perform a conversion
// 0: ClientSideLB
// 1: DNSLB
// 2: Passthrough
Resolution int `json:"Resolution,omitempty"`
MeshExternal bool `json:"MeshExternal,omitempty"`
// ResourceVersion attribute is not mapped into the model
// Kiali won't use it yet and it is only present on Istio 1.12.x
}
type RegistryStatus struct {
Configuration *RegistryConfiguration
Endpoints []*RegistryEndpoint
Services []*RegistryService
}
func (imc IstioMeshConfig) GetEnableAutoMtls() bool {
if imc.EnableAutoMtls == nil {
return true
}
return *imc.EnableAutoMtls
}
func GetPatchType(patchType string) types.PatchType {
switch patchType {
case "json":
return types.JSONPatchType
case "strategic":
return types.StrategicMergePatchType
case "apply":
return types.ApplyPatchType
case "merge":
return types.MergePatchType
default:
return types.MergePatchType
}
}