-
Notifications
You must be signed in to change notification settings - Fork 273
[RFC]: Azure: Proposal to Integrate User Creation in Ignition via Ignition Config #2185
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -55,14 +55,15 @@ var ( | |
|
|
||
| // Engine represents the entity that fetches and executes a configuration. | ||
| type Engine struct { | ||
| ConfigCache string | ||
| FetchTimeout time.Duration | ||
| Logger *log.Logger | ||
| NeedNet string | ||
| Root string | ||
| PlatformConfig platform.Config | ||
| Fetcher *resource.Fetcher | ||
| State *state.State | ||
| ConfigCache string | ||
| FetchTimeout time.Duration | ||
| GenerateCloudConfig bool | ||
| Logger *log.Logger | ||
| NeedNet string | ||
| Root string | ||
| PlatformConfig platform.Config | ||
| Fetcher *resource.Fetcher | ||
| State *state.State | ||
| } | ||
|
|
||
| // Run executes the stage of the given name. It returns true if the stage | ||
|
|
@@ -286,6 +287,10 @@ func (e *Engine) acquireProviderConfig() (cfg types.Config, err error) { | |
| // is unavailable. This will also render the config (see renderConfig) before | ||
| // returning. | ||
| func (e *Engine) fetchProviderConfig() (types.Config, error) { | ||
| if e.GenerateCloudConfig { | ||
| return e.fetchGeneratedConfig() | ||
| } | ||
|
|
||
| platformConfigs := []platform.Config{ | ||
| cmdline.Config, | ||
| system.Config, | ||
|
|
@@ -331,6 +336,28 @@ func (e *Engine) fetchProviderConfig() (types.Config, error) { | |
| return configFetcher.RenderConfig(cfg) | ||
| } | ||
|
|
||
| func (e *Engine) fetchGeneratedConfig() (types.Config, error) { | ||
| e.Logger.Info("using generated cloud config for platform %q", e.PlatformConfig.Name()) | ||
| cfg, err := e.PlatformConfig.GenerateConfig(e.Fetcher) | ||
| if err != nil { | ||
| return types.Config{}, err | ||
| } | ||
|
|
||
| e.State.FetchedConfigs = append(e.State.FetchedConfigs, state.FetchedConfig{ | ||
| Kind: "user", | ||
| Source: fmt.Sprintf("%s-generator", e.PlatformConfig.Name()), | ||
| Referenced: false, | ||
| }) | ||
|
|
||
| configFetcher := ConfigFetcher{ | ||
| Logger: e.Logger, | ||
| Fetcher: e.Fetcher, | ||
| State: e.State, | ||
| } | ||
|
|
||
| return configFetcher.RenderConfig(cfg) | ||
| } | ||
|
Comment on lines
+339
to
+359
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. This new Additionally, there is significant code duplication between func (e *Engine) fetchGeneratedConfig() (types.Config, error) {
e.Logger.Info("using generated cloud config for platform %q", e.PlatformConfig.Name())
cfg, err := e.PlatformConfig.GenerateConfig(e.Fetcher)
if err != nil {
return types.Config{}, err
}
e.State.FetchedConfigs = append(e.State.FetchedConfigs, state.FetchedConfig{
Kind: "user",
Source: fmt.Sprintf("%s-generator", e.PlatformConfig.Name()),
Referenced: false,
})
// Update the http client to use the timeouts and CAs from the newly fetched
// config, before rendering and fetching remote resources.
if err := e.Fetcher.UpdateHttpTimeoutsAndCAs(cfg.Ignition.Timeouts, cfg.Ignition.Security.TLS.CertificateAuthorities, cfg.Ignition.Proxy); err != nil {
return types.Config{}, err
}
configFetcher := ConfigFetcher{
Logger: e.Logger,
Fetcher: e.Fetcher,
State: e.State,
}
return configFetcher.RenderConfig(cfg)
} |
||
|
|
||
| func (e *Engine) signalNeedNet() error { | ||
| if err := executil.MkdirForFile(e.NeedNet); err != nil { | ||
| return err | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -48,20 +48,22 @@ func main() { | |||||||||||||||||||
|
|
||||||||||||||||||||
| func ignitionMain() { | ||||||||||||||||||||
| flags := struct { | ||||||||||||||||||||
| configCache string | ||||||||||||||||||||
| fetchTimeout time.Duration | ||||||||||||||||||||
| needNet string | ||||||||||||||||||||
| platform platform.Name | ||||||||||||||||||||
| root string | ||||||||||||||||||||
| stage stages.Name | ||||||||||||||||||||
| stateFile string | ||||||||||||||||||||
| version bool | ||||||||||||||||||||
| logToStdout bool | ||||||||||||||||||||
| configCache string | ||||||||||||||||||||
| fetchTimeout time.Duration | ||||||||||||||||||||
| generateCloudConfig bool | ||||||||||||||||||||
| needNet string | ||||||||||||||||||||
| platform platform.Name | ||||||||||||||||||||
| root string | ||||||||||||||||||||
| stage stages.Name | ||||||||||||||||||||
| stateFile string | ||||||||||||||||||||
| version bool | ||||||||||||||||||||
| logToStdout bool | ||||||||||||||||||||
| }{} | ||||||||||||||||||||
|
|
||||||||||||||||||||
| 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.needNet, "neednet", "/run/ignition/neednet", "flag file to write from fetch-offline if networking is needed") | ||||||||||||||||||||
| flag.BoolVar(&flags.generateCloudConfig, "generate-cloud-config", false, "generate config from cloud provider metadata instead of fetching") | ||||||||||||||||||||
| 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())) | ||||||||||||||||||||
|
|
@@ -71,6 +73,11 @@ func ignitionMain() { | |||||||||||||||||||
|
|
||||||||||||||||||||
| flag.Parse() | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // Never allow cloud config generation during fetch-offline stage (no networking) | ||||||||||||||||||||
| if flags.stage == "fetch" && flags.platform == "azure" { | ||||||||||||||||||||
| flags.generateCloudConfig = true | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
Comment on lines
+76
to
+79
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 comment on line 76 is misleading. It states "Never allow cloud config generation during fetch-offline stage", but the code block enables
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| if flags.version { | ||||||||||||||||||||
| fmt.Printf("%s\n", version.String) | ||||||||||||||||||||
| return | ||||||||||||||||||||
|
|
@@ -91,6 +98,8 @@ func ignitionMain() { | |||||||||||||||||||
|
|
||||||||||||||||||||
| logger.Info("%s", version.String) | ||||||||||||||||||||
| logger.Info("Stage: %v", flags.stage) | ||||||||||||||||||||
| logger.Info("Platform: %v", flags.platform) | ||||||||||||||||||||
| logger.Info("GenerateCloudConfig: %v", flags.generateCloudConfig) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| platformConfig := platform.MustGet(flags.platform.String()) | ||||||||||||||||||||
| fetcher, err := platformConfig.NewFetcher(&logger) | ||||||||||||||||||||
|
|
@@ -104,14 +113,15 @@ func ignitionMain() { | |||||||||||||||||||
| os.Exit(3) | ||||||||||||||||||||
| } | ||||||||||||||||||||
| engine := exec.Engine{ | ||||||||||||||||||||
| Root: flags.root, | ||||||||||||||||||||
| FetchTimeout: flags.fetchTimeout, | ||||||||||||||||||||
| Logger: &logger, | ||||||||||||||||||||
| NeedNet: flags.needNet, | ||||||||||||||||||||
| ConfigCache: flags.configCache, | ||||||||||||||||||||
| PlatformConfig: platformConfig, | ||||||||||||||||||||
| Fetcher: &fetcher, | ||||||||||||||||||||
| State: &state, | ||||||||||||||||||||
| Root: flags.root, | ||||||||||||||||||||
| FetchTimeout: flags.fetchTimeout, | ||||||||||||||||||||
| GenerateCloudConfig: flags.generateCloudConfig, | ||||||||||||||||||||
| Logger: &logger, | ||||||||||||||||||||
| NeedNet: flags.needNet, | ||||||||||||||||||||
| ConfigCache: flags.configCache, | ||||||||||||||||||||
| PlatformConfig: platformConfig, | ||||||||||||||||||||
| Fetcher: &fetcher, | ||||||||||||||||||||
| State: &state, | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| 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.
This change hardcodes
--generate-cloud-config=truefor thefetchstage. As noted in the RFC description, this is "Option B" which auto-enables the feature. While this simplifies the default case, it removes the flexibility for an Azure user to provide a standard Ignition config via user data if they wished. Have you considered making this configurable via a kernel argument, allowing users to opt-out of this new behavior if needed? This would align more with "Option A" and provide greater control.