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

Adjust to govmomi simulator breaking changes #3219

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module sigs.k8s.io/vsphere-csi-driver/v3

go 1.22.8
go 1.23.0

require (
github.com/agiledragon/gomonkey/v2 v2.3.1
Expand All @@ -23,10 +23,10 @@ require (
github.com/stretchr/testify v1.10.0
github.com/vmware-tanzu/vm-operator/api v0.0.0-20241108223224-20f977201370
github.com/vmware-tanzu/vm-operator/external/byok v0.0.0-20241108223224-20f977201370
github.com/vmware/govmomi v0.48.0
github.com/vmware/govmomi v0.49.0
go.uber.org/zap v1.26.0
golang.org/x/crypto v0.31.0
golang.org/x/sync v0.10.0
golang.org/x/sync v0.12.0
golang.org/x/sys v0.28.0
google.golang.org/grpc v1.67.1
google.golang.org/protobuf v1.34.2
Expand Down Expand Up @@ -98,7 +98,7 @@ require (
github.com/google/btree v1.0.1 // indirect
github.com/google/cadvisor v0.49.0 // indirect
github.com/google/cel-go v0.20.1 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20240525223248-4bfdf5a9a2af // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
Expand Down Expand Up @@ -166,7 +166,7 @@ require (
golang.org/x/net v0.33.0 // indirect
golang.org/x/oauth2 v0.22.0 // indirect
golang.org/x/term v0.27.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/text v0.23.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
Expand Down
15 changes: 8 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,9 @@ github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
Expand Down Expand Up @@ -509,8 +510,8 @@ github.com/vmware-tanzu/vm-operator/api v0.0.0-20241108223224-20f977201370 h1:+5
github.com/vmware-tanzu/vm-operator/api v0.0.0-20241108223224-20f977201370/go.mod h1:V0JbH4beGCU+q7yqnWUYYOuDij0ut5i1iBO4cyzg+tM=
github.com/vmware-tanzu/vm-operator/external/byok v0.0.0-20241108223224-20f977201370 h1:XYJD5bIAMJJ7n2sTpXd0BvIwzebXMo53zcNG3AT7Wqo=
github.com/vmware-tanzu/vm-operator/external/byok v0.0.0-20241108223224-20f977201370/go.mod h1:mAGA/R19pPESFFsIP98hu1fOmTu1hwTk8MikZJTSdH0=
github.com/vmware/govmomi v0.48.0 h1:CP5bCvkDNGkmn29UlcJKTWMLwDg3iusP8anrZnedWrg=
github.com/vmware/govmomi v0.48.0/go.mod h1:bYwUHpGpisE4AOlDl5eph90T+cjJMIcKx/kaa5v5rQM=
github.com/vmware/govmomi v0.49.0 h1:M80ExmFq3kOfeMvMJcHnXgA/4w5hUAFfYfc+Qm3lmPg=
github.com/vmware/govmomi v0.49.0/go.mod h1:+oZ0tYJw/pXKoeWHLR9Egq5KENVr2hLePRzisFhEWpA=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8=
Expand Down Expand Up @@ -676,8 +677,8 @@ golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw=
golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down Expand Up @@ -773,8 +774,8 @@ golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
Expand Down
6 changes: 3 additions & 3 deletions pkg/common/cns-lib/vsphere/virtualmachine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func getClientFromVCSimAndAttachTags(t *testing.T) {
}

// Add region tag to the datacenter
dcMoRef := simulator.Map.Any("Datacenter").(*simulator.Datacenter).Reference()
dcMoRef := model.Map().Any("Datacenter").(*simulator.Datacenter).Reference()
err = AttachTag(ctx, regionTagId, dcMoRef, tagManager)
if err != nil {
t.Fatalf("Error adding region tag to datacenter, err: %v", err)
Expand All @@ -117,7 +117,7 @@ func getClientFromVCSimAndAttachTags(t *testing.T) {
}

// Add zone tag to the cluster
clusterMoRef := simulator.Map.Any("ClusterComputeResource").(*simulator.ClusterComputeResource).Reference()
clusterMoRef := model.Map().Any("ClusterComputeResource").(*simulator.ClusterComputeResource).Reference()
err = AttachTag(ctx, zoneTagId, clusterMoRef, tagManager)
if err != nil {
t.Fatalf("Error adding region tag to datacenter, err: %v", err)
Expand All @@ -128,7 +128,7 @@ func getClientFromVCSimAndAttachTags(t *testing.T) {
dc := &Datacenter{
Datacenter: dcobj,
}
obj := simulator.Map.Any("VirtualMachine").(*simulator.VirtualMachine)
obj := model.Map().Any("VirtualMachine").(*simulator.VirtualMachine)
vm = &VirtualMachine{
Datacenter: dc,
VirtualMachine: object.NewVirtualMachine(client.Client, obj.Reference()),
Expand Down
22 changes: 16 additions & 6 deletions pkg/csi/service/vanilla/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ import (
"github.com/google/uuid"
"github.com/vmware/govmomi/cns"
cnstypes "github.com/vmware/govmomi/cns/types"
"github.com/vmware/govmomi/find"
"github.com/vmware/govmomi/pbm"
"github.com/vmware/govmomi/pbm/types"
"github.com/vmware/govmomi/vim25"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/vmware/govmomi/simulator"
clientset "k8s.io/client-go/kubernetes"
testclient "k8s.io/client-go/kubernetes/fake"

Expand Down Expand Up @@ -75,6 +76,7 @@ type controllerTest struct {
type FakeNodeManager struct {
cnsNodeManager node.Manager
k8sClient clientset.Interface
vimClient *vim25.Client
}

type FakeAuthManager struct {
Expand All @@ -86,12 +88,14 @@ func (f *FakeNodeManager) Initialize(ctx context.Context) error {
f.cnsNodeManager.SetKubernetesClient(f.k8sClient)
var t *testing.T

objVMs := simulator.Map.All("VirtualMachine")
objVMs, err := find.NewFinder(f.vimClient).VirtualMachineList(ctx, "*")
if err != nil {
return err
}
var i int
for _, vm := range objVMs {
i++
obj := vm.(*simulator.VirtualMachine)
nodeUUID := obj.Config.Uuid
nodeUUID := vm.UUID(ctx)
nodeName := "k8s-node-" + strconv.Itoa(i)
err := f.cnsNodeManager.RegisterNode(ctx, nodeUUID, nodeName)
if err != nil {
Expand Down Expand Up @@ -241,7 +245,9 @@ func getControllerTest(t *testing.T) *controllerTest {
}

nodeManager := &FakeNodeManager{
k8sClient: k8sClient}
k8sClient: k8sClient,
vimClient: vcenter.Client.Client,
}
err = nodeManager.Initialize(ctx)
if err != nil {
t.Fatalf("Failed to initialize node manager, err = %v", err)
Expand Down Expand Up @@ -903,7 +909,11 @@ func TestCompleteControllerFlow(t *testing.T) {
if v := os.Getenv("VSPHERE_K8S_NODE"); v != "" {
NodeID = v
} else {
NodeID = simulator.Map.Any("VirtualMachine").(*simulator.VirtualMachine).Config.Uuid
vms, err := find.NewFinder(ct.vcenter.Client.Client).VirtualMachineList(ctx, "*")
if err != nil {
t.Fatal(err)
}
NodeID = vms[0].UUID(ctx)
}

// Attach.
Expand Down
50 changes: 42 additions & 8 deletions pkg/csi/service/vanilla/controller_topology_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ import (
"github.com/google/uuid"
cnstypes "github.com/vmware/govmomi/cns/types"
"github.com/vmware/govmomi/find"
"github.com/vmware/govmomi/view"
"github.com/vmware/govmomi/vim25"
"github.com/vmware/govmomi/vim25/mo"
"k8s.io/apimachinery/pkg/util/wait"

"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/vmware/govmomi/simulator"
clientset "k8s.io/client-go/kubernetes"
testclient "k8s.io/client-go/kubernetes/fake"

Expand Down Expand Up @@ -68,6 +70,32 @@ type FakeTopologyManager struct {
type FakeNodeManagerTopology struct {
cnsNodeManager node.Manager
k8sClient clientset.Interface
vimClient *vim25.Client
}

func getAllManagedObjects(ctx context.Context, client *vim25.Client, kind string, prop []string, dst any) error {
m := view.NewManager(client)

v, err := m.CreateContainerView(ctx, client.ServiceContent.RootFolder, []string{kind}, true)
if err != nil {
return err
}

defer v.Destroy(ctx)

return v.Retrieve(ctx, []string{kind}, prop, dst)
}

func getAllVirtualMachines(ctx context.Context, client *vim25.Client, props ...string) ([]mo.VirtualMachine, error) {
var vms []mo.VirtualMachine
err := getAllManagedObjects(ctx, client, "VirtualMachine", props, &vms)
if err != nil {
return nil, err
}
if len(vms) == 0 {
return nil, fmt.Errorf("no VirtualMachines found")
}
return vms, nil
}

func (f *FakeNodeManagerTopology) Initialize(ctx context.Context) error {
Expand All @@ -83,12 +111,14 @@ func (f *FakeNodeManagerTopology) Initialize(ctx context.Context) error {
t.Errorf("Error occurred while unregistering all nodes, err: %v", err)
}

objVMs := simulator.Map.All("VirtualMachine")
objVMs, err := getAllVirtualMachines(ctx, f.vimClient, "config.uuid")
if err != nil {
return err
}
var i int
for _, vm := range objVMs {
i++
obj := vm.(*simulator.VirtualMachine)
nodeUUID := obj.Config.Uuid
nodeUUID := vm.Config.Uuid
nodeName := "k8s-node-" + strconv.Itoa(i)
// Register new node entry in nodeManager
err := f.cnsNodeManager.RegisterNode(ctx, nodeUUID, nodeName)
Expand Down Expand Up @@ -141,11 +171,13 @@ func generateNodeLabels(ctx context.Context, vc *cnsvsphere.VirtualCenter) (map[
var i int

finder := find.NewFinder(vc.Client.Client, false)
objDCs := simulator.Map.All("Datacenter")
objDCs, err := finder.DatacenterList(ctx, "*")
if err != nil {
return nil, err
}
for _, dc := range objDCs {
i++
dcref := dc.(*simulator.Datacenter)
dcname := dcref.Name
dcname := dc.Name()
fmt.Printf("generateNodeLabels for datacenter=%s\n", dcname)
datacenter, err := finder.Datacenter(ctx, dcname)
if err != nil {
Expand Down Expand Up @@ -419,7 +451,9 @@ func getControllerTestWithTopology(t *testing.T) *controllerTestTopology {
}

nodeManager := &FakeNodeManagerTopology{
k8sClient: k8sClient}
k8sClient: k8sClient,
vimClient: vcenter.Client.Client,
}
err = nodeManager.Initialize(ctxtopology)
if err != nil {
t.Fatalf("Failed to initialize the node manager, err= =%v", err)
Expand Down
11 changes: 7 additions & 4 deletions pkg/csi/service/wcp/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import (

"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/google/uuid"
"github.com/vmware/govmomi/find"
"github.com/vmware/govmomi/pbm"
"github.com/vmware/govmomi/simulator"
v1 "k8s.io/api/core/v1"

cnstypes "github.com/vmware/govmomi/cns/types"
Expand Down Expand Up @@ -83,9 +83,6 @@ func getControllerTest(t *testing.T) *controllerTest {
// CNS based CSI requires a valid cluster name.
config.Global.ClusterID = testClusterName

clusterMoRef := simulator.Map.Any("ClusterComputeResource").(*simulator.ClusterComputeResource).Reference()
clusterComputeResourceMoIds = append(clusterComputeResourceMoIds, clusterMoRef.Value)

vcenterconfig, err := cnsvsphere.GetVirtualCenterConfig(ctx, config)
if err != nil {
t.Fatal(err)
Expand All @@ -101,6 +98,12 @@ func getControllerTest(t *testing.T) *controllerTest {
t.Fatal(err)
}

clusters, err := find.NewFinder(vcenter.Client.Client).ClusterComputeResourceList(ctx, "*")
if err != nil {
t.Fatal(err)
}
clusterComputeResourceMoIds = append(clusterComputeResourceMoIds, clusters[0].Reference().Value)

fakeOpStore, err := unittestcommon.InitFakeVolumeOperationRequestInterface()
if err != nil {
t.Fatal(err)
Expand Down
14 changes: 12 additions & 2 deletions pkg/syncer/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import (
"github.com/davecgh/go-spew/spew"
"github.com/google/uuid"
cnstypes "github.com/vmware/govmomi/cns/types"
"github.com/vmware/govmomi/simulator"
"github.com/vmware/govmomi/find"
"github.com/vmware/govmomi/vim25/mo"
vimtypes "github.com/vmware/govmomi/vim25/types"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down Expand Up @@ -185,7 +186,16 @@ func TestSyncerWorkflows(t *testing.T) {
if v := os.Getenv("VSPHERE_DATASTORE_URL"); v != "" {
sharedDatastore = v
} else {
sharedDatastore = simulator.Map.Any("Datastore").(*simulator.Datastore).Info.GetDatastoreInfo().Url
datastores, err := find.NewFinder(virtualCenter.Client.Client).DatastoreList(ctx, "*")
if err != nil {
t.Fatalf("failed to get datastores. Err: %v", err)
}
var ds mo.Datastore
err = virtualCenter.Client.RetrieveOne(ctx, datastores[0].Reference(), []string{"info"}, &ds)
if err != nil {
t.Fatalf("failed to get datastore info. Err: %v", err)
}
sharedDatastore = ds.Info.GetDatastoreInfo().Url
}
dc, err = virtualCenter.GetDatacenters(ctx)
if err != nil || len(dc) == 0 {
Expand Down