github.com/openshift/installer@v1.4.17/pkg/asset/agent/workflow/agentworkflow.go (about)

     1  package workflow
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"os"
     7  
     8  	"github.com/openshift/installer/pkg/asset"
     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(_ context.Context, dependencies asset.Parents) error {
    33  	// Set install workflow as a default
    34  	a.Workflow = AgentWorkflowTypeInstall
    35  	a.File = &asset.File{
    36  		Filename: agentWorkflowFilename,
    37  		Data:     []byte(a.Workflow),
    38  	}
    39  
    40  	return nil
    41  }
    42  
    43  // Files returns the files generated by the asset.
    44  func (a *AgentWorkflow) Files() []*asset.File {
    45  	if a.File != nil {
    46  		return []*asset.File{a.File}
    47  	}
    48  	return []*asset.File{}
    49  }
    50  
    51  // Load returns the asset from disk.
    52  func (a *AgentWorkflow) Load(f asset.FileFetcher) (bool, error) {
    53  	file, err := f.FetchByName(agentWorkflowFilename)
    54  	if err != nil {
    55  		if os.IsNotExist(err) {
    56  			return false, nil
    57  		}
    58  		return false, fmt.Errorf("failed to load %s file: %w", agentWorkflowFilename, err)
    59  	}
    60  
    61  	// Get the current workflow
    62  	a.Workflow = AgentWorkflowType(file.Data)
    63  	a.File = file
    64  
    65  	return true, nil
    66  }