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

(wip) Update vm-operator spec to v1alpha2 #2831

Closed
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 go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/pkg/sftp v1.13.6
github.com/prometheus/client_golang v1.18.0
github.com/stretchr/testify v1.9.0
github.com/vmware-tanzu/vm-operator/api v1.8.2
github.com/vmware-tanzu/vm-operator/api v1.8.5
github.com/vmware/govmomi v0.36.1
go.uber.org/zap v1.26.0
golang.org/x/crypto v0.18.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1296,8 +1296,8 @@ github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYp
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU=
github.com/vishvananda/netns v0.0.2 h1:Cn05BRLm+iRP/DZxyVSsfVyrzgjDbwHwkVt38qvXnNI=
github.com/vishvananda/netns v0.0.2/go.mod h1:yitZXdAVI+yPFSb4QUe+VW3vOVl4PZPNcBgbPxAtJxw=
github.com/vmware-tanzu/vm-operator/api v1.8.2 h1:7cZHVusqAmAMFWvsiU7X5xontxdjasknI/sVfe0p0Z4=
github.com/vmware-tanzu/vm-operator/api v1.8.2/go.mod h1:vauVboD3sQxP+pb28TnI9wfrj+0nH2zSEc9Q7AzWJ54=
github.com/vmware-tanzu/vm-operator/api v1.8.5 h1:E8rpRdV8+cNp/eNZ/QUHvlrbpPh8uk6bKqwEEmGWe64=
github.com/vmware-tanzu/vm-operator/api v1.8.5/go.mod h1:SXaSFtnw2502Tzy0bfQVHrvbFDijR96r1ihUYQWPOK8=
github.com/vmware/govmomi v0.36.1 h1:+E/nlfteQ8JvC0xhuKAfpnMsuIeGeGj7rJwqENUcWm8=
github.com/vmware/govmomi v0.36.1/go.mod h1:mtGWtM+YhTADHlCgJBiskSRPOZRsN9MSjPzaZLte/oQ=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
Expand Down
2 changes: 1 addition & 1 deletion pkg/csi/service/wcp/controller_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"strings"

