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

     1  package machine
     2  
     3  import (
     4  	"context"
     5  	"path/filepath"
     6  
     7  	"github.com/pkg/errors"
     8  	"github.com/sirupsen/logrus"
     9  	"sigs.k8s.io/yaml"
    10  
    11  	mcfgv1 "github.com/openshift/api/machineconfiguration/v1"
    12  	"github.com/openshift/installer/pkg/asset"
    13  	"github.com/openshift/installer/pkg/asset/ignition"
    14  	"github.com/openshift/installer/pkg/asset/installconfig"
    15  	"github.com/openshift/installer/pkg/asset/tls"
    16  )
    17  
    18  var (
    19  	masterMachineConfigFileName = filepath.Join(directory, "99_openshift-installer-ignition_master.yaml")
    20  )
    21  
    22  // MasterIgnitionCustomizations is an asset that checks for any customizations a user might
    23  // have made to the pointer ignition configs before creating the cluster. If customizations
    24  // are made, then the updates are reconciled as a MachineConfig file
    25  type MasterIgnitionCustomizations struct {
    26  	File *asset.File
    27  }
    28  
    29  var _ asset.WritableAsset = (*MasterIgnitionCustomizations)(nil)
    30  
    31  // Dependencies returns the dependencies for MasterIgnitionCustomizations
    32  func (a *MasterIgnitionCustomizations) Dependencies() []asset.Asset {
    33  	return []asset.Asset{
    34  		&installconfig.InstallConfig{},
    35  		&tls.RootCA{},
    36  		&Master{},
    37  	}
    38  }
    39  
    40  // Generate queries for input from the user.
    41  func (a *MasterIgnitionCustomizations) Generate(_ context.Context, dependencies asset.Parents) error {
    42  	installConfig := &installconfig.InstallConfig{}
    43  	rootCA := &tls.RootCA{}
    44  	master := &Master{}
    45  	dependencies.Get(installConfig, rootCA, master)
    46  
    47  	defaultPointerIgnition := pointerIgnitionConfig(installConfig.Config, rootCA.Cert(), "master")
    48  	savedPointerIgnition := master.Config
    49  
    50  	savedPointerIgnitionJSON, err := ignition.Marshal(savedPointerIgnition)
    51  	if err != nil {
    52  		return errors.Wrap(err, "failed to Marshal savedPointerIgnition")
    53  	}
    54  	defaultPointerIgnitionJSON, err := ignition.Marshal(defaultPointerIgnition)
    55  	if err != nil {
    56  		return errors.Wrap(err, "failed to Marshal defaultPointerIgnition")
    57  	}
    58  	if string(savedPointerIgnitionJSON) != string(defaultPointerIgnitionJSON) {
    59  		logrus.Infof("Master pointer ignition was modified. Saving contents to a machineconfig")
    60  		mc := &mcfgv1.MachineConfig{}
    61  		mc, err = generatePointerMachineConfig(*savedPointerIgnition, "master")
    62  		if err != nil {
    63  			return errors.Wrap(err, "failed to generate master installer machineconfig")
    64  		}
    65  		configData, err := yaml.Marshal(mc)
    66  		if err != nil {
    67  			return errors.Wrap(err, "failed to marshal master installer machineconfig")
    68  		}
    69  		a.File = &asset.File{
    70  			Filename: masterMachineConfigFileName,
    71  			Data:     configData,
    72  		}
    73  	}
    74  
    75  	return nil
    76  }
    77  
    78  // Name returns the human-friendly name of the asset.
    79  func (a *MasterIgnitionCustomizations) Name() string {
    80  	return "Master Ignition Customization Check"
    81  }
    82  
    83  // Files returns the files generated by the asset.
    84  func (a *MasterIgnitionCustomizations) Files() []*asset.File {
    85  	if a.File != nil {
    86  		return []*asset.File{a.File}
    87  	}
    88  	return []*asset.File{}
    89  }
    90  
    91  // Load does nothing, since we consume the ignition-configs
    92  func (a *MasterIgnitionCustomizations) Load(f asset.FileFetcher) (found bool, err error) {
    93  	return false, nil
    94  }