Skip to content
Merged
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
1 change: 1 addition & 0 deletions docs/FUNCTIONS_GLOSSARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ All exported functions available in the `pkg/` directory, grouped by resource.
`pkg/kubernetes/virtualdisk.go`

- `AttachVirtualDiskToVM(ctx, kubeconfig, config)` — Creates a blank VirtualDisk and attaches it to a VM using VirtualMachineBlockDeviceAttachment. Returns created resource names.
- `ReattachVirtualDiskToVM(ctx, kubeconfig, config)` — Attaches an existing VirtualDisk to a VM by creating a VirtualMachineBlockDeviceAttachment with explicit names.
- `WaitForVirtualDiskAttached(ctx, kubeconfig, namespace, attachmentName, pollInterval)` — Waits for a VirtualMachineBlockDeviceAttachment to reach the Attached phase.
- `ListVirtualMachineNames(ctx, kubeconfig, namespace)` — Lists VM names in a namespace.
- `GetVMIPFromBaseCluster(ctx, baseKubeconfig, namespace, vmName)` — Returns VM IP address from status (for SSH connections).
Expand Down
6 changes: 6 additions & 0 deletions docs/WORKLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,9 @@ All notable changes to this repository are documented here. New entries are appe
## 2026-05-13

- **Update** synchronized docs for commit `bc358dff` by adding `pkg/kubernetes.NewVirtualizationClient` and `pkg/storage-e2e.Initialize` to `docs/FUNCTIONS_GLOSSARY.md`, and reflecting new `pkg/kubernetes/virtclient.go` / `pkg/storage-e2e/setup.go` in `docs/ARCHITECTURE.md`

---

## 2026-05-14

- **Update** `pkg/kubernetes/virtualdisk.go`: normalized new reattach API to `ReattachVirtualDiskToVM` (Go initialism style), added input validation and exported docs for `VirtualDiskReattachmentConfig`; synced entry in `docs/FUNCTIONS_GLOSSARY.md`
59 changes: 59 additions & 0 deletions pkg/kubernetes/virtualdisk.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,65 @@ func AttachVirtualDiskToVM(ctx context.Context, kubeconfig *rest.Config, config
}, nil
}

// VirtualDiskReattachmentConfig holds configuration for reattaching an existing virtual disk to a VM.
type VirtualDiskReattachmentConfig struct {
// AttachmentName is the name of the VirtualMachineBlockDeviceAttachment to create.
AttachmentName string
// VMName is the name of the VirtualMachine to attach the disk to.
VMName string
// Namespace is the namespace where the VM and disk resources are located.
Namespace string
// DiskName is the name of an existing VirtualDisk to attach.
DiskName string
}

// ReattachVirtualDiskToVM attaches an existing VirtualDisk to the specified VM.
// It creates a VirtualMachineBlockDeviceAttachment using the provided disk and attachment names.
func ReattachVirtualDiskToVM(ctx context.Context, kubeconfig *rest.Config, config VirtualDiskReattachmentConfig) (*VirtualDiskAttachmentResult, error) {
if config.AttachmentName == "" {
return nil, fmt.Errorf("AttachmentName is required")
}
if config.VMName == "" {
return nil, fmt.Errorf("VMName is required")
}
if config.Namespace == "" {
return nil, fmt.Errorf("Namespace is required")
}
if config.DiskName == "" {
return nil, fmt.Errorf("DiskName is required")
}

virtClient, err := virtualization.NewClient(ctx, kubeconfig)
if err != nil {
return nil, fmt.Errorf("failed to create virtualization client: %w", err)
}

attachment := &v1alpha2.VirtualMachineBlockDeviceAttachment{
ObjectMeta: metav1.ObjectMeta{
Name: config.AttachmentName,
Namespace: config.Namespace,
},
Spec: v1alpha2.VirtualMachineBlockDeviceAttachmentSpec{
VirtualMachineName: config.VMName,
BlockDeviceRef: v1alpha2.VMBDAObjectRef{
Kind: v1alpha2.VMBDAObjectRefKindVirtualDisk,
Name: config.DiskName,
},
},
}

err = virtClient.VirtualMachineBlockDeviceAttachments().Create(ctx, attachment)
if err != nil {
return nil, fmt.Errorf("failed to create VirtualMachineBlockDeviceAttachment %s: %w", config.AttachmentName, err)
}
logger.Success("VirtualMachineBlockDeviceAttachment %s created", config.AttachmentName)

return &VirtualDiskAttachmentResult{
DiskName: config.DiskName,
AttachmentName: config.AttachmentName,
}, nil
}

// WaitForVirtualDiskAttached waits for the VirtualMachineBlockDeviceAttachment to reach the Attached phase.
// It polls the attachment status until it's attached or the context is cancelled/times out.
// The pollInterval parameter specifies how often to check the status (recommended: 10 seconds).
Expand Down
Loading