github.com/openshift/installer@v1.4.17/pkg/asset/manifests/featuregate.go (about)

     1  package manifests
     2  
     3  import (
     4  	"context"
     5  	"path/filepath"
     6  
     7  	"github.com/pkg/errors"
     8  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
     9  	"sigs.k8s.io/yaml"
    10  
    11  	configv1 "github.com/openshift/api/config/v1"
    12  	"github.com/openshift/installer/pkg/asset"
    13  	"github.com/openshift/installer/pkg/asset/installconfig"
    14  	"github.com/openshift/installer/pkg/types/featuregates"
    15  )
    16  
    17  var fgFileName = filepath.Join(openshiftManifestDir, "99_feature-gate.yaml")
    18  
    19  // FeatureGate generates the feature gate manifest.
    20  type FeatureGate struct {
    21  	FileList []*asset.File
    22  	Config   configv1.FeatureGate
    23  }
    24  
    25  var _ asset.WritableAsset = (*Proxy)(nil)
    26  
    27  // Name returns a human-friendly name for the asset.
    28  func (*FeatureGate) Name() string {
    29  	return "Feature Gate Config"
    30  }
    31  
    32  // Dependencies returns all of the dependencies directly needed to generate
    33  // the asset.
    34  func (*FeatureGate) Dependencies() []asset.Asset {
    35  	return []asset.Asset{
    36  		&installconfig.InstallConfig{},
    37  	}
    38  }
    39  
    40  // Generate generates the FeatureGate CRD.
    41  func (f *FeatureGate) Generate(_ context.Context, dependencies asset.Parents) error {
    42  	installConfig := &installconfig.InstallConfig{}
    43  	dependencies.Get(installConfig)
    44  
    45  	f.Config = configv1.FeatureGate{
    46  		TypeMeta: metav1.TypeMeta{
    47  			APIVersion: configv1.SchemeGroupVersion.String(),
    48  			Kind:       "FeatureGate",
    49  		},
    50  		ObjectMeta: metav1.ObjectMeta{
    51  			Name: "cluster",
    52  		},
    53  		Spec: configv1.FeatureGateSpec{
    54  			FeatureGateSelection: configv1.FeatureGateSelection{
    55  				FeatureSet: installConfig.Config.FeatureSet,
    56  			},
    57  		},
    58  	}
    59  
    60  	if len(installConfig.Config.FeatureGates) > 0 {
    61  		if installConfig.Config.FeatureSet != configv1.CustomNoUpgrade {
    62  			return errors.Errorf("custom features can only be used with the CustomNoUpgrade feature set")
    63  		}
    64  
    65  		customFeatures := featuregates.GenerateCustomFeatures(installConfig.Config.FeatureGates)
    66  		f.Config.Spec.CustomNoUpgrade = customFeatures
    67  	}
    68  
    69  	configData, err := yaml.Marshal(f.Config)
    70  	if err != nil {
    71  		return errors.Wrapf(err, "failed to create %s manifests from InstallConfig", f.Name())
    72  	}
    73  
    74  	f.FileList = []*asset.File{
    75  		{
    76  			Filename: fgFileName,
    77  			Data:     configData,
    78  		},
    79  	}
    80  
    81  	return nil
    82  }
    83  
    84  // Files returns the files generated by the asset.
    85  func (f *FeatureGate) Files() []*asset.File {
    86  	return f.FileList
    87  }
    88  
    89  // Load loads the already-rendered files back from disk.
    90  func (f *FeatureGate) Load(ff asset.FileFetcher) (bool, error) {
    91  	return false, nil
    92  }