1
0
mirror of https://github.com/openshift/installer.git synced 2026-02-05 15:47:14 +01:00

add agent workflow asset

This commit is contained in:
Andrea Fasano
2024-02-08 08:47:10 -05:00
parent 0481a93111
commit fa469ccc4d
3 changed files with 107 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
package workflow
import (
"fmt"
"os"
"github.com/openshift/installer/pkg/asset"
"github.com/pkg/errors"
)
// AgentWorkflow allows other assets to check
// which is the workflow currently active
type AgentWorkflow struct {
File *asset.File
Workflow AgentWorkflowType
}
var _ asset.WritableAsset = (*AgentWorkflow)(nil)
// Name returns a human friendly name for the asset.
func (*AgentWorkflow) Name() string {
return "Agent Workflow"
}
// Dependencies returns all of the dependencies directly needed to generate
// the asset.
func (*AgentWorkflow) Dependencies() []asset.Asset {
return []asset.Asset{}
}
// Generate generates the AgentWorkflow asset.
func (a *AgentWorkflow) Generate(dependencies asset.Parents) error {
// Set install workflow as a default
a.Workflow = AgentWorkflowTypeInstall
a.File = &asset.File{
Filename: agentWorkflowFilename,
Data: []byte(a.Workflow),
}
return nil
}
// Files returns the files generated by the asset.
func (a *AgentWorkflow) Files() []*asset.File {
if a.File != nil {
return []*asset.File{a.File}
}
return []*asset.File{}
}
// Load returns the asset from disk.
func (a *AgentWorkflow) Load(f asset.FileFetcher) (bool, error) {
file, err := f.FetchByName(agentWorkflowFilename)
if err != nil {
if os.IsNotExist(err) {
return false, nil
}
return false, errors.Wrap(err, fmt.Sprintf("failed to load %s file", agentWorkflowFilename))
}
// Get the current workflow
a.Workflow = AgentWorkflowType(file.Data)
a.File = file
return true, nil
}

View File

@@ -0,0 +1,28 @@
package workflow
import "github.com/openshift/installer/pkg/asset"
// AgentWorkflowAddNodes is meant just to define
// the add nodes workflow
type AgentWorkflowAddNodes struct {
AgentWorkflow
}
var _ asset.WritableAsset = (*AgentWorkflowAddNodes)(nil)
// Name returns a human friendly name for the asset.
func (*AgentWorkflowAddNodes) Name() string {
return "Agent Workflow Add Nodes"
}
// Generate generates the AgentWorkflow asset.
func (a *AgentWorkflowAddNodes) Generate(dependencies asset.Parents) error {
a.Workflow = AgentWorkflowTypeAddNodes
a.File = &asset.File{
Filename: agentWorkflowFilename,
Data: []byte(a.Workflow),
}
return nil
}

View File

@@ -0,0 +1,12 @@
package workflow
// AgentWorkflowType defines the supported
// agent workflows.
type AgentWorkflowType string
const (
AgentWorkflowTypeInstall AgentWorkflowType = "install"
AgentWorkflowTypeAddNodes AgentWorkflowType = "addnodes"
agentWorkflowFilename = ".agentworkflow"
)