mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-05-11 09:55:19 +00:00
Make interactive installer use the collector as well (#113)
This commit is contained in:
parent
822222a645
commit
00eae4c029
@ -3,13 +3,15 @@ package agent
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gopkg.in/yaml.v3"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/kairos-io/kairos-agent/v2/internal/bus"
|
||||
"github.com/kairos-io/kairos-agent/v2/internal/cmd"
|
||||
"github.com/kairos-io/kairos-agent/v2/pkg/config"
|
||||
events "github.com/kairos-io/kairos-sdk/bus"
|
||||
"github.com/kairos-io/kairos-sdk/collector"
|
||||
"github.com/kairos-io/kairos-sdk/unstructured"
|
||||
|
||||
"github.com/erikgeiser/promptkit/textinput"
|
||||
@ -259,26 +261,35 @@ func InteractiveInstall(debug, spawnShell bool) error {
|
||||
},
|
||||
}}}
|
||||
|
||||
c := &config.Config{
|
||||
// This is temporal to generate a valid cc file, no need to properly initialize everything
|
||||
cc := &config.Config{
|
||||
Install: &config.Install{
|
||||
Device: device,
|
||||
},
|
||||
}
|
||||
// Merge all yamls into one
|
||||
dat, err := config.MergeYAML(cloudConfig, c, result)
|
||||
dat, err := config.MergeYAML(cloudConfig, cc, result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
finalCloudConfig := config.AddHeader("#cloud-config", string(dat))
|
||||
|
||||
// Store it in a temp file and load it with the collector to have a standard way of loading across all methods
|
||||
tmpdir, err := os.MkdirTemp("", "kairos-install-")
|
||||
if err == nil {
|
||||
err = os.WriteFile(filepath.Join(tmpdir, "kairos-event-install-data.yaml"), []byte(finalCloudConfig), os.ModePerm)
|
||||
if err != nil {
|
||||
fmt.Printf("could not write event cloud init: %s\n", err.Error())
|
||||
}
|
||||
// override cc with our new config object from the scan, so it's updated for the RunInstall function
|
||||
cc, _ = config.Scan(collector.Directories(tmpdir), collector.MergeBootLine, collector.NoLogs)
|
||||
}
|
||||
|
||||
pterm.Info.Println("Starting installation")
|
||||
// Generate final config
|
||||
|
||||
cc := &config.Config{}
|
||||
yaml.Unmarshal([]byte(finalCloudConfig), cc)
|
||||
|
||||
pterm.Info.Println(finalCloudConfig)
|
||||
ccString, _ := cc.String()
|
||||
pterm.Info.Println(ccString)
|
||||
|
||||
err = RunInstall(cc)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user