Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

// DiskMode describes the desired mode to use when attaching the volume.
// +kubebuilder:validation:Enum=independent_persistent;persistent;independent_nonpersistent
// +kubebuilder:validation:Enum=independent_persistent;persistent;independent_nonpersistent;nonpersistent
type DiskMode string

const (
Expand All @@ -34,6 +34,8 @@ const (
// and discarded at power off.
// It is not affected by snapshots.
IndependentNonPersistent = "independent_nonpersistent"
// Changes to virtual disk are made to a redo log and discarded at power off.
NonPersistent = "nonpersistent"
)

// SharingMode is the sharing mode of the virtual disk.
Expand All @@ -52,9 +54,9 @@ const (
type CnsNodeVMBatchAttachmentSpec struct {
// +required

// NodeUUID indicates the UUID of the node where the volume needs to be attached to.
// Here NodeUUID is the instance UUID of the node.
NodeUUID string `json:"nodeUUID"`
// InstanceUUID indicates the instance UUID of the node where the volume needs to be attached to.
InstanceUUID string `json:"instanceUUID"`
// +required

// +listType=map
// +listMapKey=name
Expand All @@ -63,8 +65,12 @@ type CnsNodeVMBatchAttachmentSpec struct {
}

type VolumeSpec struct {
// +required

// Name of the volume as given by the user.
Name string `json:"name"`
// +required

// PersistentVolumeClaim contains details about the volume's desired state.
PersistentVolumeClaim PersistentVolumeClaimSpec `json:"persistentVolumeClaim"`
}
Expand All @@ -74,22 +80,22 @@ type PersistentVolumeClaimSpec struct {

// ClaimName is the PVC name.
ClaimName string `json:"claimName"`
// +optional
// +required

// DiskMode is the desired mode to use when attaching the volume
DiskMode DiskMode `json:"diskMode,omitempty"`
// +optional
DiskMode DiskMode `json:"diskMode"`
// +required

// SharingMode indicates the sharing mode if the virtual disk while attaching.
SharingMode SharingMode `json:"sharingMode,omitempty"`
// +optional
SharingMode SharingMode `json:"sharingMode"`
// +required

// ControllerKey is the object key for the controller object for this device.
ControllerKey *int32 `json:"controllerKey,omitempty"`
// +optional
ControllerKey *int32 `json:"controllerKey"`
// +required

// UnitNumber of this device on its controller.
UnitNumber *int32 `json:"unitNumber,omitempty"`
UnitNumber *int32 `json:"unitNumber"`
}

// CnsNodeVMBatchAttachmentStatus defines the observed state of CnsNodeVMBatchAttachment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ spec:
description: CnsNodeVMBatchAttachmentSpec defines the desired state of
CnsNodeVMBatchAttachment
properties:
nodeUUID:
description: |-
NodeUUID indicates the UUID of the node where the volume needs to be attached to.
Here NodeUUID is the instance UUID of the node.
instanceUUID:
description: InstanceUUID indicates the instance UUID of the node
where the volume needs to be attached to.
type: string
volumes:
description: VolumeSpec reflects the desired state for each volume.
Expand Down Expand Up @@ -78,6 +77,7 @@ spec:
- independent_persistent
- persistent
- independent_nonpersistent
- nonpersistent
type: string
sharingMode:
description: SharingMode indicates the sharing mode if the
Expand All @@ -92,6 +92,10 @@ spec:
type: integer
required:
- claimName
- controllerKey
- diskMode
- sharingMode
- unitNumber
type: object
required:
- name
Expand All @@ -102,7 +106,7 @@ spec:
- name
x-kubernetes-list-type: map
required:
- nodeUUID
- instanceUUID
- volumes
type: object
status:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func (r *Reconciler) Reconcile(ctx context.Context,
// If VM is deleted from the VC but CnsNodeVMBatchAttachment is not being deleted, it is an error.
err := fmt.Errorf("virtual Machine with UUID %s on vCenter does not exist. "+
"Vm is CR is deleted or is being deleted but"+
"CnsNodeVMBatchAttachmentInstance %s is not being deleted", instance.Spec.NodeUUID, instance.Name)
"CnsNodeVMBatchAttachmentInstance %s is not being deleted", instance.Spec.InstanceUUID, instance.Name)
return r.completeReconciliationWithError(batchAttachCtx, instance, request.NamespacedName, timeout, err)
}
// If CnsNodeVMBatchAttachment is also being deleted, then all volumes on the instance can be considered detached.
Expand All @@ -295,7 +295,7 @@ func (r *Reconciler) Reconcile(ctx context.Context,
// For every PVC mentioned in instance.Spec, remove finalizer from its PVC.
for _, volume := range instance.Spec.Volumes {
err := removePvcFinalizer(ctx, r.client, k8sClient, volume.PersistentVolumeClaim.ClaimName, instance.Namespace,
instance.Spec.NodeUUID)
instance.Spec.InstanceUUID)
if err != nil {
log.Errorf("failed to remove finalizer from PVC %s. Err: %s", volume.PersistentVolumeClaim.ClaimName,
err)
Expand Down Expand Up @@ -460,7 +460,7 @@ func (r *Reconciler) detachVolumes(ctx context.Context,
instance, pvc, volumesThatFailedToDetach)
} else {
log.Errorf("failed to detach volume %s from VM %s. Fault: %s Err: %s",
pvc, instance.Spec.NodeUUID, faulttype, detachErr)
pvc, instance.Spec.InstanceUUID, faulttype, detachErr)
// Update the instance with error for this PVC.
updateInstanceWithErrorForPvc(instance, pvc, detachErr.Error())
volumesThatFailedToDetach = append(volumesThatFailedToDetach, pvc)
Expand All @@ -486,15 +486,15 @@ func removeFinalizerAndStatusEntry(ctx context.Context, client client.Client, k8
volumesThatFailedToDetach []string) []string {
log := logger.GetLogger(ctx)

err := removePvcFinalizer(ctx, client, k8sClient, pvc, instance.Namespace, instance.Spec.NodeUUID)
err := removePvcFinalizer(ctx, client, k8sClient, pvc, instance.Namespace, instance.Spec.InstanceUUID)
if err != nil {
log.Errorf("failed to remove finalizer from PVC %s. Err: %s", pvc, err)
updateInstanceWithErrorForPvc(instance, pvc, err.Error())
volumesThatFailedToDetach = append(volumesThatFailedToDetach, pvc)
} else {
// Remove entry of this volume from the instance's status.
deleteVolumeFromStatus(pvc, instance)
log.Infof("Successfully detached volume %s from VM %s", pvc, instance.Spec.NodeUUID)
log.Infof("Successfully detached volume %s from VM %s", pvc, instance.Spec.InstanceUUID)
}
return volumesThatFailedToDetach
}
Expand Down Expand Up @@ -538,7 +538,7 @@ func (r *Reconciler) processBatchAttach(ctx context.Context, k8sClient kubernete
// If attach was successful, add finalizer to the PVC.
if result.Error == nil {
// Add finalizer on PVC as attach was successful.
err = addPvcFinalizer(ctx, r.client, k8sClient, pvcName, instance.Namespace, instance.Spec.NodeUUID)
err = addPvcFinalizer(ctx, r.client, k8sClient, pvcName, instance.Namespace, instance.Spec.InstanceUUID)
if err != nil {
log.Errorf("failed to add finalizer %s on PVC %s", cnsoperatortypes.CNSPvcFinalizer, pvcName)
result.Error = err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func removeStaleEntriesFromInstanceStatus(ctx context.Context,
// This kind of situation can happen when detach is successful but finalizer could not be removed
// because of which the instance is back in queue.
err := removePvcFinalizer(ctx, client, k8sClient, volumeStatus.PersistentVolumeClaim.ClaimName, instance.Namespace,
instance.Spec.NodeUUID)
instance.Spec.InstanceUUID)
if err != nil {
log.Errorf("failed to ensure that PVC finalizers are removed.")
return err
Expand Down Expand Up @@ -452,10 +452,10 @@ func getVmObject(ctx context.Context, client client.Client, configInfo config.Co
log := logger.GetLogger(ctx)

// Get vm from vCenter.
vm, err := GetVMFromVcenter(ctx, instance.Spec.NodeUUID, configInfo)
vm, err := GetVMFromVcenter(ctx, instance.Spec.InstanceUUID, configInfo)
if err != nil {
if err == cnsvsphere.ErrVMNotFound {
log.Infof("VM %s not found on VC", instance.Spec.NodeUUID)
log.Infof("VM %s not found on VC", instance.Spec.InstanceUUID)
return nil, nil
}
return nil, err
Expand Down Expand Up @@ -507,7 +507,7 @@ func getVolumesToDetachFromVM(ctx context.Context, client client.Client,
log.Errorf("failed to find the FCDs attached to VM %s. Err: %s", vm, err)
return map[string]string{}, err
}
log.Infof("List of attached FCDs %+v to VM %s", attachedFcdList, instance.Spec.NodeUUID)
log.Infof("List of attached FCDs %+v to VM %s", attachedFcdList, instance.Spec.InstanceUUID)

// Find volumes to be detached from the VM by takinga diff with FCDs attached to VM on vCenter.
volumesToDetach, err := getVolumesToDetachForVmFromVC(ctx, instance, client, k8sClient, attachedFcdList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func setupTestCnsNodeVMBatchAttachment() v1alpha1.CnsNodeVMBatchAttachment {
ResourceVersion: "1",
},
Spec: v1alpha1.CnsNodeVMBatchAttachmentSpec{
NodeUUID: testNodeUUID,
InstanceUUID: testNodeUUID,
Volumes: []v1alpha1.VolumeSpec{
{
Name: disk1,
Expand Down Expand Up @@ -203,7 +203,7 @@ func getClientSetWithPvc() *k8sFake.Clientset {
func TestCnsNodeVMBatchAttachmentWhenVmOnVcenterReturnsError(t *testing.T) {
t.Run("TestCnsNodeVMBatchAttachmentWhenVmOnVcenterReturnsError", func(t *testing.T) {
testCnsNodeVMBatchAttachment := setupTestCnsNodeVMBatchAttachment()
testCnsNodeVMBatchAttachment.Spec.NodeUUID = "test-2"
testCnsNodeVMBatchAttachment.Spec.InstanceUUID = "test-2"

r := setTestEnvironment(&testCnsNodeVMBatchAttachment, false)

Expand Down Expand Up @@ -237,7 +237,7 @@ func TestCnsNodeVMBatchAttachmentWhenVmOnVcenterReturnsNotFoundError(t *testing.

t.Run("TestCnsNodeVMBatchAttachmentWhenVmOnVcenterReturnsNotFoundError", func(t *testing.T) {
testCnsNodeVMBatchAttachment := setupTestCnsNodeVMBatchAttachment()
testCnsNodeVMBatchAttachment.Spec.NodeUUID = "test-3"
testCnsNodeVMBatchAttachment.Spec.InstanceUUID = "test-3"

r := setTestEnvironment(&testCnsNodeVMBatchAttachment, true)

Expand Down Expand Up @@ -287,7 +287,7 @@ func TestCnsNodeVMBatchAttachmentWhenVmOnVcenterReturnsNotFoundErrorAndInstanceI
func(t *testing.T) {
testCnsNodeVMBatchAttachment := setupTestCnsNodeVMBatchAttachment()
nodeUUID := "test-3"
testCnsNodeVMBatchAttachment.Spec.NodeUUID = nodeUUID
testCnsNodeVMBatchAttachment.Spec.InstanceUUID = nodeUUID

r := setTestEnvironment(&testCnsNodeVMBatchAttachment, false)

Expand Down