-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
master.go
87 lines (71 loc) · 2.07 KB
/
master.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package machine
import (
"context"
"encoding/json"
"os"
igntypes "github.com/coreos/ignition/v2/config/v3_2/types"
"github.com/pkg/errors"
"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/ignition"
"github.com/openshift/installer/pkg/asset/installconfig"
"github.com/openshift/installer/pkg/asset/tls"
)
const (
masterIgnFilename = "master.ign"
)
// Master is an asset that generates the ignition config for master nodes.
type Master struct {
Config *igntypes.Config
File *asset.File
}
var _ asset.WritableAsset = (*Master)(nil)
// Dependencies returns the assets on which the Master asset depends.
func (a *Master) Dependencies() []asset.Asset {
return []asset.Asset{
&installconfig.InstallConfig{},
&tls.RootCA{},
}
}
// Generate generates the ignition config for the Master asset.
func (a *Master) Generate(_ context.Context, dependencies asset.Parents) error {
installConfig := &installconfig.InstallConfig{}
rootCA := &tls.RootCA{}
dependencies.Get(installConfig, rootCA)
a.Config = pointerIgnitionConfig(installConfig.Config, rootCA.Cert(), "master")
data, err := ignition.Marshal(a.Config)
if err != nil {
return errors.Wrap(err, "failed to marshal Ignition config")
}
a.File = &asset.File{
Filename: masterIgnFilename,
Data: data,
}
return nil
}
// Name returns the human-friendly name of the asset.
func (a *Master) Name() string {
return "Master Ignition Config"
}
// Files returns the files generated by the asset.
func (a *Master) Files() []*asset.File {
if a.File != nil {
return []*asset.File{a.File}
}
return []*asset.File{}
}
// Load returns the master ignitions from disk.
func (a *Master) Load(f asset.FileFetcher) (found bool, err error) {
file, err := f.FetchByName(masterIgnFilename)
if err != nil {
if os.IsNotExist(err) {
return false, nil
}
return false, err
}
config := &igntypes.Config{}
if err := json.Unmarshal(file.Data, config); err != nil {
return false, errors.Wrapf(err, "failed to unmarshal %s", masterIgnFilename)
}
a.File, a.Config = file, config
return true, nil
}