Skip to content

Commit 408fb77

Browse files
author
Avesh Agarwal
committed
Cluster-capacity code update for kube 1.9.
1 parent 64c9fe2 commit 408fb77

File tree

26 files changed

+713
-388
lines changed

26 files changed

+713
-388
lines changed

cmd/cluster-capacity/go/src/github.com/kubernetes-incubator/cluster-capacity/.gitignore

-3
This file was deleted.

cmd/cluster-capacity/go/src/github.com/kubernetes-incubator/cluster-capacity/.travis.yml

-6
This file was deleted.

cmd/cluster-capacity/go/src/github.com/kubernetes-incubator/cluster-capacity/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ integration-tests:
2626
./integration-tests.sh
2727

2828
image:
29-
docker build -t docker.io/gofed/cluster-capacity .
29+
docker build -t cluster-capacity .
3030

3131
clean:
3232
rm -f cluster-capacity genpod hypercc
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
reviewers:
2-
- ingvagabund
3-
- aveshagarwal
4-
- hodovska
51
approvers:
6-
- ingvagabund
7-
- aveshagarwal
8-
- hodovska
2+
- ingvagabund
3+
- aveshagarwal
4+
- hodovska
5+
reviewers:
6+
- ingvagabund
7+
- aveshagarwal
8+
- hodovska

cmd/cluster-capacity/go/src/github.com/kubernetes-incubator/cluster-capacity/cmd/cluster-capacity/app/options/options.go

+63-26
Original file line numberDiff line numberDiff line change
@@ -26,42 +26,42 @@ import (
2626

2727
"github.com/spf13/pflag"
2828

29+
"k8s.io/api/core/v1"
2930
"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"
3537

3638
"github.com/kubernetes-incubator/cluster-capacity/pkg/framework/store"
3739
"github.com/kubernetes-incubator/cluster-capacity/pkg/utils"
3840
)
3941

4042
type ClusterCapacityConfig struct {
41-
Schedulers []*schedopt.SchedulerServer
43+
//Schedulers []*schedapp.SchedulerServer
4244
Pod *v1.Pod
4345
KubeClient clientset.Interface
4446
Options *ClusterCapacityOptions
45-
DefaultScheduler *schedopt.SchedulerServer
47+
DefaultScheduler *schedapp.SchedulerServer
4648
ResourceStore store.ResourceStore
4749
}
4850

4951
type ClusterCapacityOptions struct {
50-
Kubeconfig string
51-
SchedulerConfigFile []string
52+
Kubeconfig string
53+
//SchedulerConfigFile []string
5254
DefaultSchedulerConfigFile string
5355
MaxLimit int
5456
Verbose bool
5557
PodSpecFile string
5658
OutputFormat string
57-
ResourceSpaceMode string
59+
//ResourceSpaceMode string
5860
}
5961

6062
func NewClusterCapacityConfig(opt *ClusterCapacityOptions) *ClusterCapacityConfig {
6163
return &ClusterCapacityConfig{
62-
Schedulers: make([]*schedopt.SchedulerServer, 0),
63-
Options: opt,
64-
DefaultScheduler: schedopt.NewSchedulerServer(),
64+
Options: opt,
6565
}
6666
}
6767

@@ -83,8 +83,27 @@ func (s *ClusterCapacityOptions) AddFlags(fs *pflag.FlagSet) {
8383
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).")
8484
}
8585

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+
88107
if len(path) > 0 {
89108
filename, _ := filepath.Abs(path)
90109
config, err := os.Open(filename)
@@ -93,29 +112,42 @@ func parseSchedulerConfig(path string) (*schedopt.SchedulerServer, error) {
93112
}
94113

95114
decoder := yaml.NewYAMLOrJSONDecoder(config, 4096)
96-
decoder.Decode(&(newScheduler.KubeSchedulerConfiguration))
115+
decoder.Decode(ksConfig)
97116
}
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"
98134
return newScheduler, nil
99135
}
100136

