@@ -26,42 +26,42 @@ import (
26
26
27
27
"github.com/spf13/pflag"
28
28
29
+ "k8s.io/api/core/v1"
29
30
"k8s.io/apimachinery/pkg/util/yaml"
30
- "k8s.io/kubernetes/pkg/api"
31
- "k8s.io/kubernetes/pkg/api/v1"
32
- "k8s.io/kubernetes/pkg/api/validation"
33
- clientset "k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
34
- schedopt "k8s.io/kubernetes/plugin/cmd/kube-scheduler/app/options"
31
+ clientset "k8s.io/client-go/kubernetes"
32
+ api "k8s.io/kubernetes/pkg/apis/core"
33
+ apiv1 "k8s.io/kubernetes/pkg/apis/core/v1"
34
+ "k8s.io/kubernetes/pkg/apis/core/validation"
35
+ schedapp "k8s.io/kubernetes/plugin/cmd/kube-scheduler/app"
36
+ "k8s.io/kubernetes/plugin/pkg/scheduler/algorithmprovider"
35
37
36
38
"github.com/kubernetes-incubator/cluster-capacity/pkg/framework/store"
37
39
"github.com/kubernetes-incubator/cluster-capacity/pkg/utils"
38
40
)
39
41
40
42
type ClusterCapacityConfig struct {
41
- Schedulers []* schedopt .SchedulerServer
43
+ // Schedulers []*schedapp .SchedulerServer
42
44
Pod * v1.Pod
43
45
KubeClient clientset.Interface
44
46
Options * ClusterCapacityOptions
45
- DefaultScheduler * schedopt .SchedulerServer
47
+ DefaultScheduler * schedapp .SchedulerServer
46
48
ResourceStore store.ResourceStore
47
49
}
48
50
49
51
type ClusterCapacityOptions struct {
50
- Kubeconfig string
51
- SchedulerConfigFile []string
52
+ Kubeconfig string
53
+ // SchedulerConfigFile []string
52
54
DefaultSchedulerConfigFile string
53
55
MaxLimit int
54
56
Verbose bool
55
57
PodSpecFile string
56
58
OutputFormat string
57
- ResourceSpaceMode string
59
+ // ResourceSpaceMode string
58
60
}
59
61
60
62
func NewClusterCapacityConfig (opt * ClusterCapacityOptions ) * ClusterCapacityConfig {
61
63
return & ClusterCapacityConfig {
62
- Schedulers : make ([]* schedopt.SchedulerServer , 0 ),
63
- Options : opt ,
64
- DefaultScheduler : schedopt .NewSchedulerServer (),
64
+ Options : opt ,
65
65
}
66
66
}
67
67
@@ -83,8 +83,27 @@ func (s *ClusterCapacityOptions) AddFlags(fs *pflag.FlagSet) {
83
83
fs .StringVarP (& s .OutputFormat , "output" , "o" , s .OutputFormat , "Output format. One of: json|yaml (Note: output is not versioned or guaranteed to be stable across releases)." )
84
84
}
85
85
86
- func parseSchedulerConfig (path string ) (* schedopt.SchedulerServer , error ) {
87
- newScheduler := schedopt .NewSchedulerServer ()
86
+ func (s * ClusterCapacityConfig ) parseSchedulerConfig (path string ) (* schedapp.SchedulerServer , error ) {
87
+ soptions , err := schedapp .NewOptions ()
88
+ if err != nil {
89
+ return nil , err
90
+ }
91
+
92
+ err = soptions .ReallyApplyDefaults ()
93
+ if err != nil {
94
+ return nil , err
95
+ }
96
+
97
+ soptions .ConfigFile = path
98
+
99
+ err = soptions .Complete ()
100
+ if err != nil {
101
+ return nil , err
102
+ }
103
+
104
+ ksConfig := soptions .GetConfig ()
105
+ ksConfig .ClientConnection .KubeConfigFile = s .Options .Kubeconfig
106
+
88
107
if len (path ) > 0 {
89
108
filename , _ := filepath .Abs (path )
90
109
config , err := os .Open (filename )
@@ -93,29 +112,42 @@ func parseSchedulerConfig(path string) (*schedopt.SchedulerServer, error) {
93
112
}
94
113
95
114
decoder := yaml .NewYAMLOrJSONDecoder (config , 4096 )
96
- decoder .Decode (& ( newScheduler . KubeSchedulerConfiguration ) )
115
+ decoder .Decode (ksConfig )
97
116
}
117
+
118
+ var master string
119
+ master , err = utils .GetMasterFromKubeConfig (s .Options .Kubeconfig )
120
+ if err != nil {
121
+ return nil , err
122
+ }
123
+
124
+ // TODO(avesh): need to check if this works correctly
125
+ algorithmprovider .ApplyFeatureGates ()
126
+
127
+ var newScheduler * schedapp.SchedulerServer
128
+ newScheduler , err = schedapp .NewSchedulerServer (ksConfig , master )
129
+ if err != nil {
130
+ return nil , err
131
+ }
132
+
133
+ newScheduler .SchedulerName = "cluster-capacity"
98
134
return newScheduler , nil
99
135
}
100
136
101
- func (s * ClusterCapacityConfig ) ParseAdditionalSchedulerConfigs () error {
137
+ // TODO (avesh): disable until support for multiple schedulers is implemented.
138
+ /*func (s *ClusterCapacityConfig) ParseAdditionalSchedulerConfigs() error {
102
139
for _, config := range s.Options.SchedulerConfigFile {
103
140
if config == "default-scheduler.yaml" {
104
141
continue
105
142
}
106
- newScheduler , err := parseSchedulerConfig (config )
143
+ newScheduler, err := s. parseSchedulerConfig(config)
107
144
if err != nil {
108
145
return err
109
146
}
110
- newScheduler .Master , err = utils .GetMasterFromKubeConfig (s .Options .Kubeconfig )
111
- if err != nil {
112
- return err
113
- }
114
- newScheduler .Kubeconfig = s .Options .Kubeconfig
115
147
s.Schedulers = append(s.Schedulers, newScheduler)
116
148
}
117
149
return nil
118
- }
150
+ }*/
119
151
120
152
func (s * ClusterCapacityConfig ) ParseAPISpec () error {
121
153
var spec io.Reader
@@ -149,6 +181,11 @@ func (s *ClusterCapacityConfig) ParseAPISpec() error {
149
181
versionedPod .ObjectMeta .Namespace = "default"
150
182
}
151
183
184
+ // set pod's scheduler name to cluster-capacity
185
+ if versionedPod .Spec .SchedulerName == "" {
186
+ versionedPod .Spec .SchedulerName = s .DefaultScheduler .SchedulerName
187
+ }
188
+
152
189
// hardcoded from kube api defaults and validation
153
190
// TODO: rewrite when object validation gets more available for non kubectl approaches in kube
154
191
if versionedPod .Spec .DNSPolicy == "" {
@@ -166,7 +203,7 @@ func (s *ClusterCapacityConfig) ParseAPISpec() error {
166
203
167
204
// TODO: client side validation seems like a long term problem for this command.
168
205
internalPod := & api.Pod {}
169
- if err := v1 . Convert_v1_Pod_To_api_Pod (versionedPod , internalPod , nil ); err != nil {
206
+ if err := apiv1 . Convert_v1_Pod_To_core_Pod (versionedPod , internalPod , nil ); err != nil {
170
207
return fmt .Errorf ("unable to convert to internal version: %#v" , err )
171
208
172
209
}
@@ -184,7 +221,7 @@ func (s *ClusterCapacityConfig) ParseAPISpec() error {
184
221
185
222
func (s * ClusterCapacityConfig ) SetDefaultScheduler () error {
186
223
var err error
187
- s .DefaultScheduler , err = parseSchedulerConfig (s .Options .DefaultSchedulerConfigFile )
224
+ s .DefaultScheduler , err = s . parseSchedulerConfig (s .Options .DefaultSchedulerConfigFile )
188
225
if err != nil {
189
226
return fmt .Errorf ("Error in opening default scheduler config file: %v" , err )
190
227
}
0 commit comments