Skip to content
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

MGMT-3580 Can't set requested hostname for SNO #166

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/ignition/ignition.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package ignition

import (
"encoding/json"
"io/ioutil"

"github.com/coreos/ignition/v2/config/validate"

config_31 "github.com/coreos/ignition/v2/config/v3_1"
config_31_types "github.com/coreos/ignition/v2/config/v3_1/types"

"github.com/pkg/errors"
)

// ParseIgnitionFile reads an ignition config from a given path on disk
func ParseIgnitionFile(path string) (*config_31_types.Config, error) {
configBytes, err := ioutil.ReadFile(path)
if err != nil {
return nil, errors.Errorf("error reading file %s: %v", path, err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you use errors.Wrapf?
Does %v on error give some extra data?

}
config, _, err := config_31.Parse(configBytes)
if err != nil {
return nil, errors.Errorf("error parsing ignition: %v", err)
}
return &config, nil
}

// WriteIgnitionFile writes an ignition config to a given path on disk
func WriteIgnitionFile(path string, config *config_31_types.Config) error {
updatedBytes, err := json.Marshal(config)
if err != nil {
return err
}
err = ioutil.WriteFile(path, updatedBytes, 0600)
if err != nil {
return errors.Wrapf(err, "error writing file %s", path)
}
return nil
}

// MergeIgnitionConfig merges the specified configs and check the result is a valid Ignition config
func MergeIgnitionConfig(base *config_31_types.Config, overrides *config_31_types.Config) (*config_31_types.Config, error) {
config := config_31.Merge(*base, *overrides)
report := validate.ValidateWithContext(config, nil)
if report.IsFatal() {
return &config, errors.Errorf("merged ignition config is invalid: %s", report.String())
}
return &config, nil
}
38 changes: 37 additions & 1 deletion src/installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ import (
"golang.org/x/sync/errgroup"
v1 "k8s.io/api/core/v1"

config_31_types "github.com/coreos/ignition/v2/config/v3_1/types"

"github.com/openshift/assisted-installer/src/common"
"github.com/openshift/assisted-installer/src/config"
"github.com/openshift/assisted-installer/src/ignition"
"github.com/openshift/assisted-installer/src/inventory_client"
"github.com/openshift/assisted-installer/src/k8s_client"
"github.com/openshift/assisted-installer/src/ops"
Expand Down Expand Up @@ -103,7 +106,6 @@ func (i *installer) InstallNode() error {
if err != nil {
return err
}
i.Config.Role = string(models.HostRoleMaster)
} else {
ignitionPath, err = i.downloadHostIgnition()
if err != nil {
Expand Down Expand Up @@ -133,6 +135,34 @@ func (i *installer) InstallNode() error {
return nil
}

//updateSingleNodeIgnition will download the host ignition config and add the files under storage
func (i *installer) updateSingleNodeIgnition(singleNodeIgnitionPath string) error {
hostIgnitionPath, err := i.downloadHostIgnition()
if err != nil {
return err
}
singleNodeconfig, err := ignition.ParseIgnitionFile(singleNodeIgnitionPath)
if err != nil {
return err
}
hostConfig, err := ignition.ParseIgnitionFile(hostIgnitionPath)
if err != nil {
return err
}
// TODO: update this once we can get the full host specific overrides we have in the ignition
// Remove the Config part since we only want the rest of the overrides
hostConfig.Ignition.Config = config_31_types.IgnitionConfig{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 nice

merged, mergeErr := ignition.MergeIgnitionConfig(singleNodeconfig, hostConfig)
if mergeErr != nil {
return errors.Wrapf(mergeErr, "failed to apply host ignition config overrides")
}
err = ignition.WriteIgnitionFile(singleNodeIgnitionPath, merged)
if err != nil {
return err
}
return nil
}

func (i *installer) writeImageToDisk(ignitionPath string) error {
i.UpdateHostInstallProgress(models.HostStageWritingImageToDisk, "")
interval := time.Second
Expand Down Expand Up @@ -621,6 +651,12 @@ func (i *installer) createSingleNodeMasterIgnition() (string, error) {
i.log.Errorf("Failed to find single node master ignition: %s", err)
return "", err
}
i.Config.Role = string(models.HostRoleMaster)
err = i.updateSingleNodeIgnition(singleNodeMasterIgnitionPath)
if err != nil {
return "", err
}

return singleNodeMasterIgnitionPath, nil
}

Expand Down