101-
func (s *ClusterCapacityConfig) ParseAdditionalSchedulerConfigs() error {
137+
// TODO (avesh): disable until support for multiple schedulers is implemented.
138+
/*func (s *ClusterCapacityConfig) ParseAdditionalSchedulerConfigs() error {
102139
for _, config := range s.Options.SchedulerConfigFile {
103140
if config == "default-scheduler.yaml" {
104141
continue
105142
}
106-
newScheduler, err := parseSchedulerConfig(config)
143+
newScheduler, err := s.parseSchedulerConfig(config)
107144
if err != nil {
108145
return err
109146
}
110-
newScheduler.Master, err = utils.GetMasterFromKubeConfig(s.Options.Kubeconfig)
111-
if err != nil {
112-
return err
113-
}
114-
newScheduler.Kubeconfig = s.Options.Kubeconfig
115147
s.Schedulers = append(s.Schedulers, newScheduler)
116148
}
117149
return nil
118-
}
150+
}*/
119151

120152
func (s *ClusterCapacityConfig) ParseAPISpec() error {
121153
var spec io.Reader
@@ -149,6 +181,11 @@ func (s *ClusterCapacityConfig) ParseAPISpec() error {
149181
versionedPod.ObjectMeta.Namespace = "default"
150182
}
151183

184+
// set pod's scheduler name to cluster-capacity
185+
if versionedPod.Spec.SchedulerName == "" {
186+
versionedPod.Spec.SchedulerName = s.DefaultScheduler.SchedulerName
187+
}
188+
152189
// hardcoded from kube api defaults and validation
153190
// TODO: rewrite when object validation gets more available for non kubectl approaches in kube
154191
if versionedPod.Spec.DNSPolicy == "" {
@@ -166,7 +203,7 @@ func (s *ClusterCapacityConfig) ParseAPISpec() error {
166203

167204
// TODO: client side validation seems like a long term problem for this command.
168205
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 {
170207
return fmt.Errorf("unable to convert to internal version: %#v", err)
171208

172209
}
@@ -184,7 +221,7 @@ func (s *ClusterCapacityConfig) ParseAPISpec() error {
184221

185222
func (s *ClusterCapacityConfig) SetDefaultScheduler() error {
186223
var err error
187-
s.DefaultScheduler, err = parseSchedulerConfig(s.Options.DefaultSchedulerConfigFile)
224+
s.DefaultScheduler, err = s.parseSchedulerConfig(s.Options.DefaultSchedulerConfigFile)
188225
if err != nil {
189226
return fmt.Errorf("Error in opening default scheduler config file: %v", err)
190227
}

cmd/cluster-capacity/go/src/github.com/kubernetes-incubator/cluster-capacity/cmd/cluster-capacity/app/server.go

+13-9
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ import (
2323
"github.com/renstrom/dedent"
2424
"github.com/spf13/cobra"
2525

26+
clientset "k8s.io/client-go/kubernetes"
2627
restclient "k8s.io/client-go/rest"
2728
"k8s.io/client-go/tools/clientcmd"
28-
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
2929
_ "k8s.io/kubernetes/plugin/pkg/scheduler/algorithmprovider"
3030

3131
"github.com/kubernetes-incubator/cluster-capacity/cmd/cluster-capacity/app/options"
@@ -81,18 +81,21 @@ func Validate(opt *options.ClusterCapacityOptions) error {
8181

8282
func Run(opt *options.ClusterCapacityOptions) error {
8383
conf := options.NewClusterCapacityConfig(opt)
84-
err := conf.ParseAPISpec()
85-
if err != nil {
86-
return fmt.Errorf("Failed to parse pod spec file: %v ", err)
87-
}
8884

89-
err = conf.SetDefaultScheduler()
85+
err := conf.SetDefaultScheduler()
9086
if err != nil {
9187
return fmt.Errorf("Failed to set default scheduler config: %v ", err)
9288
}
93-
err = conf.ParseAdditionalSchedulerConfigs()
89+
90+
// TODO (avesh): Enable when support for multiple schedulers is implemented.
91+
/*err = conf.ParseAdditionalSchedulerConfigs()
9492
if err != nil {
9593
return fmt.Errorf("Failed to parse config file: %v ", err)
94+
}*/
95+
96+
err = conf.ParseAPISpec()
97+
if err != nil {
98+
return fmt.Errorf("Failed to parse pod spec file: %v ", err)
9699
}
97100

98101
var cfg *restclient.Config
@@ -136,11 +139,12 @@ func runSimulator(s *options.ClusterCapacityConfig, syncWithClient bool) (*frame
136139
return nil, err
137140
}
138141

139-
for i := 0; i < len(s.Schedulers); i++ {
142+
// TODO (avesh): Enable when support for multiple schedulers is implemented.
143+
/*for i := 0; i < len(s.Schedulers); i++ {
140144
if err = cc.AddScheduler(s.Schedulers[i]); err != nil {
141145
return nil, err
142146
}
143-
}
147+
}*/
144148

145149
if syncWithClient {
146150
err = cc.SyncWithClient(s.KubeClient)

cmd/cluster-capacity/go/src/github.com/kubernetes-incubator/cluster-capacity/cmd/genpod/app/server.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ import (
2323

2424
"github.com/spf13/cobra"
2525

26+
clientset "k8s.io/client-go/kubernetes"
2627
restclient "k8s.io/client-go/rest"
2728
"k8s.io/client-go/tools/clientcmd"
28-
"k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
2929
_ "k8s.io/kubernetes/plugin/pkg/scheduler/algorithmprovider"
3030

3131
"github.com/kubernetes-incubator/cluster-capacity/cmd/genpod/app/options"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Kubernetes Community Code of Conduct
2+
3+
Please refer to our [Kubernetes Community Code of Conduct](https://git.k8s.io/community/code-of-conduct.md)

0 commit comments

Comments
 (0)