Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/api/deep_copy_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,7 @@ func deepCopy_api_NodeList(in NodeList, out *NodeList, c *conversion.Cloner) err
func deepCopy_api_NodeSpec(in NodeSpec, out *NodeSpec, c *conversion.Cloner) error {
out.PodCIDR = in.PodCIDR
out.ExternalID = in.ExternalID
out.ProviderID = in.ProviderID
out.Unschedulable = in.Unschedulable
return nil
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,10 @@ type NodeSpec struct {
// External ID of the node assigned by some machine database (e.g. a cloud provider)
ExternalID string `json:"externalID,omitempty"`

// ID of the node assigned by the cloud provider
// Note: format is "<ProviderName>://<ProviderSpecificNodeID>"
ProviderID string `json:"providerID,omitempty"`

// Unschedulable controls node schedulability of new pods. By default node is schedulable.
Unschedulable bool `json:"unschedulable,omitempty"`
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/api/v1/conversion_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,7 @@ func convert_api_NodeSpec_To_v1_NodeSpec(in *api.NodeSpec, out *NodeSpec, s conv
}
out.PodCIDR = in.PodCIDR
out.ExternalID = in.ExternalID
out.ProviderID = in.ProviderID
out.Unschedulable = in.Unschedulable
return nil
}
Expand Down Expand Up @@ -3269,6 +3270,7 @@ func convert_v1_NodeSpec_To_api_NodeSpec(in *NodeSpec, out *api.NodeSpec, s conv
}
out.PodCIDR = in.PodCIDR
out.ExternalID = in.ExternalID
out.ProviderID = in.ProviderID
out.Unschedulable = in.Unschedulable
return nil
}
Expand Down
1 change: 1 addition & 0 deletions pkg/api/v1/deep_copy_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,7 @@ func deepCopy_v1_NodeList(in NodeList, out *NodeList, c *conversion.Cloner) erro
func deepCopy_v1_NodeSpec(in NodeSpec, out *NodeSpec, c *conversion.Cloner) error {
out.PodCIDR = in.PodCIDR
out.ExternalID = in.ExternalID
out.ProviderID = in.ProviderID
out.Unschedulable = in.Unschedulable
return nil
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/api/v1/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,9 @@ func TestSetDefaultNodeExternalID(t *testing.T) {
if n2.Spec.ExternalID != name {
t.Errorf("Expected default External ID: %s, got: %s", name, n2.Spec.ExternalID)
}
if n2.Spec.ProviderID != "" {
t.Errorf("Expected empty default Cloud Provider ID, got: %s", n2.Spec.ProviderID)
}
}

func TestSetDefaultObjectFieldSelectorAPIVersion(t *testing.T) {
Expand Down
4 changes: 3 additions & 1 deletion pkg/api/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,9 @@ type NodeSpec struct {
// PodCIDR represents the pod IP range assigned to the node
PodCIDR string `json:"podCIDR,omitempty" description:"pod IP range assigned to the node"`
// External ID of the node assigned by some machine database (e.g. a cloud provider)
ExternalID string `json:"externalID,omitempty" description:"external ID assigned to the node by some machine database (e.g. a cloud provider). Defaults to node name when empty."`
ExternalID string `json:"externalID,omitempty" description:"deprecated. External ID assigned to the node by some machine database (e.g. a cloud provider). Defaults to node name when empty."`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bgrant0607 do we want to put a deprecated field into the v1 api?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. We'll rip it out when we rip out the beta API versions.

// ID of the node assigned by the cloud provider
ProviderID string `json:"providerID,omitempty" description:"ID of the node assigned by the cloud provider in the format: <ProviderName>://<ProviderSpecificNodeID>"`
// Unschedulable controls node schedulability of new pods. By default node is schedulable.
Unschedulable bool `json:"unschedulable,omitempty" description:"disable pod scheduling on the node"`
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/api/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,7 @@ func addConversionFuncs() {
}
out.PodCIDR = in.Spec.PodCIDR
out.ExternalID = in.Spec.ExternalID
out.ProviderID = in.Spec.ProviderID
out.Unschedulable = in.Spec.Unschedulable
return s.Convert(&in.Status.Capacity, &out.NodeResources.Capacity, 0)
},
Expand Down Expand Up @@ -920,6 +921,7 @@ func addConversionFuncs() {
}
out.Spec.PodCIDR = in.PodCIDR
out.Spec.ExternalID = in.ExternalID
out.Spec.ProviderID = in.ProviderID
out.Spec.Unschedulable = in.Unschedulable
return s.Convert(&in.NodeResources.Capacity, &out.Status.Capacity, 0)
},
Expand Down
3 changes: 3 additions & 0 deletions pkg/api/v1beta1/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,9 @@ func TestSetDefaultMinionExternalID(t *testing.T) {
if m2.ExternalID != name {
t.Errorf("Expected default External ID: %s, got: %s", name, m2.ExternalID)
}
if m2.ProviderID != "" {
t.Errorf("Expected empty default Cloud Provider ID, got: %s", m2.ProviderID)
}
}

func TestSetDefaultObjectFieldSelectorAPIVersion(t *testing.T) {
Expand Down
4 changes: 3 additions & 1 deletion pkg/api/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,9 @@ type Minion struct {
// Labels for the node
Labels map[string]string `json:"labels,omitempty" description:"map of string keys and values that can be used to organize and categorize minions; labels of a minion assigned by the scheduler must match the scheduled pod's nodeSelector"`
// External ID of the node
ExternalID string `json:"externalID,omitempty" description:"external id of the node assigned by some machine database (e.g. a cloud provider). Defaults to node name when empty."`
ExternalID string `json:"externalID,omitempty" description:"deprecated. External id of the node assigned by some machine database (e.g. a cloud provider). Defaults to node name when empty."`
// ID of the node assigned by the cloud provider
ProviderID string `json:"providerID,omitempty" description:"ID of the node assigned by the cloud provider in the format: <ProviderName>://<ProviderSpecificNodeID>"`
}

// MinionList is a list of minions.
Expand Down
2 changes: 2 additions & 0 deletions pkg/api/v1beta2/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,7 @@ func addConversionFuncs() {
}
out.PodCIDR = in.Spec.PodCIDR
out.ExternalID = in.Spec.ExternalID
out.ProviderID = in.Spec.ProviderID
out.Unschedulable = in.Spec.Unschedulable
return s.Convert(&in.Status.Capacity, &out.NodeResources.Capacity, 0)
},
Expand Down Expand Up @@ -842,6 +843,7 @@ func addConversionFuncs() {
}
out.Spec.PodCIDR = in.PodCIDR
out.Spec.ExternalID = in.ExternalID
out.Spec.ProviderID = in.ProviderID
out.Spec.Unschedulable = in.Unschedulable
return s.Convert(&in.NodeResources.Capacity, &out.Status.Capacity, 0)
},
Expand Down
3 changes: 3 additions & 0 deletions pkg/api/v1beta2/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ func TestSetDefaultMinionExternalID(t *testing.T) {
if m2.ExternalID != name {
t.Errorf("Expected default External ID: %s, got: %s", name, m2.ExternalID)
}
if m2.ProviderID != "" {
t.Errorf("Expected empty default Cloud Provider ID, got: %s", m2.ProviderID)
}
}

