mirror of
https://github.com/coreos/ignition.git
synced 2026-02-06 18:47:54 +01:00
internal/oem: Implement framework for reporting status
main.go checks if stage Run() is successful. oem.go implements the a Status() function that calls the oem specific fucntion to report the ignition status. FetchFromHTTP in url.go will check if f.client is nill.
This commit is contained in:
@@ -93,7 +93,13 @@ func main() {
|
||||
Fetcher: &fetcher,
|
||||
}
|
||||
|
||||
if engine.Run(flags.stage.String()) != nil {
|
||||
err = engine.Run(flags.stage.String())
|
||||
if statusErr := engine.OEMConfig.Status(flags.stage.String(), *engine.Fetcher, err); statusErr != nil {
|
||||
logger.Err("POST Status error: ", statusErr.Error())
|
||||
}
|
||||
if err != nil {
|
||||
logger.Crit("Ignition failed: %v", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
logger.Info("Ignition finished successfully")
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ type Config struct {
|
||||
name string
|
||||
fetch providers.FuncFetchConfig
|
||||
newFetcher providers.FuncNewFetcher
|
||||
status providers.FuncPostStatus
|
||||
}
|
||||
|
||||
func (c Config) Name() string {
|
||||
@@ -61,6 +62,14 @@ func (c Config) NewFetcherFunc() providers.FuncNewFetcher {
|
||||
}
|
||||
}
|
||||
|
||||
// Status takes a Fetcher and the error from Run (from engine)
|
||||
func (c Config) Status(stageName string, f resource.Fetcher, statusErr error) error {
|
||||
if c.status != nil {
|
||||
return c.status(stageName, f, statusErr)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var configs = registry.Create("oem configs")
|
||||
|
||||
func init() {
|
||||
|
||||
@@ -29,3 +29,4 @@ var (
|
||||
|
||||
type FuncFetchConfig func(f resource.Fetcher) (types.Config, report.Report, error)
|
||||
type FuncNewFetcher func(logger *log.Logger) (resource.Fetcher, error)
|
||||
type FuncPostStatus func(stageName string, f resource.Fetcher, e error) error
|
||||
|
||||
@@ -219,9 +219,14 @@ func (f *Fetcher) FetchFromTFTP(u url.URL, dest *os.File, opts FetchOptions) err
|
||||
// FetchFromHTTP fetches a resource from u via HTTP(S) into dest, returning an
|
||||
// error if one is encountered.
|
||||
func (f *Fetcher) FetchFromHTTP(u url.URL, dest *os.File, opts FetchOptions) error {
|
||||
// for the case when "config is not valid"
|
||||
// this if necessary if not spawned through kola (e.g. Packet Dashboard)
|
||||
if f.client == nil {
|
||||
logger := log.New(true)
|
||||
f.Logger = &logger
|
||||
f.newHttpClient()
|
||||
}
|
||||
|
||||
dataReader, status, ctxCancel, err := f.client.getReaderWithHeader(u.String(), opts.Headers)
|
||||
if ctxCancel != nil {
|
||||
// whatever context getReaderWithHeader created for the request should
|
||||
|
||||
Reference in New Issue
Block a user