Skip to content

Commit

Permalink
asset/machines: add manifests for MachineConfig
Browse files Browse the repository at this point in the history
Provide the means by which a machines asset can add MachineConfig manifests.
This is needed so that the ignition configs can be supplemented for machine pools for example have hyperthreading disabled, include
authorized_keys for user.
  • Loading branch information
abhinavdahiya committed Mar 27, 2019
1 parent 3e15d4f commit 8683b8e
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions pkg/asset/machines/machineconfig/manifest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package machineconfig

import (
"fmt"
"os"
"path/filepath"

"github.com/ghodss/yaml"

mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"

"github.com/openshift/installer/pkg/asset"
)

const (
machineConfigFileName = "99_openshift-machineconfig_%s.yaml"
)

var (
machineConfigFileNamePattern = fmt.Sprintf(machineConfigFileName, "*")
)

// Manifests creates manifest files containing the MachineConfigs.
func Manifests(configs []*mcfgv1.MachineConfig, role, directory string) ([]*asset.File, error) {
data := []byte{}
for _, c := range configs {
if c == nil {
continue
}
configData, err := yaml.Marshal(c)
if err != nil {
return nil, err
}
data = append(data, []byte("---\n")...)
data = append(data, configData...)
}
if len(data) == 0 {
return nil, nil
}
return []*asset.File{
{
Filename: filepath.Join(directory, fmt.Sprintf(machineConfigFileName, role)),
Data: data,
},
}, nil
}

// IsManifest tests whether the specified filename is a MachineConfig manifest.
func IsManifest(role, filename string) bool {
return fmt.Sprintf(machineConfigFileName, role) == filename
}

// Load loads the MachineConfig manifests.
func Load(f asset.FileFetcher, role, directory string) ([]*asset.File, error) {
file, err := f.FetchByName(filepath.Join(directory, fmt.Sprintf(machineConfigFileName, role)))
if err != nil {
if os.IsNotExist(err) {
return nil, nil
}
return nil, err
}
return []*asset.File{file}, nil
}

0 comments on commit 8683b8e

Please sign in to comment.