@@ -42,33 +42,43 @@ var _ webhook.Validator = &AzureMachine{}
4242// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
4343func (m * AzureMachine ) ValidateCreate () error {
4444 machinelog .Info ("validate create" , "name" , m .Name )
45+ var allErrs field.ErrorList
4546
4647 if errs := ValidateImage (m .Spec .Image , field .NewPath ("image" )); len (errs ) > 0 {
47- return apierrors .NewInvalid (
48- GroupVersion .WithKind ("AzureMachine" ).GroupKind (),
49- m .Name , errs )
48+ allErrs = append (allErrs , errs ... )
5049 }
5150
5251 if errs := ValidateSSHKey (m .Spec .SSHPublicKey , field .NewPath ("sshPublicKey" )); len (errs ) > 0 {
53- return apierrors .NewInvalid (
54- GroupVersion .WithKind ("AzureMachine" ).GroupKind (),
55- m .Name , errs )
52+ allErrs = append (allErrs , errs ... )
5653 }
5754
58- return nil
55+ if errs := ValidateUserAssignedIdentity (m .Spec .Identity , m .Spec .UserAssignedIdentities , field .NewPath ("userAssignedIdentities" )); len (errs ) > 0 {
56+ allErrs = append (allErrs , errs ... )
57+ }
58+
59+ if len (allErrs ) == 0 {
60+ return nil
61+ }
62+ return apierrors .NewInvalid (GroupVersion .WithKind ("AzureMachine" ).GroupKind (), m .Name , allErrs )
5963}
6064
6165// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
6266func (m * AzureMachine ) ValidateUpdate (old runtime.Object ) error {
6367 machinelog .Info ("validate update" , "name" , m .Name )
68+ var allErrs field.ErrorList
6469
6570 if errs := ValidateSSHKey (m .Spec .SSHPublicKey , field .NewPath ("sshPublicKey" )); len (errs ) > 0 {
66- return apierrors .NewInvalid (
67- GroupVersion .WithKind ("AzureMachine" ).GroupKind (),
68- m .Name , errs )
71+ allErrs = append (allErrs , errs ... )
6972 }
7073
71- return nil
74+ if errs := ValidateUserAssignedIdentity (m .Spec .Identity , m .Spec .UserAssignedIdentities , field .NewPath ("userAssignedIdentities" )); len (errs ) > 0 {
75+ allErrs = append (allErrs , errs ... )
76+ }
77+
78+ if len (allErrs ) == 0 {
79+ return nil
80+ }
81+ return apierrors .NewInvalid (GroupVersion .WithKind ("AzureMachine" ).GroupKind (), m .Name , allErrs )
7282}
7383
7484// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
0 commit comments