github.com/openshift/installer@v1.4.17/pkg/asset/manifests/scheduler.go (about) 1 package manifests 2 3 import ( 4 "context" 5 "path/filepath" 6 7 "github.com/pkg/errors" 8 "github.com/sirupsen/logrus" 9 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 10 "sigs.k8s.io/yaml" 11 12 configv1 "github.com/openshift/api/config/v1" 13 "github.com/openshift/installer/pkg/asset" 14 "github.com/openshift/installer/pkg/asset/installconfig" 15 ) 16 17 var ( 18 // SchedulerCfgFilename is the path of the Scheduler Config file 19 SchedulerCfgFilename = filepath.Join(manifestDir, "cluster-scheduler-02-config.yml") 20 ) 21 22 // Scheduler generates the cluster-scheduler-*.yml files. 23 type Scheduler struct { 24 FileList []*asset.File 25 } 26 27 var _ asset.WritableAsset = (*Scheduler)(nil) 28 29 // Name returns a human friendly name for the asset. 30 func (*Scheduler) Name() string { 31 return "Scheduler Config" 32 } 33 34 // Dependencies returns all of the dependencies directly needed to generate 35 // the asset. 36 func (*Scheduler) Dependencies() []asset.Asset { 37 return []asset.Asset{ 38 &installconfig.InstallConfig{}, 39 } 40 } 41 42 // Generate generates the scheduler config and its CRD. 43 func (s *Scheduler) Generate(_ context.Context, dependencies asset.Parents) error { 44 config := &configv1.Scheduler{ 45 TypeMeta: metav1.TypeMeta{ 46 APIVersion: configv1.SchemeGroupVersion.String(), 47 Kind: "Scheduler", 48 }, 49 ObjectMeta: metav1.ObjectMeta{ 50 Name: "cluster", 51 // not namespaced 52 }, 53 Spec: configv1.SchedulerSpec{ 54 MastersSchedulable: false, 55 }, 56 } 57 58 installConfig := &installconfig.InstallConfig{} 59 dependencies.Get(installConfig) 60 computeReplicas := int64(0) 61 for _, pool := range installConfig.Config.Compute { 62 if pool.Replicas != nil { 63 computeReplicas += *pool.Replicas 64 } 65 } 66 if computeReplicas == 0 { 67 // A schedulable host is required for a successful install to complete. 68 // If the install config has 0 replicas for compute hosts, it's one of two cases: 69 // 1. An IPI deployment with no compute hosts. The deployment can not succeed 70 // without MastersSchedulable = true. 71 // 2. A UPI deployment. The deployment may add compute hosts, but to ensure the 72 // the highest probability of a successful deployment, we default to 73 // schedulable masters. 74 logrus.Warningf("Making control-plane schedulable by setting MastersSchedulable to true for Scheduler cluster settings") 75 config.Spec.MastersSchedulable = true 76 } 77 78 configData, err := yaml.Marshal(config) 79 if err != nil { 80 return errors.Wrapf(err, "failed to create %s manifests from InstallConfig", s.Name()) 81 } 82 83 s.FileList = []*asset.File{ 84 { 85 Filename: SchedulerCfgFilename, 86 Data: configData, 87 }, 88 } 89 90 return nil 91 } 92 93 // Files returns the files generated by the asset. 94 func (s *Scheduler) Files() []*asset.File { 95 return s.FileList 96 } 97 98 // Load returns false since this asset is not written to disk by the installer. 99 func (s *Scheduler) Load(f asset.FileFetcher) (bool, error) { 100 return false, nil 101 }