forked from openshift/installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manifest.go
67 lines (58 loc) · 1.55 KB
/
manifest.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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(filename string) (bool, error) {
matched, err := filepath.Match(machineConfigFileNamePattern, filename)
if err != nil {
return false, err
}
return matched, nil
}
// 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
}