Add a resource fit scheduler predicate. Set sensible defaults.
This commit is contained in:
@@ -26,6 +26,7 @@ import (
|
||||
"github.com/mitchellh/goamz/aws"
|
||||
"github.com/mitchellh/goamz/ec2"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
|
||||
)
|
||||
|
||||
@@ -179,3 +180,7 @@ func (aws *AWSCloud) List(filter string) ([]string, error) {
|
||||
// TODO: Should really use tag query. No need to go regexp.
|
||||
return aws.getInstancesByRegex(filter)
|
||||
}
|
||||
|
||||
func (v *AWSCloud) GetNodeResources(name string) (*api.NodeResources, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
@@ -18,6 +18,8 @@ package cloudprovider
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
)
|
||||
|
||||
// Interface is an abstract, pluggable interface for cloud providers.
|
||||
@@ -49,6 +51,8 @@ type Instances interface {
|
||||
IPAddress(name string) (net.IP, error)
|
||||
// List lists instances that match 'filter' which is a regular expression which must match the entire instance name (fqdn)
|
||||
List(filter string) ([]string, error)
|
||||
// GetNodeResources gets the resources for a particular node
|
||||
GetNodeResources(name string) (*api.NodeResources, error)
|
||||
}
|
||||
|
||||
// Zone represents the location of a particular machine.
|
||||
|
@@ -20,16 +20,19 @@ import (
|
||||
"net"
|
||||
"regexp"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
|
||||
)
|
||||
|
||||
// FakeCloud is a test-double implementation of Interface, TCPLoadBalancer and Instances. It is useful for testing.
|
||||
type FakeCloud struct {
|
||||
Exists bool
|
||||
Err error
|
||||
Calls []string
|
||||
IP net.IP
|
||||
Machines []string
|
||||
Exists bool
|
||||
Err error
|
||||
Calls []string
|
||||
IP net.IP
|
||||
Machines []string
|
||||
NodeResources *api.NodeResources
|
||||
|
||||
cloudprovider.Zone
|
||||
}
|
||||
|
||||
@@ -110,3 +113,8 @@ func (f *FakeCloud) GetZone() (cloudprovider.Zone, error) {
|
||||
f.addCall("get-zone")
|
||||
return f.Zone, f.Err
|
||||
}
|
||||
|
||||
func (f *FakeCloud) GetNodeResources(name string) (*api.NodeResources, error) {
|
||||
f.addCall("get-node-resources")
|
||||
return f.NodeResources, f.Err
|
||||
}
|
||||
|
@@ -29,7 +29,10 @@ import (
|
||||
|
||||
"code.google.com/p/goauth2/compute/serviceaccount"
|
||||
compute "code.google.com/p/google-api-go-client/compute/v1"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/resources"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
||||
@@ -254,6 +257,48 @@ func (gce *GCECloud) List(filter string) ([]string, error) {
|
||||
return instances, nil
|
||||
}
|
||||
|
||||
func makeResources(cpu float32, memory float32) *api.NodeResources {
|
||||
return &api.NodeResources{
|
||||
Capacity: api.ResourceList{
|
||||
resources.CPU: util.NewIntOrStringFromInt(int(cpu * 1000)),
|
||||
resources.Memory: util.NewIntOrStringFromInt(int(memory * 1024 * 1024 * 1024)),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func canonicalizeMachineType(machineType string) string {
|
||||
ix := strings.LastIndex(machineType, "/")
|
||||
return machineType[ix+1:]
|
||||
}
|
||||
|
||||
func (gce *GCECloud) GetNodeResources(name string) (*api.NodeResources, error) {
|
||||
instance := canonicalizeInstanceName(name)
|
||||
instanceCall := gce.service.Instances.Get(gce.projectID, gce.zone, instance)
|
||||
res, err := instanceCall.Do()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch canonicalizeMachineType(res.MachineType) {
|
||||
case "f1-micro":
|
||||
return makeResources(1, 0.6), nil
|
||||
case "g1-small":
|
||||
return makeResources(1, 1.70), nil
|
||||
case "n1-standard-1":
|
||||
return makeResources(1, 3.75), nil
|
||||
case "n1-standard-2":
|
||||
return makeResources(2, 7.5), nil
|
||||
case "n1-standard-4":
|
||||
return makeResources(4, 15), nil
|
||||
case "n1-standard-8":
|
||||
return makeResources(8, 30), nil
|
||||
case "n1-standard-16":
|
||||
return makeResources(16, 30), nil
|
||||
default:
|
||||
glog.Errorf("unknown machine: %s", res.MachineType)
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (gce *GCECloud) GetZone() (cloudprovider.Zone, error) {
|
||||
region, err := getGceRegion(gce.zone)
|
||||
if err != nil {
|
||||
|
@@ -28,6 +28,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"code.google.com/p/gcfg"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
|
||||
)
|
||||
|
||||
@@ -154,3 +155,7 @@ func (v *OVirtCloud) List(filter string) ([]string, error) {
|
||||
|
||||
return getInstancesFromXml(response.Body)
|
||||
}
|
||||
|
||||
func (v *OVirtCloud) GetNodeResources(name string) (*api.NodeResources, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
@@ -27,6 +27,7 @@ import (
|
||||
neturl "net/url"
|
||||
"sort"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
|
||||
)
|
||||
|
||||
@@ -209,3 +210,7 @@ func (v *VagrantCloud) List(filter string) ([]string, error) {
|
||||
|
||||
return instances, nil
|
||||
}
|
||||
|
||||
func (v *VagrantCloud) GetNodeResources(name string) (*api.NodeResources, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user