-
Notifications
You must be signed in to change notification settings - Fork 479
/
virtual_service_checker.go
76 lines (58 loc) · 2.73 KB
/
virtual_service_checker.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
package checkers
import (
networking_v1beta1 "istio.io/client-go/pkg/apis/networking/v1beta1"
"github.com/kiali/kiali/business/checkers/common"
"github.com/kiali/kiali/business/checkers/virtualservices"
"github.com/kiali/kiali/models"
)
const VirtualCheckerType = "virtualservice"
type VirtualServiceChecker struct {
Namespaces models.Namespaces
VirtualServices []*networking_v1beta1.VirtualService
DestinationRules []*networking_v1beta1.DestinationRule
}
// An Object Checker runs all checkers for an specific object type (i.e.: pod, route rule,...)
// It run two kinds of checkers:
// 1. Individual checks: validating individual objects.
// 2. Group checks: validating behaviour between configurations.
func (in VirtualServiceChecker) Check() models.IstioValidations {
validations := models.IstioValidations{}
validations = validations.MergeValidations(in.runIndividualChecks())
validations = validations.MergeValidations(in.runGroupChecks())
return validations
}
// Runs individual checks for each virtual service
func (in VirtualServiceChecker) runIndividualChecks() models.IstioValidations {
validations := models.IstioValidations{}
for _, virtualService := range in.VirtualServices {
validations.MergeValidations(in.runChecks(virtualService))
}
return validations
}
// runGroupChecks runs group checks for all virtual services
func (in VirtualServiceChecker) runGroupChecks() models.IstioValidations {
validations := models.IstioValidations{}
enabledCheckers := []GroupChecker{
virtualservices.SingleHostChecker{Namespaces: in.Namespaces, VirtualServices: in.VirtualServices},
}
for _, checker := range enabledCheckers {
validations = validations.MergeValidations(checker.Check())
}
return validations
}
// runChecks runs all the individual checks for a single virtual service and appends the result into validations.
func (in VirtualServiceChecker) runChecks(virtualService *networking_v1beta1.VirtualService) models.IstioValidations {
virtualServiceName := virtualService.Name
key, rrValidation := EmptyValidValidation(virtualServiceName, virtualService.Namespace, VirtualCheckerType)
enabledCheckers := []Checker{
virtualservices.RouteChecker{VirtualService: virtualService, Namespaces: in.Namespaces.GetNames()},
virtualservices.SubsetPresenceChecker{Namespaces: in.Namespaces.GetNames(), VirtualService: virtualService, DestinationRules: in.DestinationRules},
common.ExportToNamespaceChecker{ExportTo: virtualService.Spec.ExportTo, Namespaces: in.Namespaces},
}
for _, checker := range enabledCheckers {
checks, validChecker := checker.Check()
rrValidation.Checks = append(rrValidation.Checks, checks...)
rrValidation.Valid = rrValidation.Valid && validChecker
}
return models.IstioValidations{key: rrValidation}
}