forked from openshift/installer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a machineconfig for IPI pointer ignition customizations
In the case where an IPI user customizes the pointer config, this config is only persisted via the user-data secret, which was an issue when moving to an MCO templated pointer config: openshift#4228 It was also a problem for attempts for IPI baremetal to consume the MCO rendered config directly, with the aim of enabling network configuration via MachineConfig: openshift#3589 With this new approach, we detect the case where a change has been made to the pointer config by the user, and in that case it is stored via a MachineConfig manifest, such that any customizations are reflected in the MCO rendered config. Implements: openshift/enhancements#540 Co-Authored-By: Steven Hardy <[email protected]>
- Loading branch information
1 parent
26514dc
commit bbc9f67
Showing
7 changed files
with
309 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
84 changes: 84 additions & 0 deletions
84
pkg/asset/ignition/machine/master_ignition_customizations.go
This file contains 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,84 @@ | ||
package machine | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"github.com/ghodss/yaml" | ||
"github.com/pkg/errors" | ||
"github.com/sirupsen/logrus" | ||
|
||
"github.com/openshift/installer/pkg/asset" | ||
"github.com/openshift/installer/pkg/asset/installconfig" | ||
"github.com/openshift/installer/pkg/asset/tls" | ||
mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" | ||
) | ||
|
||
var ( | ||
masterMachineConfigFileName = filepath.Join(directory, "99_openshift-installer-ignition_master.yaml") | ||
) | ||
|
||
// MasterIgnitionCustomizations 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 MasterIgnitionCustomizations struct { | ||
File *asset.File | ||
} | ||
|
||
var _ asset.WritableAsset = (*MasterIgnitionCustomizations)(nil) | ||
|
||
// Dependencies returns the dependencies for MasterIgnitionCustomizations | ||
func (a *MasterIgnitionCustomizations) Dependencies() []asset.Asset { | ||
return []asset.Asset{ | ||
&installconfig.InstallConfig{}, | ||
&tls.RootCA{}, | ||
&Master{}, | ||
} | ||
} | ||
|
||
// Generate queries for input from the user. | ||
func (a *MasterIgnitionCustomizations) Generate(dependencies asset.Parents) error { | ||
installConfig := &installconfig.InstallConfig{} | ||
rootCA := &tls.RootCA{} | ||
master := &Master{} | ||
dependencies.Get(installConfig, rootCA, master) | ||
|
||
defaultPointerIgnition := pointerIgnitionConfig(installConfig.Config, rootCA.Cert(), "master") | ||
savedPointerIgnition := master.Config | ||
|
||
if savedPointerIgnition != defaultPointerIgnition { | ||
logrus.Infof("Master pointer ignition was modified. Saving contents to a machineconfig") | ||
mc := &mcfgv1.MachineConfig{} | ||
mc, err := generatePointerMachineConfig(*savedPointerIgnition, "master") | ||
if err != nil { | ||
return errors.Wrap(err, "failed to generate master installer machineconfig") | ||
} | ||
configData, err := yaml.Marshal(mc) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to marshal master installer machineconfig") | ||
} | ||
a.File = &asset.File{ | ||
Filename: masterMachineConfigFileName, | ||
Data: configData, | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// Name returns the human-friendly name of the asset. | ||
func (a *MasterIgnitionCustomizations) Name() string { | ||
return "Master Ignition Customization Check" | ||
} | ||
|
||
// Files returns the files generated by the asset. | ||
func (a *MasterIgnitionCustomizations) 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 *MasterIgnitionCustomizations) Load(f asset.FileFetcher) (found bool, err error) { | ||
return false, nil | ||
} |
50 changes: 50 additions & 0 deletions
50
pkg/asset/ignition/machine/master_ignition_customizations_test.go
This file contains 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,50 @@ | ||
package machine | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/openshift/installer/pkg/asset" | ||
"github.com/openshift/installer/pkg/asset/installconfig" | ||
"github.com/openshift/installer/pkg/asset/tls" | ||
"github.com/openshift/installer/pkg/ipnet" | ||
"github.com/openshift/installer/pkg/types" | ||
"github.com/openshift/installer/pkg/types/aws" | ||
) | ||
|
||
// TestMasterIgnitionCustomizationsGenerate tests generating the master ignition check asset. | ||
func TestMasterIgnitionCustomizationsGenerate(t *testing.T) { | ||
installConfig := &installconfig.InstallConfig{ | ||
Config: &types.InstallConfig{ | ||
Networking: &types.Networking{ | ||
ServiceNetwork: []ipnet.IPNet{*ipnet.MustParseCIDR("10.0.1.0/24")}, | ||
}, | ||
Platform: types.Platform{ | ||
AWS: &aws.Platform{ | ||
Region: "us-east", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
rootCA := &tls.RootCA{} | ||
err := rootCA.Generate(nil) | ||
assert.NoError(t, err, "unexpected error generating root CA") | ||
|
||
parents := asset.Parents{} | ||
parents.Add(installConfig, rootCA) | ||
|
||
master := &Master{} | ||
err = master.Generate(parents) | ||
assert.NoError(t, err, "unexpected error generating master asset") | ||
|
||
parents.Add(master) | ||
masterIgnCheck := &MasterIgnitionCustomizations{} | ||
err = masterIgnCheck.Generate(parents) | ||
assert.NoError(t, err, "unexpected error generating master ignition check asset") | ||
|
||
actualFiles := masterIgnCheck.Files() | ||
assert.Equal(t, 1, len(actualFiles), "unexpected number of files in master state") | ||
assert.Equal(t, masterMachineConfigFileName, actualFiles[0].Filename, "unexpected name for master ignition config") | ||
} |
This file contains 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
85 changes: 85 additions & 0 deletions
85
pkg/asset/ignition/machine/worker_ignition_customizations.go
This file contains 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 machine | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"github.com/ghodss/yaml" | ||
"github.com/pkg/errors" | ||
"github.com/sirupsen/logrus" | ||
|
||
"github.com/openshift/installer/pkg/asset" | ||
"github.com/openshift/installer/pkg/asset/installconfig" | ||
"github.com/openshift/installer/pkg/asset/tls" | ||
mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" | ||
) | ||
|
||
var ( | ||
workerMachineConfigFileName = filepath.Join(directory, "99_openshift-installer-ignition_worker.yaml") | ||
) | ||
|
||
// WorkerIgnitionCustomizations 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 WorkerIgnitionCustomizations struct { | ||
File *asset.File | ||
} | ||
|
||
var _ asset.WritableAsset = (*WorkerIgnitionCustomizations)(nil) | ||
|
||
// Dependencies returns the dependencies for WorkerIgnitionCustomizations | ||
func (a *WorkerIgnitionCustomizations) Dependencies() []asset.Asset { | ||
return []asset.Asset{ | ||
&installconfig.InstallConfig{}, | ||
&tls.RootCA{}, | ||
&Worker{}, | ||
} | ||
} | ||
|
||
// Generate queries for input from the user. | ||
func (a *WorkerIgnitionCustomizations) Generate(dependencies asset.Parents) error { | ||
installConfig := &installconfig.InstallConfig{} | ||
rootCA := &tls.RootCA{} | ||
worker := &Worker{} | ||
dependencies.Get(installConfig, rootCA, worker) | ||
|
||
defaultPointerIgnition := pointerIgnitionConfig(installConfig.Config, rootCA.Cert(), "worker") | ||
savedPointerIgnition := worker.Config | ||
|
||
// Create a machineconfig if the ignition has been modified | ||
if savedPointerIgnition != defaultPointerIgnition { | ||
logrus.Infof("Worker pointer ignition was modified. Saving contents to a machineconfig") | ||
mc := &mcfgv1.MachineConfig{} | ||
mc, err := generatePointerMachineConfig(*savedPointerIgnition, "worker") | ||
if err != nil { | ||
return errors.Wrap(err, "failed to generate worker installer machineconfig") | ||
} | ||
configData, err := yaml.Marshal(mc) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to marshal worker installer machineconfig") | ||
} | ||
a.File = &asset.File{ | ||
Filename: workerMachineConfigFileName, | ||
Data: configData, | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// Name returns the human-friendly name of the asset. | ||
func (a *WorkerIgnitionCustomizations) Name() string { | ||
return "Worker Ignition Customization Check" | ||
} | ||
|
||
// Files returns the files generated by the asset. | ||
func (a *WorkerIgnitionCustomizations) 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 *WorkerIgnitionCustomizations) Load(f asset.FileFetcher) (found bool, err error) { | ||
return false, nil | ||
} |
50 changes: 50 additions & 0 deletions
50
pkg/asset/ignition/machine/worker_ignition_customizations_test.go
This file contains 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,50 @@ | ||
package machine | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/openshift/installer/pkg/asset" | ||
"github.com/openshift/installer/pkg/asset/installconfig" | ||
"github.com/openshift/installer/pkg/asset/tls" | ||
"github.com/openshift/installer/pkg/ipnet" | ||
"github.com/openshift/installer/pkg/types" | ||
"github.com/openshift/installer/pkg/types/aws" | ||
) | ||
|
||
// TestWorkerIgnitionCustomizationsGenerate tests generating the worker ignition check asset. | ||
func TestWorkerIgnitionCustomizationsGenerate(t *testing.T) { | ||
installConfig := &installconfig.InstallConfig{ | ||
Config: &types.InstallConfig{ | ||
Networking: &types.Networking{ | ||
ServiceNetwork: []ipnet.IPNet{*ipnet.MustParseCIDR("10.0.1.0/24")}, | ||
}, | ||
Platform: types.Platform{ | ||
AWS: &aws.Platform{ | ||
Region: "us-east", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
rootCA := &tls.RootCA{} | ||
err := rootCA.Generate(nil) | ||
assert.NoError(t, err, "unexpected error generating root CA") | ||
|
||
parents := asset.Parents{} | ||
parents.Add(installConfig, rootCA) | ||
|
||
worker := &Worker{} | ||
err = worker.Generate(parents) | ||
assert.NoError(t, err, "unexpected error generating worker asset") | ||
|
||
parents.Add(worker) | ||
workerIgnCheck := &WorkerIgnitionCustomizations{} | ||
err = workerIgnCheck.Generate(parents) | ||
assert.NoError(t, err, "unexpected error generating worker ignition check asset") | ||
|
||
actualFiles := workerIgnCheck.Files() | ||
assert.Equal(t, 1, len(actualFiles), "unexpected number of files in worker state") | ||
assert.Equal(t, workerMachineConfigFileName, actualFiles[0].Filename, "unexpected name for worker ignition config") | ||
} |
This file contains 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