@@ -17,11 +17,8 @@ limitations under the License.
1717package v1beta2
1818
1919import (
20- "fmt"
21- "reflect"
2220 "strings"
2321
24- "k8s.io/apimachinery/pkg/api/errors"
2522 "k8s.io/apimachinery/pkg/runtime"
2623 "k8s.io/apimachinery/pkg/util/validation/field"
2724 "sigs.k8s.io/cluster-api-provider-cloudstack/pkg/webhookutil"
@@ -79,30 +76,7 @@ func (r *CloudStackMachineTemplate) ValidateCreate() error {
7976
8077// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
8178func (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 ()
10680}
10781
10882// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
0 commit comments