-
Notifications
You must be signed in to change notification settings - Fork 1.5k
OCPEDGE-1310: feat: add arbiter node support to installer #9159
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
Merged
Merged
Changes from all commits
Commits
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
1,099 changes: 1,099 additions & 0 deletions
1,099
data/data/install.openshift.io_installconfigs.yaml
Large diffs are not rendered by default.
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
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,92 @@ | ||
| package machine | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
| "os" | ||
|
|
||
| igntypes "github.com/coreos/ignition/v2/config/v3_2/types" | ||
|
|
||
| "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 ( | ||
| arbiterIgnFilename = "arbiter.ign" | ||
| ) | ||
|
|
||
| // Arbiter is an asset that generates the ignition config for arbiter nodes. | ||
| type Arbiter struct { | ||
| Config *igntypes.Config | ||
| File *asset.File | ||
| } | ||
|
|
||
| var _ asset.WritableAsset = (*Arbiter)(nil) | ||
|
|
||
| // Dependencies returns the assets on which the Arbiter asset depends. | ||
| func (a *Arbiter) Dependencies() []asset.Asset { | ||
| return []asset.Asset{ | ||
| &installconfig.InstallConfig{}, | ||
| &tls.RootCA{}, | ||
| } | ||
| } | ||
|
|
||
| // Generate generates the ignition config for the Arbiter asset. | ||
| func (a *Arbiter) Generate(_ context.Context, dependencies asset.Parents) error { | ||
| installConfig := &installconfig.InstallConfig{} | ||
| rootCA := &tls.RootCA{} | ||
| dependencies.Get(installConfig, rootCA) | ||
|
|
||
| // Avoid creating ignition files when not an arbiter deployment. | ||
| if !installConfig.Config.IsArbiterEnabled() { | ||
| return nil | ||
| } | ||
|
|
||
| a.Config = pointerIgnitionConfig(installConfig.Config, rootCA.Cert(), "arbiter") | ||
|
|
||
| data, err := ignition.Marshal(a.Config) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to marshal Ignition config: %w", err) | ||
| } | ||
| a.File = &asset.File{ | ||
| Filename: arbiterIgnFilename, | ||
| Data: data, | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // Name returns the human-friendly name of the asset. | ||
| func (a *Arbiter) Name() string { | ||
| return "Arbiter Ignition Config" | ||
| } | ||
|
|
||
| // Files returns the files generated by the asset. | ||
| func (a *Arbiter) Files() []*asset.File { | ||
| if a.File != nil { | ||
| return []*asset.File{a.File} | ||
| } | ||
| return []*asset.File{} | ||
| } | ||
|
|
||
| // Load returns the arbiter ignitions from disk. | ||
| func (a *Arbiter) Load(f asset.FileFetcher) (found bool, err error) { | ||
| file, err := f.FetchByName(arbiterIgnFilename) | ||
| 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, fmt.Errorf("failed to unmarshal %s: %w", arbiterIgnFilename, err) | ||
| } | ||
|
|
||
| a.File, a.Config = file, config | ||
| return true, nil | ||
| } |
97 changes: 97 additions & 0 deletions
97
pkg/asset/ignition/machine/arbiter_ignition_customizations.go
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,97 @@ | ||
| package machine | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "path/filepath" | ||
|
|
||
| "github.com/sirupsen/logrus" | ||
| "sigs.k8s.io/yaml" | ||
|
|
||
| "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" | ||
| ) | ||
|
|
||
| var ( | ||
| arbiterMachineConfigFileName = filepath.Join(directory, "99_openshift-installer-arbiter.yaml") | ||
| ) | ||
|
|
||
| // ArbiterIgnitionCustomizations is an asset that checks for any customizations a user might | ||
| // have made to the pointer ignition configs before creating the cluster. If customizations | ||
| // are made, then the updates are reconciled as a MachineConfig file. | ||
| type ArbiterIgnitionCustomizations struct { | ||
| File *asset.File | ||
| } | ||
|
|
||
| var _ asset.WritableAsset = (*ArbiterIgnitionCustomizations)(nil) | ||
|
|
||
| // Dependencies returns the dependencies for ArbiterIgnitionCustomizations. | ||
| func (a *ArbiterIgnitionCustomizations) Dependencies() []asset.Asset { | ||
| return []asset.Asset{ | ||
| &installconfig.InstallConfig{}, | ||
| &tls.RootCA{}, | ||
| &Arbiter{}, | ||
| } | ||
| } | ||
|
|
||
| // Generate queries for input from the user. | ||
| func (a *ArbiterIgnitionCustomizations) Generate(_ context.Context, dependencies asset.Parents) error { | ||
| installConfig := &installconfig.InstallConfig{} | ||
| rootCA := &tls.RootCA{} | ||
| arbiter := &Arbiter{} | ||
| dependencies.Get(installConfig, rootCA, arbiter) | ||
|
|
||
| // Avoid creating ignition customizations when not an arbiter deployment. | ||
| if !installConfig.Config.IsArbiterEnabled() { | ||
| return nil | ||
| } | ||
|
|
||
| defaultPointerIgnition := pointerIgnitionConfig(installConfig.Config, rootCA.Cert(), "arbiter") | ||
| savedPointerIgnition := arbiter.Config | ||
|
|
||
| savedPointerIgnitionJSON, err := ignition.Marshal(savedPointerIgnition) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to Marshal savedPointerIgnition: %w", err) | ||
| } | ||
| defaultPointerIgnitionJSON, err := ignition.Marshal(defaultPointerIgnition) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to Marshal defaultPointerIgnition: %w", err) | ||
| } | ||
| if string(savedPointerIgnitionJSON) != string(defaultPointerIgnitionJSON) { | ||
| logrus.Infof("Arbiter pointer ignition was modified. Saving contents to a machineconfig") | ||
| mc, err := generatePointerMachineConfig(*savedPointerIgnition, "arbiter") | ||
| if err != nil { | ||
| return fmt.Errorf("failed to generate arbiter installer machineconfig: %w", err) | ||
| } | ||
| configData, err := yaml.Marshal(mc) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to marshal arbiter installer machineconfig: %w", err) | ||
| } | ||
| a.File = &asset.File{ | ||
| Filename: arbiterMachineConfigFileName, | ||
| Data: configData, | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // Name returns the human-friendly name of the asset. | ||
| func (a *ArbiterIgnitionCustomizations) Name() string { | ||
| return "Arbiter Ignition Customization Check" | ||
| } | ||
|
|
||
| // Files returns the files generated by the asset. | ||
| func (a *ArbiterIgnitionCustomizations) Files() []*asset.File { | ||
| if a.File != nil { | ||
| return []*asset.File{a.File} | ||
| } | ||
| return []*asset.File{} | ||
| } | ||
|
|
||
| // Load does nothing, since we consume the ignition-configs. | ||
| func (a *ArbiterIgnitionCustomizations) Load(f asset.FileFetcher) (found bool, err error) { | ||
| return false, nil | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.