func TestSetDefaultObjectFieldSelectorAPIVersion(t *testing.T) {
Expand Down
4 changes: 3 additions & 1 deletion pkg/api/v1beta2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,9 @@ type Minion struct {
// Labels for the node
Labels map[string]string `json:"labels,omitempty" description:"map of string keys and values that can be used to organize and categorize minions; labels of a minion assigned by the scheduler must match the scheduled pod's nodeSelector"`
// External ID of the node
ExternalID string `json:"externalID,omitempty" description:"external id of the node assigned by some machine database (e.g. a cloud provider). Defaults to node name when empty."`
ExternalID string `json:"externalID,omitempty" description:"deprecated. External id of the node assigned by some machine database (e.g. a cloud provider). Defaults to node name when empty."`
// ID of the node assigned by the cloud provider
ProviderID string `json:"providerID,omitempty" description:"ID of the node assigned by the cloud provider in the format: <ProviderName>://<ProviderSpecificNodeID>"`
}

// MinionList is a list of minions.
Expand Down
2 changes: 2 additions & 0 deletions pkg/api/v1beta3/conversion_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,7 @@ func convert_api_NodeSpec_To_v1beta3_NodeSpec(in *api.NodeSpec, out *NodeSpec, s
}
out.PodCIDR = in.PodCIDR
out.ExternalID = in.ExternalID
out.ProviderID = in.ProviderID
out.Unschedulable = in.Unschedulable
return nil
}
Expand Down Expand Up @@ -3109,6 +3110,7 @@ func convert_v1beta3_NodeSpec_To_api_NodeSpec(in *NodeSpec, out *api.NodeSpec, s
}
out.PodCIDR = in.PodCIDR
out.ExternalID = in.ExternalID
out.ProviderID = in.ProviderID
out.Unschedulable = in.Unschedulable
return nil
}
Expand Down
1 change: 1 addition & 0 deletions pkg/api/v1beta3/deep_copy_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,7 @@ func deepCopy_v1beta3_NodeList(in NodeList, out *NodeList, c *conversion.Cloner)
func deepCopy_v1beta3_NodeSpec(in NodeSpec, out *NodeSpec, c *conversion.Cloner) error {
out.PodCIDR = in.PodCIDR
out.ExternalID = in.ExternalID
out.ProviderID = in.ProviderID
out.Unschedulable = in.Unschedulable
return nil
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/api/v1beta3/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,9 @@ func TestSetDefaultNodeExternalID(t *testing.T) {
if n2.Spec.ExternalID != name {
t.Errorf("Expected default External ID: %s, got: %s", name, n2.Spec.ExternalID)
}
if n2.Spec.ProviderID != "" {
t.Errorf("Expected empty default Cloud Provider ID, got: %s", n2.Spec.ProviderID)
}
}

func TestSetDefaultObjectFieldSelectorAPIVersion(t *testing.T) {
Expand Down
4 changes: 3 additions & 1 deletion pkg/api/v1beta3/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,9 @@ type NodeSpec struct {
// PodCIDR represents the pod IP range assigned to the node
PodCIDR string `json:"podCIDR,omitempty" description:"pod IP range assigned to the node"`
// External ID of the node assigned by some machine database (e.g. a cloud provider)
ExternalID string `json:"externalID,omitempty" description:"external ID assigned to the node by some machine database (e.g. a cloud provider). Defaults to node name when empty."`
ExternalID string `json:"externalID,omitempty" description:"deprecated. External ID assigned to the node by some machine database (e.g. a cloud provider). Defaults to node name when empty."`
// ID of the node assigned by the cloud provider
ProviderID string `json:"providerID,omitempty" description:"ID of the node assigned by the cloud provider in the format: <ProviderName>://<ProviderSpecificNodeID>"`
// Unschedulable controls node schedulability of new pods. By default node is schedulable.
Unschedulable bool `json:"unschedulable,omitempty" description:"disable pod scheduling on the node"`
}
Expand Down
22 changes: 20 additions & 2 deletions pkg/cloudprovider/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import (
"github.com/golang/glog"
)

const ProviderName = "aws"

// Abstraction over EC2, to allow mocking/other implementations
type EC2 interface {
// Query EC2 for instances matching the filter
Expand Down Expand Up @@ -250,7 +252,7 @@ func (s *awsSdkEC2) DeleteVolume(volumeID string) (resp *ec2.DeleteVolumeOutput,
}

func init() {
cloudprovider.RegisterCloudProvider("aws", func(config io.Reader) (cloudprovider.Interface, error) {
cloudprovider.RegisterCloudProvider(ProviderName, func(config io.Reader) (cloudprovider.Interface, error) {
metadata := &awsSdkMetadata{}
return newAWSCloud(config, getAuth, metadata)
})
Expand Down Expand Up @@ -366,6 +368,11 @@ func (aws *AWSCloud) Clusters() (cloudprovider.Clusters, bool) {
return nil, false
}

// ProviderName returns the cloud provider ID.
func (aws *AWSCloud) ProviderName() string {
return ProviderName
}

// TCPLoadBalancer returns an implementation of TCPLoadBalancer for Amazon Web Services.
func (aws *AWSCloud) TCPLoadBalancer() (cloudprovider.TCPLoadBalancer, bool) {
return nil, false
Expand Down Expand Up @@ -420,7 +427,7 @@ func (aws *AWSCloud) NodeAddresses(name string) ([]api.NodeAddress, error) {
return addresses, nil
}

// ExternalID returns the cloud provider ID of the specified instance.
// ExternalID returns the cloud provider ID of the specified instance (deprecated).
func (aws *AWSCloud) ExternalID(name string) (string, error) {
inst, err := aws.getInstancesByDnsName(name)
if err != nil {
Expand All @@ -429,6 +436,17 @@ func (aws *AWSCloud) ExternalID(name string) (string, error) {
return *inst.InstanceID, nil
}

// InstanceID returns the cloud provider ID of the specified instance.
func (aws *AWSCloud) InstanceID(name string) (string, error) {
inst, err := aws.getInstancesByDnsName(name)
if err != nil {
return "", err
}
// In the future it is possible to also return an endpoint as:
// <endpoint>/<zone>/<instanceid>
return "/" + *inst.Placement.AvailabilityZone + "/" + *inst.InstanceID, nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should InstanceID return a name with a leading slash (here and all other cloudproviders)? You prefix it with ProviderName() followed by :// to produce the providerID. Also, please document the expectation in the interface declaration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a comment above: in the future the format may be: <endpoint>/<zone>/<instanceid>
Therefore now for aws we would have: aws:///<zone>/<instanceid> because <endpoint> is empty.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok.

}

// Return the instances matching the relevant private dns name.
func (aws *AWSCloud) getInstancesByDnsName(name string) (*ec2.Instance, error) {
f := &ec2InstanceFilter{}
Expand Down
19 changes: 18 additions & 1 deletion pkg/cloudprovider/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cloudprovider

import (
"errors"
"fmt"
"net"
"strings"

Expand All @@ -36,6 +37,8 @@ type Interface interface {
Clusters() (Clusters, bool)
// Routes returns a routes interface along with whether the interface is supported.
Routes() (Routes, bool)
// ProviderName returns the cloud provider ID.
ProviderName() string
}

// Clusters is an abstract, pluggable interface for clusters of containers.
Expand All @@ -59,6 +62,18 @@ func GetLoadBalancerName(service *api.Service) string {
return ret
}

func GetInstanceProviderID(cloud Interface, nodeName string) (string, error) {
instances, ok := cloud.Instances()
if !ok {
return "", fmt.Errorf("failed to get instances from cloud provider")
}
instanceID, err := instances.InstanceID(nodeName)
if err != nil {
return "", fmt.Errorf("failed to get instance ID from cloud provider: %v", err)
}
return cloud.ProviderName() + "://" + instanceID, nil
}

// TCPLoadBalancer is an abstract, pluggable interface for TCP load balancers.
type TCPLoadBalancer interface {
// TODO: Break this up into different interfaces (LB, etc) when we have more than one type of service
Expand All @@ -85,8 +100,10 @@ type Instances interface {
// returns the address of the calling instance. We should do a rename to
// make this clearer.
NodeAddresses(name string) ([]api.NodeAddress, error)
// ExternalID returns the cloud provider ID of the specified instance.
// ExternalID returns the cloud provider ID of the specified instance (deprecated).
ExternalID(name string) (string, error)
// InstanceID returns the cloud provider ID of the specified instance.
InstanceID(name string) (string, 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
Expand Down
13 changes: 13 additions & 0 deletions pkg/cloudprovider/fake/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
)

const ProviderName = "fake"

// FakeBalancer is a fake storage of balancer information
type FakeBalancer struct {
Name string
Expand Down Expand Up @@ -81,6 +83,11 @@ func (f *FakeCloud) Clusters() (cloudprovider.Clusters, bool) {
return f, true
}

// ProviderName returns the cloud provider ID.
func (f *FakeCloud) ProviderName() string {
return ProviderName
}

// TCPLoadBalancer returns a fake implementation of TCPLoadBalancer.
// Actually it just returns f itself.
func (f *FakeCloud) TCPLoadBalancer() (cloudprovider.TCPLoadBalancer, bool) {
Expand Down Expand Up @@ -152,6 +159,12 @@ func (f *FakeCloud) ExternalID(instance string) (string, error) {
return f.ExtID[instance], f.Err
}

// InstanceID returns the cloud provider ID of the specified instance.
func (f *FakeCloud) InstanceID(instance string) (string, error) {
f.addCall("instance-id")
return f.ExtID[instance], nil
}

// List is a test-spy implementation of Instances.List.
// It adds an entry "list" into the internal method call record.
func (f *FakeCloud) List(filter string) ([]string, error) {
Expand Down
16 changes: 14 additions & 2 deletions pkg/cloudprovider/gce/gce.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import (
"google.golang.org/cloud/compute/metadata"
)

const ProviderName = "gce"

const EXTERNAL_IP_METADATA_URL = "http://169.254.169.254/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip"

// GCECloud is an implementation of Interface, TCPLoadBalancer and Instances for Google Compute Engine.
Expand All @@ -67,7 +69,7 @@ type Config struct {
}

func init() {
cloudprovider.RegisterCloudProvider("gce", func(config io.Reader) (cloudprovider.Interface, error) { return newGCECloud(config) })
cloudprovider.RegisterCloudProvider(ProviderName, func(config io.Reader) (cloudprovider.Interface, error) { return newGCECloud(config) })
}

func getMetadata(url string) (string, error) {
Expand Down Expand Up @@ -182,6 +184,11 @@ func (gce *GCECloud) Clusters() (cloudprovider.Clusters, bool) {
return gce, true
}

// ProviderName returns the cloud provider ID.
func (gce *GCECloud) ProviderName() string {
return ProviderName
}

// TCPLoadBalancer returns an implementation of TCPLoadBalancer for Google Compute Engine.
func (gce *GCECloud) TCPLoadBalancer() (cloudprovider.TCPLoadBalancer, bool) {
return gce, true
Expand Down Expand Up @@ -481,7 +488,7 @@ func (gce *GCECloud) NodeAddresses(_ string) ([]api.NodeAddress, error) {
}, nil
}

// ExternalID returns the cloud provider ID of the specified instance.
// ExternalID returns the cloud provider ID of the specified instance (deprecated).
func (gce *GCECloud) ExternalID(instance string) (string, error) {
inst, err := gce.getInstanceByName(instance)
if err != nil {
Expand All @@ -490,6 +497,11 @@ func (gce *GCECloud) ExternalID(instance string) (string, error) {
return strconv.FormatUint(inst.Id, 10), nil
}

// InstanceID returns the cloud provider ID of the specified instance.
func (gce *GCECloud) InstanceID(instance string) (string, error) {
return gce.projectID + "/" + gce.zone + "/" + canonicalizeInstanceName(instance), nil
}

// List is an implementation of Instances.List.
func (gce *GCECloud) List(filter string) ([]string, error) {
listCall := gce.service.Instances.List(gce.projectID, gce.zone)
Expand Down
Loading