@@ -17,11 +17,8 @@ limitations under the License.
17
17
package v1beta2
18
18
19
19
import (
20
- "fmt"
21
- "reflect"
22
20
"strings"
23
21
24
- "k8s.io/apimachinery/pkg/api/errors"
25
22
"k8s.io/apimachinery/pkg/runtime"
26
23
"k8s.io/apimachinery/pkg/util/validation/field"
27
24
"sigs.k8s.io/cluster-api-provider-cloudstack/pkg/webhookutil"
@@ -79,30 +76,7 @@ func (r *CloudStackMachineTemplate) ValidateCreate() error {
79
76
80
77
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
81
78
func (r * CloudStackMachineTemplate ) ValidateUpdate (old runtime.Object ) error {
82
- cloudstackmachinetemplatelog .V (1 ).Info ("entered validate update webhook" , "api resource name" , r .Name )
83
-
84
- oldMachineTemplate , ok := old .(* CloudStackMachineTemplate )
85
- if ! ok {
86
- return errors .NewBadRequest (fmt .Sprintf ("expected a CloudStackMachineTemplate but got a %T" , old ))
87
- }
88
-
89
- // CloudStackMachineTemplateSpec.CloudStackMachineTemplateResource.CloudStackMachineSpec
90
- spec := r .Spec .Spec .Spec
91
- oldSpec := oldMachineTemplate .Spec .Spec .Spec
92
-
93
- errorList := field .ErrorList (nil )
94
- errorList = webhookutil .EnsureBothFieldsAreEqual (spec .Offering .ID , spec .Offering .Name , oldSpec .Offering .ID , oldSpec .Offering .Name , "offering" , errorList )
95
- errorList = webhookutil .EnsureBothFieldsAreEqual (spec .DiskOffering .ID , spec .DiskOffering .Name , oldSpec .DiskOffering .ID , oldSpec .DiskOffering .Name , "diskOffering" , errorList )
96
- errorList = webhookutil .EnsureStringFieldsAreEqual (spec .SSHKey , oldSpec .SSHKey , "sshkey" , errorList )
97
- errorList = webhookutil .EnsureBothFieldsAreEqual (spec .Template .ID , spec .Template .Name , oldSpec .Template .ID , oldSpec .Template .Name , "template" , errorList )
98
- errorList = webhookutil .EnsureStringStringMapFieldsAreEqual (& spec .Details , & oldSpec .Details , "details" , errorList )
99
- errorList = webhookutil .EnsureStringFieldsAreEqual (spec .Affinity , oldSpec .Affinity , "affinity" , errorList )
100
-
101
- if ! reflect .DeepEqual (spec .AffinityGroupIDs , oldSpec .AffinityGroupIDs ) { // Equivalent to other Ensure funcs.
102
- errorList = append (errorList , field .Forbidden (field .NewPath ("spec" , "AffinityGroupIDs" ), "AffinityGroupIDs" ))
103
- }
104
-
105
- return webhookutil .AggregateObjErrors (r .GroupVersionKind ().GroupKind (), r .Name , errorList )
79
+ return r .ValidateCreate ()
106
80
}
107
81
108
82
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
0 commit comments