From cba6b50b43f190f1c901bc3c940849e591590ec6 Mon Sep 17 00:00:00 2001 From: ekarlso Date: Tue, 1 Oct 2024 00:27:56 +0200 Subject: [PATCH] Generate descriptions Signed-off-by: ekarlso --- api/v1alpha1/proxmoxmachine_types.go | 1 + ...ture.cluster.x-k8s.io_proxmoxclusters.yaml | 3 +++ ...ster.x-k8s.io_proxmoxclustertemplates.yaml | 3 +++ ...ture.cluster.x-k8s.io_proxmoxmachines.yaml | 2 ++ ...ster.x-k8s.io_proxmoxmachinetemplates.yaml | 3 +++ internal/service/vmservice/vm.go | 20 ++----------------- internal/service/vmservice/vm_test.go | 2 +- pkg/proxmox/goproxmox/api_client.go | 1 + pkg/scope/machine.go | 18 +++++++++++++++++ 9 files changed, 34 insertions(+), 19 deletions(-) diff --git a/api/v1alpha1/proxmoxmachine_types.go b/api/v1alpha1/proxmoxmachine_types.go index 8a87f223..d2fd7119 100644 --- a/api/v1alpha1/proxmoxmachine_types.go +++ b/api/v1alpha1/proxmoxmachine_types.go @@ -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 diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxclusters.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxclusters.yaml index b226e731..4e6ebfd8 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxclusters.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxclusters.yaml @@ -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: diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxclustertemplates.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxclustertemplates.yaml index d950d601..7e7daf90 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxclustertemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxclustertemplates.yaml @@ -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: diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxmachines.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxmachines.yaml index 8f3a2cb8..043bc1c6 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxmachines.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxmachines.yaml @@ -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: diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxmachinetemplates.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxmachinetemplates.yaml index bbf2a7d4..8ca64ba2 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxmachinetemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxmachinetemplates.yaml @@ -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: diff --git a/internal/service/vmservice/vm.go b/internal/service/vmservice/vm.go index 42154037..dbd076b9 100644 --- a/internal/service/vmservice/vm.go +++ b/internal/service/vmservice/vm.go @@ -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 diff --git a/internal/service/vmservice/vm_test.go b/internal/service/vmservice/vm_test.go index c016484a..686abf98 100644 --- a/internal/service/vmservice/vm_test.go +++ b/internal/service/vmservice/vm_test.go @@ -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) diff --git a/pkg/proxmox/goproxmox/api_client.go b/pkg/proxmox/goproxmox/api_client.go index 3af6e726..781e4dc4 100644 --- a/pkg/proxmox/goproxmox/api_client.go +++ b/pkg/proxmox/goproxmox/api_client.go @@ -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") diff --git a/pkg/scope/machine.go b/pkg/scope/machine.go index 00945b7f..988d57e8 100644 --- a/pkg/scope/machine.go +++ b/pkg/scope/machine.go @@ -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 +}