From bee82b030de44740469ebfc4ae50b9ea471f46bb 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 | 5 ++ ...ster.x-k8s.io_proxmoxclustertemplates.yaml | 5 ++ ...ture.cluster.x-k8s.io_proxmoxmachines.yaml | 3 ++ ...ster.x-k8s.io_proxmoxmachinetemplates.yaml | 5 ++ 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 +++++++ pkg/scope/machine_test.go | 52 +++++++++++++++++++ 10 files changed, 93 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..6bd32e5a 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxclusters.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxclusters.yaml @@ -73,12 +73,17 @@ spec: a ProxmoxMachine. properties: checks: + description: ProxmoxMachineChecks defines possibibles checks + to skip. properties: skipCloudInitStatus: description: Skip checking CloudInit which can be very 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..1904f1c4 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxclustertemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxclustertemplates.yaml @@ -91,6 +91,8 @@ spec: state of a ProxmoxMachine. properties: checks: + description: ProxmoxMachineChecks defines possibibles + checks to skip. properties: skipCloudInitStatus: description: Skip checking CloudInit which can @@ -98,6 +100,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..a8c06f61 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxmachines.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxmachines.yaml @@ -66,12 +66,15 @@ spec: description: ProxmoxMachineSpec defines the desired state of a ProxmoxMachine. properties: checks: + description: ProxmoxMachineChecks defines possibibles checks to skip. properties: skipCloudInitStatus: description: Skip checking CloudInit which can be very 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_proxmoxmachinetemplates.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxmachinetemplates.yaml index bbf2a7d4..5922922e 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxmachinetemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxmachinetemplates.yaml @@ -73,12 +73,17 @@ spec: ProxmoxMachine. properties: checks: + description: ProxmoxMachineChecks defines possibibles checks + to skip. properties: skipCloudInitStatus: description: Skip checking CloudInit which can be very 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 +} diff --git a/pkg/scope/machine_test.go b/pkg/scope/machine_test.go index f13e5801..814c0def 100644 --- a/pkg/scope/machine_test.go +++ b/pkg/scope/machine_test.go @@ -122,6 +122,58 @@ func TestMachineScope_HasFailed(t *testing.T) { require.False(t, scope.HasFailed()) } +func TestMachineScope_SkipQemuCheckEnabled(t *testing.T) { + p := infrav1alpha1.ProxmoxMachine{ + Spec: infrav1alpha1.ProxmoxMachineSpec{ + Checks: &infrav1alpha1.ProxmoxMachineChecks{ + SkipCloudInitStatus: ptr.To(true), + }, + }, + } + scope := MachineScope{ + ProxmoxMachine: &p, + } + + require.True(t, scope.SkipCloudInitCheck()) +} + +func TestMachineScope_SkipQemuCheck(t *testing.T) { + p := infrav1alpha1.ProxmoxMachine{ + Spec: infrav1alpha1.ProxmoxMachineSpec{}, + } + scope := MachineScope{ + ProxmoxMachine: &p, + } + + require.False(t, scope.SkipCloudInitCheck()) +} + +func TestMachineScope_SkipCloudInitCheckEnabled(t *testing.T) { + p := infrav1alpha1.ProxmoxMachine{ + Spec: infrav1alpha1.ProxmoxMachineSpec{ + Checks: &infrav1alpha1.ProxmoxMachineChecks{ + SkipCloudInitStatus: ptr.To(true), + }, + }, + } + scope := MachineScope{ + ProxmoxMachine: &p, + } + + require.True(t, scope.SkipCloudInitCheck()) +} + +func TestMachineScope_SkipCloudInit(t *testing.T) { + p := infrav1alpha1.ProxmoxMachine{ + Spec: infrav1alpha1.ProxmoxMachineSpec{}, + } + scope := MachineScope{ + ProxmoxMachine: &p, + } + + require.False(t, scope.SkipQemuGuestCheck()) +} + func TestMachineScope_GetBootstrapSecret(t *testing.T) { client := fake.NewClientBuilder().Build() p := infrav1alpha1.ProxmoxMachine{