"github.com/container-storage-interface/spec/lib/go/csi"
vmoperatorv1alpha1 "github.com/vmware-tanzu/vm-operator/api/v1alpha1"
vmoperatorv1alpha1 "github.com/vmware-tanzu/vm-operator/api/v1alpha2"
"github.com/vmware/govmomi/object"
"github.com/vmware/govmomi/property"
"github.com/vmware/govmomi/vim25/mo"
Expand Down
25 changes: 13 additions & 12 deletions pkg/csi/service/wcpguest/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"github.com/fsnotify/fsnotify"
snapshotterClientSet "github.com/kubernetes-csi/external-snapshotter/client/v6/clientset/versioned"
"github.com/prometheus/client_golang/prometheus/promhttp"
vmoperatortypes "github.com/vmware-tanzu/vm-operator/api/v1alpha1"
vmoperatortypes "github.com/vmware-tanzu/vm-operator/api/v1alpha2"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/timestamppb"
Expand Down Expand Up @@ -630,11 +630,12 @@ func controllerPublishForBlockVolume(ctx context.Context, req *csi.ControllerPub
// volume in the spec and patching virtualMachine instance.
vmvolumes := vmoperatortypes.VirtualMachineVolume{
Name: req.VolumeId,
PersistentVolumeClaim: &vmoperatortypes.PersistentVolumeClaimVolumeSource{
PersistentVolumeClaimVolumeSource: corev1.PersistentVolumeClaimVolumeSource{
ClaimName: req.VolumeId,
},
},
VirtualMachineVolumeSource: vmoperatortypes.VirtualMachineVolumeSource{
PersistentVolumeClaim: &vmoperatortypes.PersistentVolumeClaimVolumeSource{
PersistentVolumeClaimVolumeSource: corev1.PersistentVolumeClaimVolumeSource{
ClaimName: req.VolumeId,
},
}},
}
virtualMachine.Spec.Volumes = append(virtualMachine.Spec.Volumes, vmvolumes)

Expand All @@ -653,11 +654,11 @@ func controllerPublishForBlockVolume(ctx context.Context, req *csi.ControllerPub
}

for _, volume := range virtualMachine.Status.Volumes {
if volume.Name == req.VolumeId && volume.Attached && volume.DiskUuid != "" {
diskUUID = volume.DiskUuid
if volume.Name == req.VolumeId && volume.Attached && volume.DiskUUID != "" {
diskUUID = volume.DiskUUID
isVolumeAttached = true
log.Infof("Volume %q is already attached in the virtualMachine.Spec.Volumes. Disk UUID: %q",
volume.Name, volume.DiskUuid)
volume.Name, volume.DiskUUID)
break
}
}
Expand Down Expand Up @@ -695,10 +696,10 @@ func controllerPublishForBlockVolume(ctx context.Context, req *csi.ControllerPub
virtualMachine.Name, req.VolumeId)
for _, volume := range vm.Status.Volumes {
if volume.Name == req.VolumeId {
if volume.Attached && volume.DiskUuid != "" && volume.Error == "" {
diskUUID = volume.DiskUuid
if volume.Attached && volume.DiskUUID != "" && volume.Error == "" {
diskUUID = volume.DiskUUID
log.Infof("observed disk UUID %q is set for the volume %q on virtualmachine %q",
volume.DiskUuid, volume.Name, vm.Name)
volume.DiskUUID, volume.Name, vm.Name)
} else {
if volume.Error != "" {
msg := fmt.Sprintf("observed Error: %q is set on the volume %q on virtualmachine %q",
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"strconv"
"time"

vmoperatorv1alpha1 "github.com/vmware-tanzu/vm-operator/api/v1alpha1"
vmoperatorv1alpha1 "github.com/vmware-tanzu/vm-operator/api/v1alpha2"
v1 "k8s.io/api/core/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apiextensionsclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"sync"
"time"

vmoperatortypes "github.com/vmware-tanzu/vm-operator/api/v1alpha1"
vmoperatortypes "github.com/vmware-tanzu/vm-operator/api/v1alpha2"
cnstypes "github.com/vmware/govmomi/cns/types"
v1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -41,6 +41,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/source"

vsanfstypes "github.com/vmware/govmomi/vsan/vsanfs/types"

cnsoperatorapis "sigs.k8s.io/vsphere-csi-driver/v3/pkg/apis/cnsoperator"
cnsfileaccessconfigv1alpha1 "sigs.k8s.io/vsphere-csi-driver/v3/pkg/apis/cnsoperator/cnsfileaccessconfig/v1alpha1"
volumes "sigs.k8s.io/vsphere-csi-driver/v3/pkg/common/cns-lib/volume"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ import (
"reflect"
"strconv"

vmoperatortypes "github.com/vmware-tanzu/vm-operator/api/v1alpha1"
vmoperatortypes "github.com/vmware-tanzu/vm-operator/api/v1alpha2"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
apitypes "k8s.io/apimachinery/pkg/types"

"sigs.k8s.io/controller-runtime/pkg/client"

cnsfileaccessconfigv1alpha1 "sigs.k8s.io/vsphere-csi-driver/v3/pkg/apis/cnsoperator/cnsfileaccessconfig/v1alpha1"
"sigs.k8s.io/vsphere-csi-driver/v3/pkg/csi/service/logger"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"sync"
"time"

vmoperatortypes "github.com/vmware-tanzu/vm-operator/api/v1alpha1"
vmoperatortypes "github.com/vmware-tanzu/vm-operator/api/v1alpha2"
cnstypes "github.com/vmware/govmomi/cns/types"
"github.com/vmware/govmomi/object"
vimtypes "github.com/vmware/govmomi/vim25/types"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"sync"
"time"

vmoperatortypes "github.com/vmware-tanzu/vm-operator/api/v1alpha1"
vmoperatortypes "github.com/vmware-tanzu/vm-operator/api/v1alpha2"
cnstypes "github.com/vmware/govmomi/cns/types"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

"github.com/google/uuid"
"github.com/stretchr/testify/assert"
vmoperatortypes "github.com/vmware-tanzu/vm-operator/api/v1alpha1"
vmoperatortypes "github.com/vmware-tanzu/vm-operator/api/v1alpha2"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down
27 changes: 22 additions & 5 deletions pkg/syncer/cnsoperator/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"context"
"fmt"

vmoperatortypes "github.com/vmware-tanzu/vm-operator/api/v1alpha1"
vmoperatortypes "github.com/vmware-tanzu/vm-operator/api/v1alpha2"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand Down Expand Up @@ -98,11 +98,23 @@ func GetTKGVMIP(ctx context.Context, vmOperatorClient client.Client, dc dynamic.
}

var networkName string
for _, networkInterface := range virtualMachineInstance.Spec.NetworkInterfaces {

// NSX
// network:
// interfaces:
// - name: eth0
// network:
// apiVersion: vmware.com/v1alpha1
// kind: VirtualNetwork
// name: <>
// virtualnetwork object: network.interfaces.network.name <> in the above spec
// networkinterfaces object: vm-medium-1-ltw8-vnet

for _, networkInterface := range virtualMachineInstance.Spec.Network.Interfaces {
// The assumption is that a TKG VM will have only a single network interface.
// This logic needs to be revisited when multiple network interface support
// is added.
networkName = networkInterface.NetworkName
networkName = networkInterface.Network.Name
}
log.Debugf("VirtualMachine %s/%s is configured with network %s", vmNamespace, vmName, networkName)

Expand All @@ -121,9 +133,14 @@ func GetTKGVMIP(ctx context.Context, vmOperatorClient client.Client, dc dynamic.
return "", fmt.Errorf("failed to get SNAT IP annotation from VirtualMachine %s/%s", vmNamespace, vmName)
}
} else {
ip = virtualMachineInstance.Status.VmIp
networkStatus := virtualMachineInstance.Status.Network
if networkStatus == nil {
return "", fmt.Errorf("vm.Status.Network is not populated for %s/%s", vmNamespace, vmName)
}

ip = networkStatus.PrimaryIP4
if ip == "" {
return "", fmt.Errorf("vm.Status.VmIp is not populated for %s/%s", vmNamespace, vmName)
return "", fmt.Errorf("vm.Status.Network.PrimaryIP4 is not populated for %s/%s", vmNamespace, vmName)
}
}
log.Infof("Found external IP Address %s for VirtualMachine %s/%s", ip, vmNamespace, vmName)
Expand Down
41 changes: 29 additions & 12 deletions tests/e2e/vmservice_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ import (

"github.com/onsi/gomega"
"github.com/pkg/sftp"
"github.com/vmware-tanzu/vm-operator/api/v1alpha2/common"
"golang.org/x/crypto/ssh"

vmopv1 "github.com/vmware-tanzu/vm-operator/api/v1alpha1"
vmopv1 "github.com/vmware-tanzu/vm-operator/api/v1alpha2"
v1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -43,6 +44,7 @@ import (
"k8s.io/kubernetes/test/e2e/framework"
fssh "k8s.io/kubernetes/test/e2e/framework/ssh"
ctlrclient "sigs.k8s.io/controller-runtime/pkg/client"

cnsnodevmattachmentv1alpha1 "sigs.k8s.io/vsphere-csi-driver/v3/pkg/apis/cnsoperator/cnsnodevmattachment/v1alpha1"
)

Expand Down Expand Up @@ -256,7 +258,7 @@ func waitNGetVmiForImageName(ctx context.Context, c ctlrclient.Client, namespace
err := c.List(ctx, vmImagesList)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
for _, instance := range vmImagesList.Items {
if instance.Status.ImageName == imageName {
if instance.Status.Name == imageName {
framework.Logf("Found vmi %v for image name %v", instance.Name, imageName)
vmi = instance.Name
return true, nil
Expand All @@ -278,20 +280,27 @@ func createVmServiceVmWithPvcs(ctx context.Context, c ctlrclient.Client, namespa
for _, pvc := range pvcs {
vols = append(vols, vmopv1.VirtualMachineVolume{
Name: pvc.Name,
PersistentVolumeClaim: &vmopv1.PersistentVolumeClaimVolumeSource{
PersistentVolumeClaimVolumeSource: v1.PersistentVolumeClaimVolumeSource{ClaimName: pvc.Name},
VirtualMachineVolumeSource: vmopv1.VirtualMachineVolumeSource{
PersistentVolumeClaim: &vmopv1.PersistentVolumeClaimVolumeSource{
PersistentVolumeClaimVolumeSource: v1.PersistentVolumeClaimVolumeSource{ClaimName: pvc.Name},
},
},
})
}
vm := vmopv1.VirtualMachine{
ObjectMeta: metav1.ObjectMeta{Name: vmName, Namespace: namespace},
Spec: vmopv1.VirtualMachineSpec{
PowerState: vmopv1.VirtualMachinePoweredOn,
PowerState: vmopv1.VirtualMachinePowerStateOn,
ImageName: vmi,
ClassName: vmClass,
StorageClass: storageClassName,
Volumes: vols,
VmMetadata: &vmopv1.VirtualMachineMetadata{Transport: "CloudInit", SecretName: secretName},
Bootstrap: &vmopv1.VirtualMachineBootstrapSpec{CloudInit: &vmopv1.VirtualMachineBootstrapCloudInitSpec{
RawCloudConfig: &common.SecretKeySelector{
Name: secretName,
Key: "user-data",
},
}},
},
}
err := c.Create(ctx, &vm)
Expand Down Expand Up @@ -341,10 +350,11 @@ func waitNgetVmsvcVmIp(ctx context.Context, c ctlrclient.Client, namespace strin
}
return false, nil
}
if vm.Status.VmIp == "" {
networkStatus := vm.Status.Network
if networkStatus == nil || networkStatus.PrimaryIP4 == "" {
return false, nil
}
ip = vm.Status.VmIp
ip = networkStatus.PrimaryIP4
return true, nil
})
framework.Logf("Found IP '%s' for VM '%s'", ip, name)
Expand Down Expand Up @@ -746,8 +756,10 @@ func createVmServiceVmWithPvcsWithZone(ctx context.Context, c ctlrclient.Client,
for _, pvc := range pvcs {
vols = append(vols, vmopv1.VirtualMachineVolume{
Name: pvc.Name,
PersistentVolumeClaim: &vmopv1.PersistentVolumeClaimVolumeSource{
PersistentVolumeClaimVolumeSource: v1.PersistentVolumeClaimVolumeSource{ClaimName: pvc.Name},
VirtualMachineVolumeSource: vmopv1.VirtualMachineVolumeSource{
PersistentVolumeClaim: &vmopv1.PersistentVolumeClaimVolumeSource{
PersistentVolumeClaimVolumeSource: v1.PersistentVolumeClaimVolumeSource{ClaimName: pvc.Name},
},
},
})
}
Expand All @@ -756,12 +768,17 @@ func createVmServiceVmWithPvcsWithZone(ctx context.Context, c ctlrclient.Client,
vm := vmopv1.VirtualMachine{
ObjectMeta: metav1.ObjectMeta{Name: vmName, Namespace: namespace, Labels: labels},
Spec: vmopv1.VirtualMachineSpec{
PowerState: vmopv1.VirtualMachinePoweredOn,
PowerState: vmopv1.VirtualMachinePowerStateOn,
ImageName: vmi,
ClassName: vmClass,
StorageClass: storageClassName,
Volumes: vols,
VmMetadata: &vmopv1.VirtualMachineMetadata{Transport: "CloudInit", SecretName: secretName},
Bootstrap: &vmopv1.VirtualMachineBootstrapSpec{CloudInit: &vmopv1.VirtualMachineBootstrapCloudInitSpec{
RawCloudConfig: &common.SecretKeySelector{
Name: secretName,
Key: "user-data",
},
}},
},
}
err := c.Create(ctx, &vm)
Expand Down
Loading