diff --git a/pkg/cloudcommon/cmdline/parser.go b/pkg/cloudcommon/cmdline/parser.go index e43d1dec47..ad12eb9d8a 100644 --- a/pkg/cloudcommon/cmdline/parser.go +++ b/pkg/cloudcommon/cmdline/parser.go @@ -36,23 +36,27 @@ var ( ErrorEmptyDesc = errors.New("Empty description") ) -// ParseSchedtagConfig desc format: : +// ParseSchedtagConfig desc format: :: func ParseSchedtagConfig(desc string) (*compute.SchedtagConfig, error) { if len(desc) == 0 { return nil, ErrorEmptyDesc } parts := strings.Split(desc, ":") - if len(parts) != 2 { + if len(parts) < 2 { return nil, fmt.Errorf("Invalid desc: %s", desc) } strategy := parts[1] if !utils.IsInStringArray(strategy, compute.STRATEGY_LIST) { return nil, fmt.Errorf("Invalid strategy: %s", strategy) } - return &compute.SchedtagConfig{ + conf := &compute.SchedtagConfig{ Id: parts[0], Strategy: parts[1], - }, nil + } + if len(parts) == 3 { + conf.ResourceType = parts[2] + } + return conf, nil } // ParseResourceSchedtagConfig desc format: :: diff --git a/pkg/cloudcommon/cmdline/parser_test.go b/pkg/cloudcommon/cmdline/parser_test.go index 264a92f6f7..624ea532a9 100644 --- a/pkg/cloudcommon/cmdline/parser_test.go +++ b/pkg/cloudcommon/cmdline/parser_test.go @@ -45,6 +45,12 @@ func TestParseSchedtagConfig(t *testing.T) { want: &compute.SchedtagConfig{Id: "ssd", Strategy: "require"}, wantErr: false, }, + { + name: "with resource type", + args: args{"ssd:require:zones"}, + want: &compute.SchedtagConfig{Id: "ssd", Strategy: "require", ResourceType: "zones"}, + wantErr: false, + }, { name: "invalid strategy", args: args{"ssd:require2"}, diff --git a/pkg/scheduler/api/sched.go b/pkg/scheduler/api/sched.go index a4d8dd204b..6fb904213c 100644 --- a/pkg/scheduler/api/sched.go +++ b/pkg/scheduler/api/sched.go @@ -270,9 +270,10 @@ type FilteredCandidate struct { } type SchedForecastResult struct { - CanCreate bool `json:"can_create"` - ReqCount int64 `json:"req_count"` - AllowCount int64 `json:"allow_count"` - NotAllowReasons []string `json:"not_allow_reasons"` - FilteredCandidates []FilteredCandidate `json:"filtered_candidates"` + CanCreate bool `json:"can_create"` + Candidates []*api.CandidateResource `json:"candidates"` + ReqCount int64 `json:"req_count"` + AllowCount int64 `json:"allow_count"` + NotAllowReasons []string `json:"not_allow_reasons"` + FilteredCandidates []FilteredCandidate `json:"filtered_candidates"` } diff --git a/pkg/scheduler/core/result_helper.go b/pkg/scheduler/core/result_helper.go index cc0527610d..987e4ddc67 100644 --- a/pkg/scheduler/core/result_helper.go +++ b/pkg/scheduler/core/result_helper.go @@ -159,6 +159,7 @@ func transToSchedForecastResult(result *SchedResultItemList) *api.SchedForecastR for _, candi := range output.Candidates { if len(candi.Error) == 0 { readyCount++ + ret.Candidates = append(ret.Candidates, candi) continue } ret.NotAllowReasons = append(ret.NotAllowReasons, candi.Error) @@ -170,6 +171,5 @@ func transToSchedForecastResult(result *SchedResultItemList) *api.SchedForecastR } else { ret.CanCreate = true } - return ret } diff --git a/pkg/scheduler/test/generic_scheduler_test.go b/pkg/scheduler/test/generic_scheduler_test.go index 87fda02e6b..0e2c219e9b 100644 --- a/pkg/scheduler/test/generic_scheduler_test.go +++ b/pkg/scheduler/test/generic_scheduler_test.go @@ -184,6 +184,7 @@ func TestGenericSchedulerSchedule(t *testing.T) { }, }, } + res.ForecastResult.Candidates = nil if !reflect.DeepEqual(res.ForecastResult, forcastResult) { t.Errorf("want: %v, real: %v", forcastResult, res.ForecastResult) }