-
Notifications
You must be signed in to change notification settings - Fork 283
WIP: support for fetch --detect-offline-config
#948
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,8 @@ import ( | |
| "os" | ||
| "time" | ||
|
|
||
| "github.com/coreos/ignition/v2/internal/providers/file" | ||
|
|
||
| "github.com/coreos/ignition/v2/config" | ||
| "github.com/coreos/ignition/v2/config/shared/errors" | ||
| latest "github.com/coreos/ignition/v2/config/v3_1_experimental" | ||
|
|
@@ -54,6 +56,8 @@ type Engine struct { | |
| Root string | ||
| PlatformConfig platform.Config | ||
| Fetcher *resource.Fetcher | ||
|
|
||
| DetectOfflineConfig string | ||
| } | ||
|
|
||
| // Run executes the stage of the given name. It returns true if the stage | ||
|
|
@@ -67,6 +71,26 @@ func (e Engine) Run(stageName string) error { | |
| Ignition: types.Ignition{Version: types.MaxVersion.String()}, | ||
| } | ||
|
|
||
| if stageName == "fetch" && e.DetectOfflineConfig != "" { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WDYT about making this a helper func? |
||
| var haveConfig bool | ||
| // If we already have a config cache, we're done | ||
| if _, err := os.Stat(e.ConfigCache); err != nil { | ||
| haveConfig = true | ||
| } else { | ||
| haveConfig, err = e.detectOfflineConfig() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } | ||
| if haveConfig { | ||
| if err := ioutil.WriteFile(e.DetectOfflineConfig, []byte{}, 0644); err != nil { | ||
| return err | ||
| } | ||
| } | ||
| // Note early return | ||
| return nil | ||
| } | ||
|
|
||
| systemBaseConfig, r, err := system.FetchBaseConfig(e.Logger) | ||
| e.logReport(r) | ||
| if err != nil && err != providers.ErrNoProvider { | ||
|
|
@@ -175,6 +199,26 @@ func (e *Engine) acquireConfig() (cfg types.Config, err error) { | |
| return | ||
| } | ||
|
|
||
| // acquireConfigOffline only looks at config providers which do not | ||
| // require networking. | ||
| func (e *Engine) detectOfflineConfig() (bool, error) { | ||
| offlineFetchers := []providers.FuncDetectConfig{ | ||
| cmdline.DetectConfig, | ||
| file.DetectConfig, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, this is confusing. The goal here isn't to detect "offline" so much as whether a config was provided at all. We know that "statically" with those two by just looking at the filesystem basically. For other providers we may need to wait for a driver or even do a network request. Ideally we detect the "no config provided" case with those too. But...that's a higher level thing I think. |
||
| } | ||
|
|
||
| for _, fetcher := range offlineFetchers { | ||
| exists, err := fetcher(e.Fetcher) | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
| if exists { | ||
| return true, nil | ||
| } | ||
| } | ||
| return false, nil | ||
| } | ||
|
|
||
| // fetchProviderConfig returns the externally-provided configuration. It first | ||
| // checks to see if the command-line option is present. If so, it uses that | ||
| // source for the configuration. If the command-line option is not present, it | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,11 +42,14 @@ func main() { | |
| stage stages.Name | ||
| version bool | ||
| logToStdout bool | ||
|
|
||
| detectOfflineConfig string | ||
| }{} | ||
|
|
||
| flag.BoolVar(&flags.clearCache, "clear-cache", false, "clear any cached config") | ||
| flag.StringVar(&flags.configCache, "config-cache", "/run/ignition.json", "where to cache the config") | ||
| flag.DurationVar(&flags.fetchTimeout, "fetch-timeout", exec.DefaultFetchTimeout, "initial duration for which to wait for config") | ||
| flag.StringVar(&flags.detectOfflineConfig, "detect-config-provided", "", "If a config is provided, create a file at this path") | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason we write a stamp file is this is the best pattern I know of to signal the equivalent of |
||
| flag.Var(&flags.platform, "platform", fmt.Sprintf("current platform. %v", platform.Names())) | ||
| flag.StringVar(&flags.root, "root", "/", "root of the filesystem") | ||
| flag.Var(&flags.stage, "stage", fmt.Sprintf("execution stage. %v", stages.Names())) | ||
|
|
@@ -95,6 +98,8 @@ func main() { | |
| ConfigCache: flags.configCache, | ||
| PlatformConfig: platformConfig, | ||
| Fetcher: &fetcher, | ||
|
|
||
| DetectOfflineConfig: flags.detectOfflineConfig, | ||
| } | ||
|
|
||
| err = engine.Run(flags.stage.String()) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should fix the Ignition code so that the stages can have their own CLI args.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I can't agree more.