volcano.sh/volcano@v1.9.0/pkg/scheduler/util.go (about)

     1  /*
     2  Copyright 2018 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package scheduler
    18  
    19  import (
    20  	"flag"
    21  	"fmt"
    22  	"os"
    23  	"strings"
    24  
    25  	"gopkg.in/yaml.v2"
    26  
    27  	"volcano.sh/volcano/pkg/scheduler/conf"
    28  	"volcano.sh/volcano/pkg/scheduler/framework"
    29  	"volcano.sh/volcano/pkg/scheduler/plugins"
    30  	"volcano.sh/volcano/pkg/util"
    31  )
    32  
    33  var DefaultSchedulerConf = `
    34  actions: "enqueue, allocate, backfill"
    35  tiers:
    36  - plugins:
    37    - name: priority
    38    - name: gang
    39    - name: conformance
    40  - plugins:
    41    - name: overcommit
    42    - name: drf
    43    - name: predicates
    44    - name: proportion
    45    - name: nodeorder
    46  `
    47  
    48  func UnmarshalSchedulerConf(confStr string) ([]framework.Action, []conf.Tier, []conf.Configuration, map[string]string, error) {
    49  	var actions []framework.Action
    50  
    51  	schedulerConf := &conf.SchedulerConfiguration{}
    52  
    53  	if err := yaml.Unmarshal([]byte(confStr), schedulerConf); err != nil {
    54  		return nil, nil, nil, nil, err
    55  	}
    56  	// Set default settings for each plugin if not set
    57  	for i, tier := range schedulerConf.Tiers {
    58  		// drf with hierarchy enabled
    59  		hdrf := false
    60  		// proportion enabled
    61  		proportion := false
    62  		for j := range tier.Plugins {
    63  			if tier.Plugins[j].Name == "drf" &&
    64  				tier.Plugins[j].EnabledHierarchy != nil &&
    65  				*tier.Plugins[j].EnabledHierarchy {
    66  				hdrf = true
    67  			}
    68  			if tier.Plugins[j].Name == "proportion" {
    69  				proportion = true
    70  			}
    71  			plugins.ApplyPluginConfDefaults(&schedulerConf.Tiers[i].Plugins[j])
    72  		}
    73  		if hdrf && proportion {
    74  			return nil, nil, nil, nil, fmt.Errorf("proportion and drf with hierarchy enabled conflicts")
    75  		}
    76  	}
    77  
    78  	actionNames := strings.Split(schedulerConf.Actions, ",")
    79  	for _, actionName := range actionNames {
    80  		if action, found := framework.GetAction(strings.TrimSpace(actionName)); found {
    81  			actions = append(actions, action)
    82  		} else {
    83  			return nil, nil, nil, nil, fmt.Errorf("failed to find Action %s, ignore it", actionName)
    84  		}
    85  	}
    86  
    87  	return actions, schedulerConf.Tiers, schedulerConf.Configurations, schedulerConf.MetricsConfiguration, nil
    88  }
    89  
    90  func runSchedulerSocket() {
    91  	fs := flag.CommandLine
    92  	startKlogLevel := fs.Lookup("v").Value.String()
    93  	socketDir := os.Getenv(util.SocketDirEnvName)
    94  	if socketDir == "" {
    95  		socketDir = util.DefaultSocketDir
    96  	}
    97  	util.ListenAndServeKlogLogLevel("klog", startKlogLevel, socketDir)
    98  }