mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-08-25 03:22:44 +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 (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"gopkg.in/yaml.v3"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/kairos-io/kairos-agent/v2/internal/bus"
|
"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/internal/cmd"
|
||||||
"github.com/kairos-io/kairos-agent/v2/pkg/config"
|
"github.com/kairos-io/kairos-agent/v2/pkg/config"
|
||||||
events "github.com/kairos-io/kairos-sdk/bus"
|
events "github.com/kairos-io/kairos-sdk/bus"
|
||||||
|
"github.com/kairos-io/kairos-sdk/collector"
|
||||||
"github.com/kairos-io/kairos-sdk/unstructured"
|
"github.com/kairos-io/kairos-sdk/unstructured"
|
||||||
|
|
||||||
"github.com/erikgeiser/promptkit/textinput"
|
"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{
|
Install: &config.Install{
|
||||||
Device: device,
|
Device: device,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
// Merge all yamls into one
|
// Merge all yamls into one
|
||||||
dat, err := config.MergeYAML(cloudConfig, c, result)
|
dat, err := config.MergeYAML(cloudConfig, cc, result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
finalCloudConfig := config.AddHeader("#cloud-config", string(dat))
|
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")
|
pterm.Info.Println("Starting installation")
|
||||||
// Generate final config
|
// Generate final config
|
||||||
|
ccString, _ := cc.String()
|
||||||
cc := &config.Config{}
|
pterm.Info.Println(ccString)
|
||||||
yaml.Unmarshal([]byte(finalCloudConfig), cc)
|
|
||||||
|
|
||||||
pterm.Info.Println(finalCloudConfig)
|
|
||||||
|
|
||||||
err = RunInstall(cc)
|
err = RunInstall(cc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user