Skip to content

Commit

Permalink
VCD: Fix compute and sizing policies (#1687)
Browse files Browse the repository at this point in the history
Signed-off-by: Waleed Malik <ahmedwaleedmalik@gmail.com>
Co-authored-by: Waleed Malik <ahmedwaleedmalik@gmail.com>
  • Loading branch information
kubermatic-bot and ahmedwaleedmalik committed Jul 21, 2023
1 parent 97b3526 commit bea09e1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
6 changes: 6 additions & 0 deletions examples/vmware-cloud-director-machinedeployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ spec:
diskBusType: "paravirtual"
diskIOPS: 0
storageProfile: "*"
# Optional: SizingPolicy is the sizing policy to be used for machines created by this machine deployment.
# If left empty, default sizing policy if specified at OVDC/organization level is used.
sizingPolicy: ""
# Optional: PlacementPolicy is the placement policy to be used for machines created by this machine deployment.
# If left empty, default placement policy if specified at OVDC/organization level is used.
placementPolicy: ""
operatingSystem: "ubuntu"
operatingSystemSpec:
distUpgradeOnBoot: false
Expand Down
26 changes: 12 additions & 14 deletions pkg/cloudprovider/provider/vmwareclouddirector/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func createVM(client *Client, machine *clusterv1alpha1.Machine, c *Config, org *
}

// 2. Retrieve Sizing and Placement Compute Policy if required.
computePolicy := vcdapitypes.ComputePolicy{}
var computePolicy *types.ComputePolicy
if c.SizingPolicy != nil || c.PlacementPolicy != nil {
allPolicies, err := org.GetAllVdcComputePolicies(url.Values{})
if err != nil {
Expand All @@ -89,6 +89,9 @@ func createVM(client *Client, machine *clusterv1alpha1.Machine, c *Config, org *
if sizingPolicy == nil {
return fmt.Errorf("sizing policy '%s' doesn't exist", *c.SizingPolicy)
}
if computePolicy == nil {
computePolicy = &types.ComputePolicy{}
}
computePolicy.VmSizingPolicy = &vcdapitypes.Reference{
HREF: sizingPolicy.VdcComputePolicy.ID,
}
Expand All @@ -99,22 +102,25 @@ func createVM(client *Client, machine *clusterv1alpha1.Machine, c *Config, org *
if placementPolicy == nil {
return fmt.Errorf("placement policy '%s' doesn't exist", *c.PlacementPolicy)
}
if computePolicy == nil {
computePolicy = &types.ComputePolicy{}
}
computePolicy.VmPlacementPolicy = &vcdapitypes.Reference{
HREF: placementPolicy.VdcComputePolicy.ID,
}
}
}

// 3. Retrieve Storage Profile
storageProfileRef := vcdapitypes.Reference{}
var storageProfile *types.Reference
if c.StorageProfile != nil && *c.StorageProfile != defaultStorageProfile {
for _, sp := range vdc.Vdc.VdcStorageProfiles.VdcStorageProfile {
if sp.Name == *c.StorageProfile || sp.ID == *c.StorageProfile {
storageProfileRef = vcdapitypes.Reference{HREF: sp.HREF, Name: sp.Name, ID: sp.ID}
storageProfile = sp
break
}
}
if storageProfileRef.HREF == "" {
if storageProfile == nil {
if err != nil {
return fmt.Errorf("failed to get storage profile '%s': %w", *c.StorageProfile, err)
}
Expand Down Expand Up @@ -154,20 +160,12 @@ func createVM(client *Client, machine *clusterv1alpha1.Machine, c *Config, org *
},
},
},
StorageProfile: storageProfile,
ComputePolicy: computePolicy,
},
AllEULAsAccepted: true,
}

// Add storage profile
if storageProfileRef.HREF != "" {
vAppRecomposition.SourcedItem.StorageProfile = &storageProfileRef
}

// Add compute policy
if computePolicy.HREF != "" {
vAppRecomposition.SourcedItem.ComputePolicy = &computePolicy
}

apiEndpoint, err := url.Parse(vapp.VApp.HREF)
if err != nil {
return fmt.Errorf("error getting vapp href '%s': %w", c.Auth.URL, err)
Expand Down
2 changes: 2 additions & 0 deletions pkg/cloudprovider/provider/vmwareclouddirector/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@ func (p *provider) getConfig(provSpec clusterv1alpha1.ProviderSpec) (*Config, *p
c.DiskBusType = rawConfig.DiskBusType
c.StorageProfile = rawConfig.StorageProfile
c.Metadata = rawConfig.Metadata
c.SizingPolicy = rawConfig.SizingPolicy
c.PlacementPolicy = rawConfig.PlacementPolicy
return &c, pconfig, rawConfig, err
}

Expand Down

0 comments on commit bea09e1

Please sign in to comment.