Skip to content
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pkg/clusterapi/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ func (c *system) Run(ctx context.Context) error { //nolint:gocyclo
c.getInfrastructureController(
&VSphere,
[]string{
"-v=2",
"-v=5",
"--diagnostics-address=0",
"--health-addr={{suggestHealthHostPort}}",
"--webhook-port={{.WebhookPort}}",
Expand Down
56 changes: 56 additions & 0 deletions pkg/infrastructure/vsphere/clusterapi/clusterapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"path"
"strings"

"github.com/sirupsen/logrus"
"github.com/vmware/govmomi/object"
"sigs.k8s.io/cluster-api-provider-vsphere/apis/v1beta1"
"sigs.k8s.io/cluster-api-provider-vsphere/pkg/session"
Expand All @@ -23,6 +24,8 @@ type Provider struct {

var _ clusterapi.PreProvider = (*Provider)(nil)

//var _ clusterapi.PostProvider = (*Provider)(nil)

// Name returns the vsphere provider name.
func (p Provider) Name() string {
return vsphere.Name
Expand Down Expand Up @@ -78,6 +81,59 @@ func initializeFoldersAndTemplates(ctx context.Context, cachedImage string, fail
return nil
}

func (p Provider) InfraReady(ctx context.Context, in clusterapi.InfraReadyInput) error {

logrus.Debug("################# IN INFRAREADY ########################")
/*
installConfig := in.InstallConfig
clusterID := &installconfig.ClusterID{InfraID: in.InfraID}

for _, vcenter := range installConfig.Config.VSphere.VCenters {
server := vcenter.Server
vctrSession, err := installConfig.VSphere.Session(context.TODO(), server)
if err != nil {
return err
}

vim25Client := vctrSession.Client.Client
for _, failureDomain := range installConfig.Config.VSphere.FailureDomains {
if failureDomain.Server != server {
continue
}

if failureDomain.ZoneType == vsphere.HostGroupFailureDomain {
vmGroupAndRuleName := fmt.Sprintf("%s-%s", clusterID.InfraID, failureDomain.Name)

err = createVMGroup(ctx, vctrSession, failureDomain.Topology.ComputeCluster, vmGroupAndRuleName)
if err != nil {
return err
}

clusterVmGroups, err := getClusterVmGroups(ctx, vim25Client, failureDomain.Topology.ComputeCluster)
if err != nil {
return err
}
var clusterVmGroup *types.ClusterVmGroup
for _, group := range clusterVmGroups {
if failureDomain.Topology.HostGroup == group.Name {
clusterVmGroup = group
}
}

if clusterVmGroup != nil {
for _, gMoRef := range clusterVmGroup.Vm {
logrus.Debugf("virtual machine %s", gMoRef.Value)
}
}
}
}
}

*/

return nil
}

// PreProvision creates the vCenter objects required prior to running capv.
func (p Provider) PreProvision(ctx context.Context, in clusterapi.PreProvisionInput) error {
/*
Expand Down
25 changes: 25 additions & 0 deletions pkg/infrastructure/vsphere/clusterapi/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,35 @@ package clusterapi
import (
"context"

"github.com/vmware/govmomi/find"
"github.com/vmware/govmomi/vim25"
"github.com/vmware/govmomi/vim25/types"
"sigs.k8s.io/cluster-api-provider-vsphere/pkg/session"
)

func getClusterVmGroups(ctx context.Context, vim25Client *vim25.Client, computeCluster string) ([]*types.ClusterVmGroup, error) {
finder := find.NewFinder(vim25Client, true)

ccr, err := finder.ClusterComputeResource(ctx, computeCluster)
if err != nil {
return nil, err
}

clusterConfig, err := ccr.Configuration(ctx)
if err != nil {
return nil, err
}

var clusterVmGroup []*types.ClusterVmGroup

for _, g := range clusterConfig.Group {
if vmg, ok := g.(*types.ClusterVmGroup); ok {
clusterVmGroup = append(clusterVmGroup, vmg)
}
}
return clusterVmGroup, nil
}

func createVMGroup(ctx context.Context, session *session.Session, cluster, vmGroup string) error {
clusterObj, err := session.Finder.ClusterComputeResource(ctx, cluster)
if err != nil {
Expand Down