github.com/openshift/installer@v1.4.17/pkg/nodejoiner/addnodes.go (about)

     1  package nodejoiner
     2  
     3  import (
     4  	"context"
     5  	"os"
     6  	"path/filepath"
     7  
     8  	"github.com/openshift/installer/pkg/asset"
     9  	"github.com/openshift/installer/pkg/asset/agent/image"
    10  	"github.com/openshift/installer/pkg/asset/agent/joiner"
    11  	"github.com/openshift/installer/pkg/asset/agent/workflow"
    12  	"github.com/openshift/installer/pkg/asset/store"
    13  )
    14  
    15  const (
    16  	addNodesResultFile = "exit_code"
    17  )
    18  
    19  // NewAddNodesCommand creates a new command for add nodes.
    20  func NewAddNodesCommand(directory string, kubeConfig string) error {
    21  	err := saveParams(directory, kubeConfig)
    22  	if err != nil {
    23  		return err
    24  	}
    25  
    26  	fetcher := store.NewAssetsFetcher(directory)
    27  	err = fetcher.FetchAndPersist(context.Background(), []asset.WritableAsset{
    28  		&workflow.AgentWorkflowAddNodes{},
    29  		&image.AgentImage{},
    30  	})
    31  
    32  	// Save the exit code result
    33  	exitCode := "0"
    34  	if err != nil {
    35  		exitCode = "1"
    36  	}
    37  	if err2 := os.WriteFile(filepath.Join(directory, addNodesResultFile), []byte(exitCode), 0600); err2 != nil {
    38  		return err2
    39  	}
    40  
    41  	return err
    42  }
    43  
    44  func saveParams(directory, kubeConfig string) error {
    45  	// Store the current parameters into the assets folder, so
    46  	// that they could be retrieved later by the assets
    47  	params := joiner.Params{
    48  		Kubeconfig: kubeConfig,
    49  	}
    50  	return params.Save(directory)
    51  }