@@ -33,10 +33,8 @@ import (
33
33
"sigs.k8s.io/controller-runtime/pkg/client"
34
34
35
35
"github.com/validator-labs/validator-plugin-azure/api/v1alpha1"
36
- "github.com/validator-labs/validator-plugin-azure/pkg/azure"
37
- utils "github.com/validator-labs/validator-plugin-azure/pkg/utils/azure"
36
+ "github.com/validator-labs/validator-plugin-azure/pkg/validate"
38
37
vapi "github.com/validator-labs/validator/api/v1alpha1"
39
- "github.com/validator-labs/validator/pkg/types"
40
38
vres "github.com/validator-labs/validator/pkg/validationresult"
41
39
)
42
40
@@ -105,47 +103,8 @@ func (r *AzureValidatorReconciler) Reconcile(ctx context.Context, req ctrl.Reque
105
103
// Always update the expected result count in case the validator's rules have changed
106
104
vr .Spec .ExpectedResults = validator .Spec .ResultCount ()
107
105
108
- resp := types.ValidationResponse {
109
- ValidationRuleResults : make ([]* types.ValidationRuleResult , 0 , vr .Spec .ExpectedResults ),
110
- ValidationRuleErrors : make ([]error , 0 , vr .Spec .ExpectedResults ),
111
- }
112
-
113
- azureAPI , err := utils .NewAzureAPI ()
114
- if err != nil {
115
- l .Error (err , "failed to create Azure API object" )
116
- } else {
117
- azureCtx := context .WithoutCancel (ctx )
118
- if os .Getenv ("IS_TEST" ) == "true" {
119
- var cancel context.CancelFunc
120
- azureCtx , cancel = context .WithDeadline (ctx , time .Now ().Add (utils .TestClientTimeout ))
121
- defer cancel ()
122
- }
123
-
124
- daClient := utils .NewDenyAssignmentsClient (azureCtx , azureAPI .DenyAssignmentsClient )
125
- raClient := utils .NewRoleAssignmentsClient (azureCtx , azureAPI .RoleAssignmentsClient )
126
- rdClient := utils .NewRoleDefinitionsClient (azureCtx , azureAPI .RoleDefinitionsClient )
127
- cgiClient := utils .NewCommunityGalleryImagesClient (azureCtx , azureAPI .CommunityGalleryImagesClientProducer )
128
-
129
- // RBAC rules
130
- rbacSvc := azure .NewRBACRuleService (daClient , raClient , rdClient )
131
- for _ , rule := range validator .Spec .RBACRules {
132
- vrr , err := rbacSvc .ReconcileRBACRule (rule )
133
- if err != nil {
134
- l .Error (err , "failed to reconcile RBAC rule" )
135
- }
136
- resp .AddResult (vrr , err )
137
- }
138
-
139
- // Community gallery image rules
140
- cgiSvc := azure .NewCommunityGalleryImageRuleService (cgiClient , r .Log )
141
- for _ , rule := range validator .Spec .CommunityGalleryImageRules {
142
- vrr , err := cgiSvc .ReconcileCommunityGalleryImageRule (rule )
143
- if err != nil {
144
- l .Error (err , "failed to reconcile community gallery image rule" )
145
- }
146
- resp .AddResult (vrr , err )
147
- }
148
- }
106
+ // Validate the rules
107
+ resp := validate .Validate (validator .Spec , r .Log )
149
108
150
109
// Patch the ValidationResult with the latest ValidationRuleResults
151
110
if err := vres .SafeUpdate (ctx , p , vr , resp , r .Log ); err != nil {
0 commit comments