-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Bootstrap Ignition shim Asset #2544
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| package bootstrap | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "os" | ||
|
|
||
| igntypes "github.com/coreos/ignition/config/v2_2/types" | ||
| "github.com/pkg/errors" | ||
|
|
||
| "github.com/openshift/installer/pkg/asset" | ||
| "github.com/openshift/installer/pkg/asset/ignition" | ||
| "github.com/openshift/installer/pkg/asset/installconfig" | ||
| "github.com/openshift/installer/pkg/asset/tls" | ||
| ) | ||
|
|
||
| const ( | ||
| bootstrapShimIgnFilename = "bootstrap_shim.ign" | ||
| ) | ||
|
|
||
| // Shim holds data with the contents and path to a bootstrap ignition shim file | ||
| type Shim struct { | ||
| Config *igntypes.Config | ||
| File *asset.File | ||
| } | ||
|
|
||
| var _ asset.WritableAsset = (*Shim)(nil) | ||
|
|
||
| // Dependencies returns the assets on which the Bootstrap asset depends. | ||
| func (a *Shim) Dependencies() []asset.Asset { | ||
| return []asset.Asset{ | ||
| &installconfig.InstallConfig{}, | ||
| &tls.RootCA{}, | ||
| } | ||
| } | ||
|
|
||
| // Generate generates the ignition config for the Bootstrap asset. | ||
| func (a *Shim) Generate(dependencies asset.Parents) error { | ||
| installConfig := &installconfig.InstallConfig{} | ||
| rootCA := &tls.RootCA{} | ||
| dependencies.Get(installConfig, rootCA) | ||
|
|
||
| a.Config = ignition.PointerIgnitionConfig(installConfig.Config, rootCA.Cert(), "bootstrap") | ||
| data, err := json.Marshal(a.Config) | ||
| if err != nil { | ||
| return errors.Wrap(err, "failed to marshal Ignition config") | ||
| } | ||
| a.File = &asset.File{ | ||
| Filename: bootstrapShimIgnFilename, | ||
| Data: data, | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // Name returns the human-friendly name of the asset. | ||
| func (a *Shim) Name() string { | ||
| return "Bootstrap Shim Ignition Config" | ||
| } | ||
|
|
||
| // Files returns the files generated by the asset. | ||
| func (a *Shim) Files() []*asset.File { | ||
| if a.File != nil { | ||
| return []*asset.File{a.File} | ||
| } | ||
| return []*asset.File{} | ||
| } | ||
|
|
||
| // Load returns the master ignitions from disk. | ||
| func (a *Shim) Load(f asset.FileFetcher) (found bool, err error) { | ||
| file, err := f.FetchByName(bootstrapShimIgnFilename) | ||
| if err != nil { | ||
| if os.IsNotExist(err) { | ||
| return false, nil | ||
| } | ||
| return false, err | ||
| } | ||
|
|
||
| config := &igntypes.Config{} | ||
| if err := json.Unmarshal(file.Data, config); err != nil { | ||
| return false, errors.Wrapf(err, "failed to unmarshal %s", bootstrapShimIgnFilename) | ||
| } | ||
|
|
||
| a.File, a.Config = file, config | ||
| return true, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| package ignition | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "net/url" | ||
|
|
||
| ignition "github.com/coreos/ignition/config/v2_2/types" | ||
| "github.com/vincent-petithory/dataurl" | ||
|
|
||
| "github.com/openshift/installer/pkg/types" | ||
| baremetaltypes "github.com/openshift/installer/pkg/types/baremetal" | ||
| openstacktypes "github.com/openshift/installer/pkg/types/openstack" | ||
| openstackdefaults "github.com/openshift/installer/pkg/types/openstack/defaults" | ||
| ) | ||
|
|
||
| // PointerIgnitionConfig generates a config which references the remote config | ||
| // served by the machine config server. | ||
| func PointerIgnitionConfig(installConfig *types.InstallConfig, rootCA []byte, role string) *ignition.Config { | ||
| var ignitionHost string | ||
| CAReferences := []ignition.CaReference{} | ||
| configReference := []ignition.ConfigReference{} | ||
|
|
||
| CAReferences = append(CAReferences, ignition.CaReference{ | ||
| Source: dataurl.EncodeBytes(rootCA), | ||
| }) | ||
|
|
||
| // TODO(egarcia): Move this logic to the master/worker/bootstrap ignition config generation code | ||
| // and add parameters to service it | ||
| if role == "bootstrap" { | ||
| if installConfig.AdditionalTrustBundle != "" { | ||
| CAReferences = append(CAReferences, ignition.CaReference{ | ||
| Source: installConfig.AdditionalTrustBundle, | ||
| }) | ||
| } | ||
| } else { | ||
| switch installConfig.Platform.Name() { | ||
| case baremetaltypes.Name: | ||
| // Baremetal needs to point directly at the VIP because we don't have a | ||
| // way to configure DNS before Ignition runs. | ||
| ignitionHost = fmt.Sprintf("%s:22623", installConfig.BareMetal.APIVIP) | ||
| case openstacktypes.Name: | ||
| apiVIP, err := openstackdefaults.APIVIP(installConfig.Networking) | ||
| if err == nil { | ||
| ignitionHost = fmt.Sprintf("%s:22623", apiVIP.String()) | ||
| } else { | ||
| ignitionHost = fmt.Sprintf("api-int.%s:22623", installConfig.ClusterDomain()) | ||
| } | ||
| default: | ||
| ignitionHost = fmt.Sprintf("api-int.%s:22623", installConfig.ClusterDomain()) | ||
| } | ||
|
|
||
| configReference = []ignition.ConfigReference{{ | ||
| Source: func() *url.URL { | ||
| return &url.URL{ | ||
| Scheme: "https", | ||
| Host: ignitionHost, | ||
| Path: fmt.Sprintf("/config/%s", role), | ||
| } | ||
| }().String(), | ||
| }} | ||
| } | ||
|
|
||
| return &ignition.Config{ | ||
| Ignition: ignition.Ignition{ | ||
| Version: ignition.MaxVersion.String(), | ||
| Config: ignition.IgnitionConfig{ | ||
| Append: configReference, | ||
| }, | ||
| Security: ignition.Security{ | ||
| TLS: ignition.TLS{ | ||
| CertificateAuthorities: CAReferences, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Typo in automatically