Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-1.7] 🐛 Fix datastore selection based on StoragePolicy #1999

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion pkg/services/govmomi/vcenter/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/vmware/govmomi/object"
"github.com/vmware/govmomi/pbm"
pbmTypes "github.com/vmware/govmomi/pbm/types"
"github.com/vmware/govmomi/view"
"github.com/vmware/govmomi/vim25/mo"
"github.com/vmware/govmomi/vim25/types"
"k8s.io/utils/pointer"
Expand Down Expand Up @@ -223,9 +224,32 @@ func Clone(ctx *context.VMContext, bootstrapData []byte, format bootstrapv1.Form
return errors.Wrapf(err, "unable to get storageProfileID from name %s for %q", ctx.VSphereVM.Spec.StoragePolicyName, ctx)
}

kind := []string{"Datastore"}
m := view.NewManager(ctx.Session.Client.Client)

v, err := m.CreateContainerView(ctx, ctx.Session.Client.Client.ServiceContent.RootFolder, kind, true)
if err != nil {
return errors.Wrapf(err, "unable to create container view for Datastore for %q", ctx)
}

var content []types.ObjectContent
err = v.Retrieve(ctx, kind, []string{"name"}, &content)
_ = v.Destroy(ctx)
if err != nil {
return errors.Wrapf(err, "unable to retrieve container view for Datastore for %q", ctx)
}

var hubs []pbmTypes.PbmPlacementHub
for _, ds := range content {
hubs = append(hubs, pbmTypes.PbmPlacementHub{
HubType: ds.Obj.Type,
HubId: ds.Obj.Value,
})
}

var constraints []pbmTypes.BasePbmPlacementRequirement
constraints = append(constraints, &pbmTypes.PbmPlacementCapabilityProfileRequirement{ProfileId: pbmTypes.PbmProfileId{UniqueId: storageProfileID}})
result, err := pbmClient.CheckRequirements(ctx, nil, nil, constraints)
result, err := pbmClient.CheckRequirements(ctx, hubs, nil, constraints)
if err != nil {
return errors.Wrapf(err, "unable to check requirements for storage policy")
}
Expand Down