@@ -8,23 +8,28 @@ import (
8
8
"time"
9
9
10
10
"github.com/go-logr/logr"
11
+ vapi "github.com/validator-labs/validator/api/v1alpha1"
12
+ vconstants "github.com/validator-labs/validator/pkg/constants"
11
13
"github.com/validator-labs/validator/pkg/types"
12
14
13
15
"github.com/validator-labs/validator-plugin-azure/api/v1alpha1"
14
16
"github.com/validator-labs/validator-plugin-azure/pkg/azure"
17
+ "github.com/validator-labs/validator-plugin-azure/pkg/constants"
15
18
utils "github.com/validator-labs/validator-plugin-azure/pkg/utils/azure"
16
19
)
17
20
18
21
// Validate validates the AzureValidatorSpec and returns a ValidationResponse.
19
- func Validate (ctx context.Context , spec v1alpha1.AzureValidatorSpec , log logr.Logger ) ( types.ValidationResponse , error ) {
22
+ func Validate (ctx context.Context , spec v1alpha1.AzureValidatorSpec , log logr.Logger ) types.ValidationResponse {
20
23
resp := types.ValidationResponse {
21
24
ValidationRuleResults : make ([]* types.ValidationRuleResult , 0 , spec .ResultCount ()),
22
25
ValidationRuleErrors : make ([]error , 0 , spec .ResultCount ()),
23
26
}
24
27
25
28
azureAPI , err := utils .NewAzureAPI ()
26
29
if err != nil {
27
- return resp , fmt .Errorf ("failed to create Azure API object: %w" , err )
30
+ vrr := buildValidationResult ()
31
+ resp .AddResult (vrr , fmt .Errorf ("failed to create Azure API object: %w" , err ))
32
+ return resp
28
33
}
29
34
30
35
ctx = context .WithoutCancel (ctx )
@@ -59,5 +64,15 @@ func Validate(ctx context.Context, spec v1alpha1.AzureValidatorSpec, log logr.Lo
59
64
resp .AddResult (vrr , err )
60
65
}
61
66
62
- return resp , nil
67
+ return resp
68
+ }
69
+
70
+ func buildValidationResult () * types.ValidationRuleResult {
71
+ state := vapi .ValidationSucceeded
72
+ latestCondition := vapi .DefaultValidationCondition ()
73
+ latestCondition .Message = "Initialization succeeded"
74
+ latestCondition .ValidationRule = fmt .Sprintf ("%s-%s" , vconstants .ValidationRulePrefix , constants .PluginCode )
75
+ latestCondition .ValidationType = constants .PluginCode
76
+
77
+ return & types.ValidationRuleResult {Condition : & latestCondition , State : & state }
63
78
}
0 commit comments