github.com/openshift/installer@v1.4.17/pkg/asset/ignition/machine/worker.go (about) 1 package machine 2 3 import ( 4 "context" 5 "encoding/json" 6 "os" 7 8 igntypes "github.com/coreos/ignition/v2/config/v3_2/types" 9 "github.com/pkg/errors" 10 11 "github.com/openshift/installer/pkg/asset" 12 "github.com/openshift/installer/pkg/asset/ignition" 13 "github.com/openshift/installer/pkg/asset/installconfig" 14 "github.com/openshift/installer/pkg/asset/tls" 15 ) 16 17 const ( 18 workerIgnFilename = "worker.ign" 19 ) 20 21 // Worker is an asset that generates the ignition config for worker nodes. 22 type Worker struct { 23 Config *igntypes.Config 24 File *asset.File 25 } 26 27 var _ asset.WritableAsset = (*Worker)(nil) 28 29 // Dependencies returns the assets on which the Worker asset depends. 30 func (a *Worker) Dependencies() []asset.Asset { 31 return []asset.Asset{ 32 &installconfig.InstallConfig{}, 33 &tls.RootCA{}, 34 } 35 } 36 37 // Generate generates the ignition config for the Worker asset. 38 func (a *Worker) Generate(_ context.Context, dependencies asset.Parents) error { 39 installConfig := &installconfig.InstallConfig{} 40 rootCA := &tls.RootCA{} 41 dependencies.Get(installConfig, rootCA) 42 43 a.Config = pointerIgnitionConfig(installConfig.Config, rootCA.Cert(), "worker") 44 45 data, err := ignition.Marshal(a.Config) 46 if err != nil { 47 return errors.Wrap(err, "failed to marshal Ignition config") 48 } 49 a.File = &asset.File{ 50 Filename: workerIgnFilename, 51 Data: data, 52 } 53 54 return nil 55 } 56 57 // Name returns the human-friendly name of the asset. 58 func (a *Worker) Name() string { 59 return "Worker Ignition Config" 60 } 61 62 // Files returns the files generated by the asset. 63 func (a *Worker) Files() []*asset.File { 64 if a.File != nil { 65 return []*asset.File{a.File} 66 } 67 return []*asset.File{} 68 } 69 70 // Load returns the worker ignitions from disk. 71 func (a *Worker) Load(f asset.FileFetcher) (found bool, err error) { 72 file, err := f.FetchByName(workerIgnFilename) 73 if err != nil { 74 if os.IsNotExist(err) { 75 return false, nil 76 } 77 return false, err 78 } 79 80 config := &igntypes.Config{} 81 if err := json.Unmarshal(file.Data, config); err != nil { 82 return false, errors.Wrapf(err, "failed to unmarshal %s", workerIgnFilename) 83 } 84 85 a.File, a.Config = file, config 86 return true, nil 87 }