github.com/openshift/installer@v1.4.17/pkg/asset/ignition/bootstrap/bootstrap_in_place.go (about)

     1  package bootstrap
     2  
     3  import (
     4  	"context"
     5  
     6  	"k8s.io/apimachinery/pkg/util/validation/field"
     7  
     8  	"github.com/openshift/installer/pkg/asset"
     9  	"github.com/openshift/installer/pkg/asset/installconfig"
    10  	"github.com/openshift/installer/pkg/types"
    11  )
    12  
    13  const (
    14  	singleNodeBootstrapInPlaceIgnFilename = "bootstrap-in-place-for-live-iso.ign"
    15  )
    16  
    17  var (
    18  	bootstrapInPlaceEnabledServices = []string{
    19  		"install-to-disk.service",
    20  	}
    21  )
    22  
    23  // SingleNodeBootstrapInPlace is an asset that generates the ignition config for single node OpenShift.
    24  type SingleNodeBootstrapInPlace struct {
    25  	Common
    26  }
    27  
    28  var _ asset.Asset = (*SingleNodeBootstrapInPlace)(nil)
    29  
    30  // Name returns the human-friendly name of the asset.
    31  func (a *SingleNodeBootstrapInPlace) Name() string {
    32  	return "Single node bootstrap In Place Ignition Config"
    33  }
    34  
    35  // Generate generates the ignition config for the Bootstrap asset.
    36  func (a *SingleNodeBootstrapInPlace) Generate(_ context.Context, dependencies asset.Parents) error {
    37  	installConfig := &installconfig.InstallConfig{}
    38  	dependencies.Get(installConfig)
    39  	if err := verifyBootstrapInPlace(installConfig.Config); err != nil {
    40  		return err
    41  	}
    42  	templateData := a.getTemplateData(dependencies, true)
    43  	if err := a.generateConfig(dependencies, templateData); err != nil {
    44  		return err
    45  	}
    46  	if err := AddStorageFiles(a.Config, "/", "bootstrap/bootstrap-in-place/files", templateData); err != nil {
    47  		return err
    48  	}
    49  	if err := AddSystemdUnits(a.Config, "bootstrap/bootstrap-in-place/systemd/units", templateData, bootstrapInPlaceEnabledServices); err != nil {
    50  		return err
    51  	}
    52  	if err := a.Common.generateFile(singleNodeBootstrapInPlaceIgnFilename); err != nil {
    53  		return err
    54  	}
    55  	return nil
    56  }
    57  
    58  // Load returns the bootstrap-in-place ignition from disk.
    59  func (a *SingleNodeBootstrapInPlace) Load(f asset.FileFetcher) (found bool, err error) {
    60  	return a.load(f, singleNodeBootstrapInPlaceIgnFilename)
    61  }
    62  
    63  // verifyBootstrapInPlace validate the number of control plane replica is one and that installation disk is set
    64  func verifyBootstrapInPlace(installConfig *types.InstallConfig) error {
    65  	errorList := field.ErrorList{}
    66  	if installConfig.ControlPlane.Replicas == nil {
    67  		errorList = append(errorList, field.Invalid(field.NewPath("controlPlane", "replicas"), installConfig.ControlPlane.Replicas,
    68  			"bootstrap in place requires ControlPlane.Replicas configuration"))
    69  	}
    70  	if *installConfig.ControlPlane.Replicas != 1 {
    71  		errorList = append(errorList, field.Invalid(field.NewPath("controlPlane", "replicas"), installConfig.ControlPlane.Replicas,
    72  			"bootstrap in place requires a single ControlPlane replica"))
    73  	}
    74  	if installConfig.BootstrapInPlace == nil {
    75  		errorList = append(errorList, field.Required(field.NewPath("bootstrapInPlace"), "bootstrapInPlace is required when creating a single node bootstrap-in-place ignition"))
    76  	} else if installConfig.BootstrapInPlace.InstallationDisk == "" {
    77  		errorList = append(errorList, field.Required(field.NewPath("bootstrapInPlace", "installationDisk"),
    78  			"installationDisk must be set the target disk drive for the installation"))
    79  	}
    80  	return errorList.ToAggregate()
    81  }