Skip to content

Commit

Permalink
Generate descriptions
Browse files Browse the repository at this point in the history
Signed-off-by: ekarlso <endre.karlson@gmail.com>
  • Loading branch information
ekarlso committed Oct 9, 2024
1 parent 5299af1 commit cba6b50
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 19 deletions.
1 change: 1 addition & 0 deletions api/v1alpha1/proxmoxmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const (
IPV6Format = "v6"
)

// ProxmoxMachineChecks defines possibibles checks to skip.
type ProxmoxMachineChecks struct {
// Skip checking CloudInit which can be very useful for specific Operating Systems like TalOS
// +optional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ spec:
useful for specific Operating Systems like TalOS
type: boolean
skipQemuGuestAgent:
description: Skip checking QEMU Agent readiness which
can be very useful for specific Operating Systems
like TalOS
type: boolean
type: object
description:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ spec:
like TalOS
type: boolean
skipQemuGuestAgent:
description: Skip checking QEMU Agent readiness
which can be very useful for specific Operating
Systems like TalOS
type: boolean
type: object
description:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ spec:
for specific Operating Systems like TalOS
type: boolean
skipQemuGuestAgent:
description: Skip checking QEMU Agent readiness which can be very
useful for specific Operating Systems like TalOS
type: boolean
type: object
description:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ spec:
useful for specific Operating Systems like TalOS
type: boolean
skipQemuGuestAgent:
description: Skip checking QEMU Agent readiness which
can be very useful for specific Operating Systems like
TalOS
type: boolean
type: object
description:
Expand Down
20 changes: 2 additions & 18 deletions internal/service/vmservice/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,35 +108,19 @@ func ReconcileVM(ctx context.Context, scope *scope.MachineScope) (infrav1alpha1.
return vm, nil
}

func skipQemuGuestCheck(mc *scope.MachineScope) bool {
if mc.ProxmoxMachine.Spec.Checks != nil {
return ptr.Deref(mc.ProxmoxMachine.Spec.Checks.SkipQemuGuestAgent, false)
}

return false
}

func skipCloudInitCheck(mc *scope.MachineScope) bool {
if mc.ProxmoxMachine.Spec.Checks != nil {
return ptr.Deref(mc.ProxmoxMachine.Spec.Checks.SkipCloudInitStatus, false)
}

return false
}

func checkCloudInitStatus(ctx context.Context, machineScope *scope.MachineScope) (requeue bool, err error) {
if !machineScope.VirtualMachine.IsRunning() {
// skip if the vm is not running.
return true, nil
}

if !skipQemuGuestCheck(machineScope) {
if !machineScope.SkipQemuGuestCheck() {
if err := machineScope.InfraCluster.ProxmoxClient.QemuAgentStatus(ctx, machineScope.VirtualMachine); err != nil {
return true, errors.Wrap(err, "error waiting for agent")
}
}

if !skipCloudInitCheck(machineScope) {
if !machineScope.SkipQemuGuestCheck() && !machineScope.SkipCloudInitCheck() {
if running, err := machineScope.InfraCluster.ProxmoxClient.CloudInitStatus(ctx, machineScope.VirtualMachine); err != nil || running {
if running {
return true, nil
Expand Down
2 changes: 1 addition & 1 deletion internal/service/vmservice/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestReconcileVM_QemuAgentCheckDisabled(t *testing.T) {
}

proxmoxClient.EXPECT().GetVM(context.Background(), "node1", int64(123)).Return(vm, nil).Once()
proxmoxClient.EXPECT().CloudInitStatus(context.Background(), vm).Return(false, nil).Once()
// proxmoxClient.EXPECT().CloudInitStatus(context.Background(), vm).Return(false, nil).Once()

result, err := ReconcileVM(context.Background(), machineScope)
require.NoError(t, err)
Expand Down
1 change: 1 addition & 0 deletions pkg/proxmox/goproxmox/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ func (c *APIClient) CloudInitStatus(ctx context.Context, vm *proxmox.VirtualMach
return false, nil
}

// QemuAgentStatus returns the qemu-agent status of the VM.
func (c *APIClient) QemuAgentStatus(ctx context.Context, vm *proxmox.VirtualMachine) error {
if err := vm.WaitForAgent(ctx, 5); err != nil {
return errors.Wrap(err, "error waiting for agent")
Expand Down
18 changes: 18 additions & 0 deletions pkg/scope/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,21 @@ func (m *MachineScope) GetBootstrapSecret(ctx context.Context, secret *corev1.Se

return m.client.Get(ctx, secretKey, secret)
}

// SkipQemuGuestCheck check whether qemu-agent status check is enabled.
func (m *MachineScope) SkipQemuGuestCheck() bool {
if m.ProxmoxMachine.Spec.Checks != nil {
return ptr.Deref(m.ProxmoxMachine.Spec.Checks.SkipQemuGuestAgent, false)
}

return false
}

// SkipCloudInitCheck check whether cloud-init status check is enabled.
func (m *MachineScope) SkipCloudInitCheck() bool {
if m.ProxmoxMachine.Spec.Checks != nil {
return ptr.Deref(m.ProxmoxMachine.Spec.Checks.SkipCloudInitStatus, false)
}

return false
}

0 comments on commit cba6b50

Please sign in to comment.