github.com/openshift/installer@v1.4.17/pkg/asset/machines/machineconfig/manifest.go (about) 1 package machineconfig 2 3 import ( 4 "fmt" 5 "path/filepath" 6 7 "sigs.k8s.io/yaml" 8 9 mcfgv1 "github.com/openshift/api/machineconfiguration/v1" 10 "github.com/openshift/installer/pkg/asset" 11 ) 12 13 const ( 14 machineConfigFileName = "99_openshift-machineconfig_%s.yaml" 15 ) 16 17 var ( 18 machineConfigFileNamePattern = fmt.Sprintf(machineConfigFileName, "*") 19 ) 20 21 // Manifests creates manifest files containing the MachineConfigs. 22 func Manifests(configs []*mcfgv1.MachineConfig, role, directory string) ([]*asset.File, error) { 23 var ret []*asset.File 24 for _, c := range configs { 25 if c == nil { 26 continue 27 } 28 configData, err := yaml.Marshal(c) 29 if err != nil { 30 return nil, err 31 } 32 ret = append(ret, &asset.File{ 33 // Note that we should always be generating the role name in our MCs, 34 // but just to ensure uniqueness we add the array index and the role too. 35 Filename: filepath.Join(directory, fmt.Sprintf(machineConfigFileName, c.ObjectMeta.Name)), 36 Data: configData, 37 }) 38 } 39 if len(ret) == 0 { 40 return nil, nil 41 } 42 return ret, nil 43 } 44 45 // IsManifest tests whether the specified filename is a MachineConfig manifest. 46 func IsManifest(filename string) (bool, error) { 47 matched, err := filepath.Match(machineConfigFileNamePattern, filename) 48 if err != nil { 49 return false, err 50 } 51 return matched, nil 52 } 53 54 // Load loads the MachineConfig manifests. 55 func Load(f asset.FileFetcher, role, directory string) ([]*asset.File, error) { 56 return f.FetchByPattern(filepath.Join(directory, machineConfigFileNamePattern)) 57 }