Merge pull request #2478 from smarterclayton/refactor_minion_to_match_v1beta3
Move the internal minion representation to match v1beta3
This commit is contained in:
@@ -637,30 +637,42 @@ type EndpointsList struct {
|
||||
Items []Endpoints `json:"items" yaml:"items"`
|
||||
}
|
||||
|
||||
// NodeResources represents resources on a Kubernetes system node
|
||||
// NodeSpec describes the attributes that a node is created with.
|
||||
type NodeSpec struct {
|
||||
// Capacity represents the available resources of a node
|
||||
Capacity ResourceList `json:"capacity,omitempty" yaml:"capacity,omitempty"`
|
||||
}
|
||||
|
||||
// NodeStatus is information about the current status of a node.
|
||||
type NodeStatus struct {
|
||||
// Queried from cloud provider, if available.
|
||||
HostIP string `json:"hostIP,omitempty" yaml:"hostIP,omitempty"`
|
||||
}
|
||||
|
||||
// NodeResources is an object for conveying resource information about a node.
|
||||
// see https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/resources.md for more details.
|
||||
// TODO: Use ResourceList instead?
|
||||
type NodeResources struct {
|
||||
// Capacity represents the available resources.
|
||||
// Capacity represents the available resources of a node
|
||||
Capacity ResourceList `json:"capacity,omitempty" yaml:"capacity,omitempty"`
|
||||
}
|
||||
|
||||
type ResourceName string
|
||||
|
||||
// TODO Replace this with a more complete "Quantity" struct
|
||||
type ResourceList map[ResourceName]util.IntOrString
|
||||
|
||||
// Minion is a worker node in Kubernetenes.
|
||||
// The name of the minion according to etcd is in ID.
|
||||
// Minion is a worker node in Kubernetenes
|
||||
// The name of the minion according to etcd is in ObjectMeta.Name.
|
||||
// TODO: Rename to Node
|
||||
type Minion struct {
|
||||
TypeMeta `json:",inline" yaml:",inline"`
|
||||
ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty"`
|
||||
|
||||
// Queried from cloud provider, if available.
|
||||
HostIP string `json:"hostIP,omitempty" yaml:"hostIP,omitempty"`
|
||||
// Resources available on the node
|
||||
NodeResources NodeResources `json:"resources,omitempty" yaml:"resources,omitempty"`
|
||||
// Labels for the node
|
||||
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
|
||||
// Spec defines the behavior of a node.
|
||||
Spec NodeSpec `json:"spec,omitempty" yaml:"spec,omitempty"`
|
||||
|
||||
// Status describes the current status of a Node
|
||||
Status NodeStatus `json:"status,omitempty" yaml:"status,omitempty"`
|
||||
}
|
||||
|
||||
// MinionList is a list of minions.
|
||||
|
@@ -498,12 +498,12 @@ func init() {
|
||||
if err := s.Convert(&in.ObjectMeta, &out.TypeMeta, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.Convert(&in.Labels, &out.Labels, 0); err != nil {
|
||||
if err := s.Convert(&in.ObjectMeta.Labels, &out.Labels, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
out.HostIP = in.HostIP
|
||||
return s.Convert(&in.NodeResources, &out.NodeResources, 0)
|
||||
out.HostIP = in.Status.HostIP
|
||||
return s.Convert(&in.Spec.Capacity, &out.NodeResources.Capacity, 0)
|
||||
},
|
||||
func(in *Minion, out *newer.Minion, s conversion.Scope) error {
|
||||
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
||||
@@ -512,12 +512,12 @@ func init() {
|
||||
if err := s.Convert(&in.TypeMeta, &out.ObjectMeta, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.Convert(&in.Labels, &out.Labels, 0); err != nil {
|
||||
if err := s.Convert(&in.Labels, &out.ObjectMeta.Labels, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
out.HostIP = in.HostIP
|
||||
return s.Convert(&in.NodeResources, &out.NodeResources, 0)
|
||||
out.Status.HostIP = in.HostIP
|
||||
return s.Convert(&in.NodeResources.Capacity, &out.Spec.Capacity, 0)
|
||||
},
|
||||
|
||||
func(in *newer.BoundPod, out *BoundPod, s conversion.Scope) error {
|
||||
|
@@ -427,12 +427,12 @@ func init() {
|
||||
if err := s.Convert(&in.ObjectMeta, &out.TypeMeta, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.Convert(&in.Labels, &out.Labels, 0); err != nil {
|
||||
if err := s.Convert(&in.ObjectMeta.Labels, &out.Labels, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
out.HostIP = in.HostIP
|
||||
return s.Convert(&in.NodeResources, &out.NodeResources, 0)
|
||||
out.HostIP = in.Status.HostIP
|
||||
return s.Convert(&in.Spec.Capacity, &out.NodeResources.Capacity, 0)
|
||||
},
|
||||
func(in *Minion, out *newer.Minion, s conversion.Scope) error {
|
||||
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
||||
@@ -441,12 +441,12 @@ func init() {
|
||||
if err := s.Convert(&in.TypeMeta, &out.ObjectMeta, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.Convert(&in.Labels, &out.Labels, 0); err != nil {
|
||||
if err := s.Convert(&in.Labels, &out.ObjectMeta.Labels, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
out.HostIP = in.HostIP
|
||||
return s.Convert(&in.NodeResources, &out.NodeResources, 0)
|
||||
out.Status.HostIP = in.HostIP
|
||||
return s.Convert(&in.NodeResources.Capacity, &out.Spec.Capacity, 0)
|
||||
},
|
||||
|
||||
func(in *newer.BoundPod, out *BoundPod, s conversion.Scope) error {
|
||||
|
@@ -664,24 +664,22 @@ type EndpointsList struct {
|
||||
|
||||
// NodeSpec describes the attributes that a node is created with.
|
||||
type NodeSpec struct {
|
||||
// Capacity represents the available resources of a node
|
||||
// see https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/resources.md for more details.
|
||||
Capacity ResourceList `json:"capacity,omitempty" yaml:"capacity,omitempty"`
|
||||
}
|
||||
|
||||
// NodeStatus is information about the current status of a node.
|
||||
type NodeStatus struct {
|
||||
}
|
||||
|
||||
// NodeResources represents resources on a Kubernetes system node
|
||||
// see https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/resources.md for more details.
|
||||
type NodeResources struct {
|
||||
// Capacity represents the available resources.
|
||||
Capacity ResourceList `json:"capacity,omitempty" yaml:"capacity,omitempty"`
|
||||
// Queried from cloud provider, if available.
|
||||
HostIP string `json:"hostIP,omitempty" yaml:"hostIP,omitempty"`
|
||||
}
|
||||
|
||||
type ResourceName string
|
||||
|
||||
type ResourceList map[ResourceName]util.IntOrString
|
||||
|
||||
// Node is a worker node in Kubernetenes.
|
||||
// Node is a worker node in Kubernetes.
|
||||
// The name of the node according to etcd is in ID.
|
||||
type Node struct {
|
||||
TypeMeta `json:",inline" yaml:",inline"`
|
||||
@@ -692,9 +690,6 @@ type Node struct {
|
||||
|
||||
// Status describes the current status of a Node
|
||||
Status NodeStatus `json:"status,omitempty" yaml:"status,omitempty"`
|
||||
|
||||
// NodeResources describe the resoruces available on the node.
|
||||
NodeResources NodeResources `json:"resources,omitempty" yaml:"resources,omitempty"`
|
||||
}
|
||||
|
||||
// NodeList is a list of minions.
|
||||
|
@@ -544,9 +544,7 @@ func ValidateMinion(minion *api.Minion) errs.ValidationErrorList {
|
||||
// ValidateMinionUpdate tests to make sure a minion update can be applied. Modifies oldMinion.
|
||||
func ValidateMinionUpdate(oldMinion *api.Minion, minion *api.Minion) errs.ValidationErrorList {
|
||||
allErrs := errs.ValidationErrorList{}
|
||||
// TODO: why we need two labels for minion.
|
||||
oldMinion.Labels = minion.Labels
|
||||
oldMinion.ObjectMeta.Labels = minion.ObjectMeta.Labels
|
||||
if !reflect.DeepEqual(oldMinion, minion) {
|
||||
allErrs = append(allErrs, fmt.Errorf("update contains more than labels changes"))
|
||||
}
|
||||
|
@@ -1033,13 +1033,19 @@ func TestValidateMinion(t *testing.T) {
|
||||
invalidSelector := map[string]string{"NoUppercaseOrSpecialCharsLike=Equals": "b"}
|
||||
successCases := []api.Minion{
|
||||
{
|
||||
ObjectMeta: api.ObjectMeta{Name: "abc"},
|
||||
HostIP: "something",
|
||||
Labels: validSelector,
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "abc",
|
||||
Labels: validSelector,
|
||||
},
|
||||
Status: api.NodeStatus{
|
||||
HostIP: "something",
|
||||
},
|
||||
},
|
||||
{
|
||||
ObjectMeta: api.ObjectMeta{Name: "abc"},
|
||||
HostIP: "something",
|
||||
Status: api.NodeStatus{
|
||||
HostIP: "something",
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, successCase := range successCases {
|
||||
@@ -1050,13 +1056,19 @@ func TestValidateMinion(t *testing.T) {
|
||||
|
||||
errorCases := map[string]api.Minion{
|
||||
"zero-length Name": {
|
||||
ObjectMeta: api.ObjectMeta{Name: ""},
|
||||
HostIP: "something",
|
||||
Labels: validSelector,
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "",
|
||||
Labels: validSelector,
|
||||
},
|
||||
Status: api.NodeStatus{
|
||||
HostIP: "something",
|
||||
},
|
||||
},
|
||||
"invalid-labels": {
|
||||
ObjectMeta: api.ObjectMeta{Name: "abc-123"},
|
||||
Labels: invalidSelector,
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "abc-123",
|
||||
Labels: invalidSelector,
|
||||
},
|
||||
},
|
||||
}
|
||||
for k, v := range errorCases {
|
||||
|
Reference in New Issue
Block a user