diff --git a/apis/v1alpha3/conversion.go b/apis/v1alpha3/conversion.go index 8cbe0dc91d..95747d0846 100644 --- a/apis/v1alpha3/conversion.go +++ b/apis/v1alpha3/conversion.go @@ -47,3 +47,8 @@ func Convert_v1beta1_VSphereMachineSpec_To_v1alpha3_VSphereMachineSpec(in *infra func Convert_v1beta1_VSphereVMSpec_To_v1alpha3_VSphereVMSpec(in *infrav1.VSphereVMSpec, out *VSphereVMSpec, s conversion.Scope) error { return autoConvert_v1beta1_VSphereVMSpec_To_v1alpha3_VSphereVMSpec(in, out, s) } + +// This is required as the v1beta1 topology has an additional `storagePolicy` field. +func Convert_v1beta1_Topology_To_v1alpha3_Topology(in *infrav1.Topology, out *Topology, s conversion.Scope) error { + return autoConvert_v1beta1_Topology_To_v1alpha3_Topology(in, out, s) +} diff --git a/apis/v1alpha3/zz_generated.conversion.go b/apis/v1alpha3/zz_generated.conversion.go index 966195ccbb..72b3de53f2 100644 --- a/apis/v1alpha3/zz_generated.conversion.go +++ b/apis/v1alpha3/zz_generated.conversion.go @@ -155,11 +155,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*v1beta1.Topology)(nil), (*Topology)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta1_Topology_To_v1alpha3_Topology(a.(*v1beta1.Topology), b.(*Topology), scope) - }); err != nil { - return err - } if err := s.AddGeneratedConversionFunc((*VSphereCluster)(nil), (*v1beta1.VSphereCluster)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha3_VSphereCluster_To_v1beta1_VSphereCluster(a.(*VSphereCluster), b.(*v1beta1.VSphereCluster), scope) }); err != nil { @@ -460,6 +455,11 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*v1beta1.Topology)(nil), (*Topology)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_Topology_To_v1alpha3_Topology(a.(*v1beta1.Topology), b.(*Topology), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*v1beta1.VSphereClusterSpec)(nil), (*VSphereClusterSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1beta1_VSphereClusterSpec_To_v1alpha3_VSphereClusterSpec(a.(*v1beta1.VSphereClusterSpec), b.(*VSphereClusterSpec), scope) }); err != nil { @@ -860,14 +860,10 @@ func autoConvert_v1beta1_Topology_To_v1alpha3_Topology(in *v1beta1.Topology, out out.Hosts = (*FailureDomainHosts)(unsafe.Pointer(in.Hosts)) out.Networks = *(*[]string)(unsafe.Pointer(&in.Networks)) out.Datastore = in.Datastore + // WARNING: in.StoragePolicy requires manual conversion: does not exist in peer-type return nil } -// Convert_v1beta1_Topology_To_v1alpha3_Topology is an autogenerated conversion function. -func Convert_v1beta1_Topology_To_v1alpha3_Topology(in *v1beta1.Topology, out *Topology, s conversion.Scope) error { - return autoConvert_v1beta1_Topology_To_v1alpha3_Topology(in, out, s) -} - func autoConvert_v1alpha3_VSphereCluster_To_v1beta1_VSphereCluster(in *VSphereCluster, out *v1beta1.VSphereCluster, s conversion.Scope) error { out.ObjectMeta = in.ObjectMeta if err := Convert_v1alpha3_VSphereClusterSpec_To_v1beta1_VSphereClusterSpec(&in.Spec, &out.Spec, s); err != nil { @@ -1219,7 +1215,17 @@ func Convert_v1beta1_VSphereFailureDomain_To_v1alpha3_VSphereFailureDomain(in *v func autoConvert_v1alpha3_VSphereFailureDomainList_To_v1beta1_VSphereFailureDomainList(in *VSphereFailureDomainList, out *v1beta1.VSphereFailureDomainList, s conversion.Scope) error { out.ListMeta = in.ListMeta - out.Items = *(*[]v1beta1.VSphereFailureDomain)(unsafe.Pointer(&in.Items)) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]v1beta1.VSphereFailureDomain, len(*in)) + for i := range *in { + if err := Convert_v1alpha3_VSphereFailureDomain_To_v1beta1_VSphereFailureDomain(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Items = nil + } return nil } @@ -1230,7 +1236,17 @@ func Convert_v1alpha3_VSphereFailureDomainList_To_v1beta1_VSphereFailureDomainLi func autoConvert_v1beta1_VSphereFailureDomainList_To_v1alpha3_VSphereFailureDomainList(in *v1beta1.VSphereFailureDomainList, out *VSphereFailureDomainList, s conversion.Scope) error { out.ListMeta = in.ListMeta - out.Items = *(*[]VSphereFailureDomain)(unsafe.Pointer(&in.Items)) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]VSphereFailureDomain, len(*in)) + for i := range *in { + if err := Convert_v1beta1_VSphereFailureDomain_To_v1alpha3_VSphereFailureDomain(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Items = nil + } return nil } diff --git a/apis/v1alpha4/conversion.go b/apis/v1alpha4/conversion.go index 289c7933a3..1837bd072b 100644 --- a/apis/v1alpha4/conversion.go +++ b/apis/v1alpha4/conversion.go @@ -46,3 +46,8 @@ func Convert_v1beta1_VSphereMachineSpec_To_v1alpha4_VSphereMachineSpec(in *infra func Convert_v1beta1_VSphereVMSpec_To_v1alpha4_VSphereVMSpec(in *infrav1.VSphereVMSpec, out *VSphereVMSpec, s conversion.Scope) error { return autoConvert_v1beta1_VSphereVMSpec_To_v1alpha4_VSphereVMSpec(in, out, s) } + +// This is required as the v1beta1 topology has an additional `storagePolicy` field. +func Convert_v1beta1_Topology_To_v1alpha4_Topology(in *infrav1.Topology, out *Topology, s conversion.Scope) error { + return autoConvert_v1beta1_Topology_To_v1alpha4_Topology(in, out, s) +} diff --git a/apis/v1alpha4/zz_generated.conversion.go b/apis/v1alpha4/zz_generated.conversion.go index 147c1a9894..b7bb554d59 100644 --- a/apis/v1alpha4/zz_generated.conversion.go +++ b/apis/v1alpha4/zz_generated.conversion.go @@ -155,11 +155,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*v1beta1.Topology)(nil), (*Topology)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta1_Topology_To_v1alpha4_Topology(a.(*v1beta1.Topology), b.(*Topology), scope) - }); err != nil { - return err - } if err := s.AddGeneratedConversionFunc((*VSphereCluster)(nil), (*v1beta1.VSphereCluster)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha4_VSphereCluster_To_v1beta1_VSphereCluster(a.(*VSphereCluster), b.(*v1beta1.VSphereCluster), scope) }); err != nil { @@ -500,6 +495,11 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*v1beta1.Topology)(nil), (*Topology)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_Topology_To_v1alpha4_Topology(a.(*v1beta1.Topology), b.(*Topology), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*v1beta1.VSphereClusterSpec)(nil), (*VSphereClusterSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1beta1_VSphereClusterSpec_To_v1alpha4_VSphereClusterSpec(a.(*v1beta1.VSphereClusterSpec), b.(*VSphereClusterSpec), scope) }); err != nil { @@ -896,14 +896,10 @@ func autoConvert_v1beta1_Topology_To_v1alpha4_Topology(in *v1beta1.Topology, out out.Hosts = (*FailureDomainHosts)(unsafe.Pointer(in.Hosts)) out.Networks = *(*[]string)(unsafe.Pointer(&in.Networks)) out.Datastore = in.Datastore + // WARNING: in.StoragePolicy requires manual conversion: does not exist in peer-type return nil } -// Convert_v1beta1_Topology_To_v1alpha4_Topology is an autogenerated conversion function. -func Convert_v1beta1_Topology_To_v1alpha4_Topology(in *v1beta1.Topology, out *Topology, s conversion.Scope) error { - return autoConvert_v1beta1_Topology_To_v1alpha4_Topology(in, out, s) -} - func autoConvert_v1alpha4_VSphereCluster_To_v1beta1_VSphereCluster(in *VSphereCluster, out *v1beta1.VSphereCluster, s conversion.Scope) error { out.ObjectMeta = in.ObjectMeta if err := Convert_v1alpha4_VSphereClusterSpec_To_v1beta1_VSphereClusterSpec(&in.Spec, &out.Spec, s); err != nil { @@ -1373,7 +1369,17 @@ func Convert_v1beta1_VSphereFailureDomain_To_v1alpha4_VSphereFailureDomain(in *v func autoConvert_v1alpha4_VSphereFailureDomainList_To_v1beta1_VSphereFailureDomainList(in *VSphereFailureDomainList, out *v1beta1.VSphereFailureDomainList, s conversion.Scope) error { out.ListMeta = in.ListMeta - out.Items = *(*[]v1beta1.VSphereFailureDomain)(unsafe.Pointer(&in.Items)) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]v1beta1.VSphereFailureDomain, len(*in)) + for i := range *in { + if err := Convert_v1alpha4_VSphereFailureDomain_To_v1beta1_VSphereFailureDomain(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Items = nil + } return nil } @@ -1384,7 +1390,17 @@ func Convert_v1alpha4_VSphereFailureDomainList_To_v1beta1_VSphereFailureDomainLi func autoConvert_v1beta1_VSphereFailureDomainList_To_v1alpha4_VSphereFailureDomainList(in *v1beta1.VSphereFailureDomainList, out *VSphereFailureDomainList, s conversion.Scope) error { out.ListMeta = in.ListMeta - out.Items = *(*[]VSphereFailureDomain)(unsafe.Pointer(&in.Items)) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]VSphereFailureDomain, len(*in)) + for i := range *in { + if err := Convert_v1beta1_VSphereFailureDomain_To_v1alpha4_VSphereFailureDomain(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Items = nil + } return nil } diff --git a/apis/v1beta1/vspherefailuredomain_types.go b/apis/v1beta1/vspherefailuredomain_types.go index bcb139a97f..1cb114c707 100644 --- a/apis/v1beta1/vspherefailuredomain_types.go +++ b/apis/v1beta1/vspherefailuredomain_types.go @@ -85,6 +85,11 @@ type Topology struct { // virtual machine is created/located. // +optional Datastore string `json:"datastore,omitempty"` + + // StoragePolicy is the name of the policy that is used to target a datastore + // in which the virtual machine is created/located. + // +optional + StoragePolicy string `json:"storagePolicy,omitempty"` } // FailureDomainHosts has information required for placement of machines on VSphere hosts. diff --git a/config/default/crd/bases/infrastructure.cluster.x-k8s.io_vspherefailuredomains.yaml b/config/default/crd/bases/infrastructure.cluster.x-k8s.io_vspherefailuredomains.yaml index 0e102bdac3..835ff20c7e 100644 --- a/config/default/crd/bases/infrastructure.cluster.x-k8s.io_vspherefailuredomains.yaml +++ b/config/default/crd/bases/infrastructure.cluster.x-k8s.io_vspherefailuredomains.yaml @@ -368,6 +368,11 @@ spec: items: type: string type: array + storagePolicy: + description: |- + StoragePolicy is the name of the policy that is used to target a datastore + in which the virtual machine is created/located. + type: string required: - datacenter type: object diff --git a/pkg/services/vimmachine.go b/pkg/services/vimmachine.go index abda5dc598..ea71620754 100644 --- a/pkg/services/vimmachine.go +++ b/pkg/services/vimmachine.go @@ -432,6 +432,9 @@ func (v *VimMachineService) generateOverrideFunc(ctx context.Context, vimMachine if vsphereDeploymentZone.Spec.PlacementConstraint.ResourcePool != "" { vm.Spec.ResourcePool = vsphereDeploymentZone.Spec.PlacementConstraint.ResourcePool } + if vsphereFailureDomain.Spec.Topology.StoragePolicy != "" { + vm.Spec.StoragePolicyName = vsphereFailureDomain.Spec.Topology.StoragePolicy + } if vsphereFailureDomain.Spec.Topology.Datastore != "" { vm.Spec.Datastore = vsphereFailureDomain.Spec.Topology.Datastore }