Skip to content

Commit 319f953

Browse files
committed
Switched back to linked clones and improved logging for WaitForDisk
1 parent b131d11 commit 319f953

4 files changed

Lines changed: 9 additions & 20 deletions

File tree

internal/cloning/cloning_service.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ func (cs *CloningService) CloneTemplate(template string, targetName string, isGr
6666
}
6767

6868
// 2. Check if the template has already been cloned by the user
69-
7069
// Extract template name from pool name (remove kamino_template_ prefix)
7170
templateName := strings.TrimPrefix(template, "kamino_template_")
7271

@@ -130,14 +129,14 @@ func (cs *CloningService) CloneTemplate(template string, targetName string, isGr
130129
}
131130
}
132131

133-
newRouter, err := cs.ProxmoxService.CloneVM(*router, newPoolName, true) // Always use full clone for routers
132+
newRouter, err := cs.ProxmoxService.CloneVM(*router, newPoolName)
134133
if err != nil {
135134
errors = append(errors, fmt.Sprintf("failed to clone router VM: %v", err))
136135
}
137136

138137
// Clone each VM to new pool
139138
for _, vm := range templateVMs {
140-
_, err := cs.ProxmoxService.CloneVM(vm, newPoolName, cs.Config.UseFullClones)
139+
_, err := cs.ProxmoxService.CloneVM(vm, newPoolName)
141140
if err != nil {
142141
errors = append(errors, fmt.Sprintf("failed to clone VM %s: %v", vm.Name, err))
143142
}

internal/cloning/types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ type Config struct {
2222
WANScriptPath string `envconfig:"WAN_SCRIPT_PATH" default:"/home/update-wan-ip.sh"`
2323
VIPScriptPath string `envconfig:"VIP_SCRIPT_PATH" default:"/home/update-wan-vip.sh"`
2424
WANIPBase string `envconfig:"WAN_IP_BASE" default:"172.16."`
25-
UseFullClones bool `envconfig:"USE_FULL_CLONES" default:"false"`
2625
}
2726

2827
// KaminoTemplate represents a template in the system

internal/proxmox/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type Service interface {
4242
StopVM(node string, vmID int) error
4343
DeleteVM(node string, vmID int) error
4444
ConvertVMToTemplate(node string, vmID int) error
45-
CloneVM(sourceVM VM, newPoolName string, useFullClone bool) (*VM, error)
45+
CloneVM(sourceVM VM, newPoolName string) (*VM, error)
4646
WaitForCloneCompletion(vm *VM, timeout time.Duration) error
4747
WaitForDisk(node string, vmid int, maxWait time.Duration) error
4848
WaitForRunning(vm VM) error

internal/proxmox/vms.go

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package proxmox
22

33
import (
44
"fmt"
5+
"log"
56
"math"
67
"strconv"
78
"strings"
@@ -76,7 +77,7 @@ func (s *ProxmoxService) ConvertVMToTemplate(node string, vmID int) error {
7677
return nil
7778
}
7879

79-
func (s *ProxmoxService) CloneVM(sourceVM VM, newPoolName string, useFullClone bool) (*VM, error) {
80+
func (s *ProxmoxService) CloneVM(sourceVM VM, newPoolName string) (*VM, error) {
8081
// Get next available VMID
8182
req := tools.ProxmoxAPIRequest{
8283
Method: "GET",
@@ -99,18 +100,12 @@ func (s *ProxmoxService) CloneVM(sourceVM VM, newPoolName string, useFullClone b
99100
return nil, fmt.Errorf("failed to find best node: %w", err)
100101
}
101102

102-
// Determine clone type based on parameter
103-
cloneType := 0 // Linked clone by default
104-
if useFullClone {
105-
cloneType = 1 // Full clone
106-
}
107-
108103
// Clone VM
109104
cloneBody := map[string]any{
110105
"newid": newVMID,
111106
"name": sourceVM.Name,
112107
"pool": newPoolName,
113-
"full": cloneType, // Use configurable clone type
108+
"full": 0, // Linked clone
114109
"target": bestNode,
115110
}
116111

@@ -181,18 +176,14 @@ func (s *ProxmoxService) WaitForDisk(node string, vmid int, maxWait time.Duratio
181176
time.Sleep(2 * time.Second)
182177

183178
configResp, err := s.getVMConfig(node, vmid)
179+
log.Printf("Disk check for VM %d on node %s: %+v (err: %v)", vmid, node, configResp, err)
184180
if err != nil {
185181
continue
186182
}
187183

188184
if configResp.HardDisk != "" {
189-
// Additional check: try to get VM status to ensure disk is actually accessible
190-
_, statusErr := s.getVMStatus(node, vmid)
191-
if statusErr == nil {
192-
// Wait a bit more for linked clone dependencies to be fully ready
193-
time.Sleep(5 * time.Second)
194-
return nil // Disk is available and VM is accessible
195-
}
185+
log.Printf("Disk for VM %d on node %s is available", vmid, node)
186+
return nil // Disk is available
196187
}
197188
}
198189

0 commit comments

Comments
 (0)