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

[release-4.3] Bug 1822750: [ctrcfg controller] Use a struct array instead of map when creating new ignitions #1645

Merged
merged 1 commit into from
Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -548,9 +548,10 @@ func (ctrl *Controller) syncContainerRuntimeConfig(key string) error {
tempIgnCfg := ctrlcommon.NewIgnConfig()
mc = mtmpl.MachineConfigFromIgnConfig(role, managedKey, &tempIgnCfg)
}
mc.Spec.Config = createNewIgnition(map[string][]byte{
storageConfigPath: storageTOML,
crioConfigPath: crioTOML,

mc.Spec.Config = createNewIgnition([]ignitionConfig{
{filePath: storageConfigPath, data: storageTOML},
{filePath: crioConfigPath, data: crioTOML},
})

mc.SetAnnotations(map[string]string{
Expand Down Expand Up @@ -750,9 +751,9 @@ func registriesConfigIgnition(templateDir string, controllerConfig *mcfgv1.Contr
return nil, fmt.Errorf("could not update policy json with new changes: %v", err)
}
}
registriesIgn := createNewIgnition(map[string][]byte{
registriesConfigPath: registriesTOML,
policyConfigPath: policyJSON,
registriesIgn := createNewIgnition([]ignitionConfig{
{filePath: registriesConfigPath, data: registriesTOML},
{filePath: policyConfigPath, data: policyJSON},
})
return &registriesIgn, nil
}
Expand Down
18 changes: 13 additions & 5 deletions pkg/controller/container-runtime-config/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,34 @@ type tomlConfigCRIO struct {
} `toml:"crio"`
}

// ignitionConfig is a struct that holds the filepath and date of the various configs
// Using a struct array ensures that the order of the ignition files always stay the same
// ensuring that double MCs are not created due to a change in the order
type ignitionConfig struct {
filePath string
data []byte
}

type updateConfigFunc func(data []byte, internal *mcfgv1.ContainerRuntimeConfiguration) ([]byte, error)

// createNewIgnition takes a map where the key is the path of the file, and the value is the
// new data in the form of a byte array. The function returns the ignition config with the
// updated data.
func createNewIgnition(configs map[string][]byte) igntypes.Config {
func createNewIgnition(configs []ignitionConfig) igntypes.Config {
tempIgnConfig := ctrlcommon.NewIgnConfig()
mode := 0644
// Create ignitions
for filePath, data := range configs {
for _, ignConf := range configs {
// If the file is not included, the data will be nil so skip over
if data == nil {
if ignConf.data == nil {
continue
}
configdu := dataurl.New(data, "text/plain")
configdu := dataurl.New(ignConf.data, "text/plain")
configdu.Encoding = dataurl.EncodingASCII
configTempFile := igntypes.File{
Node: igntypes.Node{
Filesystem: "root",
Path: filePath,
Path: ignConf.filePath,
},
FileEmbedded1: igntypes.FileEmbedded1{
Mode: &mode,
Expand Down