fix: recover externally removed Talos VMs
This commit is contained in:
parent
769028c587
commit
54a2ae2838
|
|
@ -1406,6 +1406,10 @@ func terraformReconcileTargets(cfg config.Config) []string {
|
||||||
|
|
||||||
func (r Runner) rebuildTalosVMs(terraformDir string, environment []string) error {
|
func (r Runner) rebuildTalosVMs(terraformDir string, environment []string) error {
|
||||||
if err := r.importConfiguredTalosVMs(terraformDir, environment); err != nil {
|
if err := r.importConfiguredTalosVMs(terraformDir, environment); err != nil {
|
||||||
|
var apiErr proxmox.APIError
|
||||||
|
if errors.As(err, &apiErr) && apiErr.StatusCode == 404 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return destroyTalosVMs(terraformDir, environment)
|
return destroyTalosVMs(terraformDir, environment)
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -17,6 +18,7 @@ import (
|
||||||
"github.com/Pingu-Studio/MaidnCLI/internal/config"
|
"github.com/Pingu-Studio/MaidnCLI/internal/config"
|
||||||
"github.com/Pingu-Studio/MaidnCLI/internal/forgejo"
|
"github.com/Pingu-Studio/MaidnCLI/internal/forgejo"
|
||||||
"github.com/Pingu-Studio/MaidnCLI/internal/openbao"
|
"github.com/Pingu-Studio/MaidnCLI/internal/openbao"
|
||||||
|
"github.com/Pingu-Studio/MaidnCLI/internal/proxmox"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -1278,6 +1280,48 @@ func TestRebuildTerraformRetainsFullTalosVMLifecycle(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRebuildTerraformSkipsAlreadyAbsentTalosVM(t *testing.T) {
|
||||||
|
originalVerify := verifyTalosVMs
|
||||||
|
originalRun := runTerraform
|
||||||
|
originalDestroy := destroyTalosVMs
|
||||||
|
t.Cleanup(func() {
|
||||||
|
verifyTalosVMs = originalVerify
|
||||||
|
runTerraform = originalRun
|
||||||
|
destroyTalosVMs = originalDestroy
|
||||||
|
})
|
||||||
|
|
||||||
|
cfg := config.Config{ClusterID: "test-cluster", Talos: config.TalosConfig{
|
||||||
|
Nodes: []config.TalosNode{{Name: "cp-01", ProxmoxNode: "pve", VMID: 100, Role: "controlplane"}},
|
||||||
|
}}
|
||||||
|
var events []string
|
||||||
|
verifyTalosVMs = func(config.Config) error {
|
||||||
|
return fmt.Errorf("inspect configured Talos VM: %w", proxmox.APIError{StatusCode: 404})
|
||||||
|
}
|
||||||
|
destroyTalosVMs = func(string, []string) error {
|
||||||
|
t.Fatal("destroy ran for an already-absent VM")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
runTerraform = func(_ string, _ []string, name string, args ...string) error {
|
||||||
|
if name != "terraform" {
|
||||||
|
t.Fatalf("unexpected command %q", name)
|
||||||
|
}
|
||||||
|
switch args[0] {
|
||||||
|
case "init", "plan", "apply":
|
||||||
|
events = append(events, args[0])
|
||||||
|
default:
|
||||||
|
t.Fatalf("unexpected Terraform operation %q", args[0])
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := (Runner{Config: cfg, Mode: Rebuild}).reconcileTerraform(t.TempDir()); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if strings.Join(events, ",") != "init,plan,apply" {
|
||||||
|
t.Fatalf("Terraform phase order = %q", events)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestEnsureLifecycleIdentityStoresMetadataUnderGeneratedDirectory(t *testing.T) {
|
func TestEnsureLifecycleIdentityStoresMetadataUnderGeneratedDirectory(t *testing.T) {
|
||||||
repo := t.TempDir()
|
repo := t.TempDir()
|
||||||
terraformDir := filepath.Join(repo, "terraform")
|
terraformDir := filepath.Join(repo, "terraform")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue