|
| 1 | +package workflow |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "os" |
| 6 | + |
| 7 | + "github.com/openshift/installer/pkg/asset" |
| 8 | + "github.com/pkg/errors" |
| 9 | +) |
| 10 | + |
| 11 | +// AgentWorkflow allows other assets to check |
| 12 | +// which is the workflow currently active |
| 13 | +type AgentWorkflow struct { |
| 14 | + File *asset.File |
| 15 | + Workflow AgentWorkflowType |
| 16 | +} |
| 17 | + |
| 18 | +var _ asset.WritableAsset = (*AgentWorkflow)(nil) |
| 19 | + |
| 20 | +// Name returns a human friendly name for the asset. |
| 21 | +func (*AgentWorkflow) Name() string { |
| 22 | + return "Agent Workflow" |
| 23 | +} |
| 24 | + |
| 25 | +// Dependencies returns all of the dependencies directly needed to generate |
| 26 | +// the asset. |
| 27 | +func (*AgentWorkflow) Dependencies() []asset.Asset { |
| 28 | + return []asset.Asset{} |
| 29 | +} |
| 30 | + |
| 31 | +// Generate generates the AgentWorkflow asset. |
| 32 | +func (a *AgentWorkflow) Generate(dependencies asset.Parents) error { |
| 33 | + |
| 34 | + // Set install workflow as a default |
| 35 | + a.Workflow = AgentWorkflowTypeInstall |
| 36 | + a.File = &asset.File{ |
| 37 | + Filename: agentWorkflowFilename, |
| 38 | + Data: []byte(a.Workflow), |
| 39 | + } |
| 40 | + |
| 41 | + return nil |
| 42 | +} |
| 43 | + |
| 44 | +// Files returns the files generated by the asset. |
| 45 | +func (a *AgentWorkflow) Files() []*asset.File { |
| 46 | + if a.File != nil { |
| 47 | + return []*asset.File{a.File} |
| 48 | + } |
| 49 | + return []*asset.File{} |
| 50 | +} |
| 51 | + |
| 52 | +// Load returns the asset from disk. |
| 53 | +func (a *AgentWorkflow) Load(f asset.FileFetcher) (bool, error) { |
| 54 | + file, err := f.FetchByName(agentWorkflowFilename) |
| 55 | + if err != nil { |
| 56 | + if os.IsNotExist(err) { |
| 57 | + return false, nil |
| 58 | + } |
| 59 | + return false, errors.Wrap(err, fmt.Sprintf("failed to load %s file", agentWorkflowFilename)) |
| 60 | + } |
| 61 | + |
| 62 | + // Get the current workflow |
| 63 | + a.Workflow = AgentWorkflowType(file.Data) |
| 64 | + a.File = file |
| 65 | + |
| 66 | + return true, nil |
| 67 | +} |
0 commit comments