Skip to content

Commit fa469cc

Browse files
committed
add agent workflow asset
1 parent 0481a93 commit fa469cc

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package workflow
2+
3+
import "github.com/openshift/installer/pkg/asset"
4+
5+
// AgentWorkflowAddNodes is meant just to define
6+
// the add nodes workflow
7+
type AgentWorkflowAddNodes struct {
8+
AgentWorkflow
9+
}
10+
11+
var _ asset.WritableAsset = (*AgentWorkflowAddNodes)(nil)
12+
13+
// Name returns a human friendly name for the asset.
14+
func (*AgentWorkflowAddNodes) Name() string {
15+
return "Agent Workflow Add Nodes"
16+
}
17+
18+
// Generate generates the AgentWorkflow asset.
19+
func (a *AgentWorkflowAddNodes) Generate(dependencies asset.Parents) error {
20+
21+
a.Workflow = AgentWorkflowTypeAddNodes
22+
a.File = &asset.File{
23+
Filename: agentWorkflowFilename,
24+
Data: []byte(a.Workflow),
25+
}
26+
27+
return nil
28+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package workflow
2+
3+
// AgentWorkflowType defines the supported
4+
// agent workflows.
5+
type AgentWorkflowType string
6+
7+
const (
8+
AgentWorkflowTypeInstall AgentWorkflowType = "install"
9+
AgentWorkflowTypeAddNodes AgentWorkflowType = "addnodes"
10+
11+
agentWorkflowFilename = ".agentworkflow"
12+
)

0 commit comments

Comments
 (0)