api: return endpoints target object references

Signed-off-by: Federico Simoncelli <fsimonce@redhat.com>
This commit is contained in:
Federico Simoncelli
2015-02-17 08:24:05 -05:00
parent aa4dbc0df8
commit daed0af3b5
9 changed files with 130 additions and 18 deletions

View File

@@ -767,6 +767,9 @@ type Endpoint struct {
// Required: The destination port to access.
Port int `json:"port"`
// Optional: The kubernetes object related to the entry point.
TargetRef *ObjectReference `json:"targetRef,omitempty"`
}
// EndpointsList is a list of endpoints.

View File

@@ -36,6 +36,7 @@ func init() {
newer.Scheme.AddStructFieldConversion(newer.TypeMeta{}, "TypeMeta", TypeMeta{}, "TypeMeta")
newer.Scheme.AddStructFieldConversion(newer.ObjectMeta{}, "ObjectMeta", TypeMeta{}, "TypeMeta")
newer.Scheme.AddStructFieldConversion(newer.ListMeta{}, "ListMeta", TypeMeta{}, "TypeMeta")
newer.Scheme.AddStructFieldConversion(newer.Endpoints{}, "Endpoints", Endpoints{}, "Endpoints")
// TODO: scope this to a specific type once that becomes available and remove the Event conversion functions below
// newer.Scheme.AddStructFieldConversion(string(""), "Status", string(""), "Condition")
@@ -1177,7 +1178,17 @@ func init() {
}
for i := range in.Endpoints {
ep := &in.Endpoints[i]
out.Endpoints = append(out.Endpoints, net.JoinHostPort(ep.IP, strconv.Itoa(ep.Port)))
hostPort := net.JoinHostPort(ep.IP, strconv.Itoa(ep.Port))
out.Endpoints = append(out.Endpoints, hostPort)
if ep.TargetRef != nil {
target := EndpointObjectReference{
Endpoint: hostPort,
}
if err := s.Convert(ep.TargetRef, &target.ObjectReference, 0); err != nil {
return err
}
out.TargetRefs = append(out.TargetRefs, target)
}
}
return nil
},
@@ -1204,6 +1215,15 @@ func init() {
return err
}
ep.Port = pn
for j := range in.TargetRefs {
if in.TargetRefs[j].Endpoint != in.Endpoints[i] {
continue
}
ep.TargetRef = &newer.ObjectReference{}
if err := s.Convert(&in.TargetRefs[j].ObjectReference, ep.TargetRef, 0); err != nil {
return err
}
}
}
return nil
},

View File

@@ -602,6 +602,12 @@ type Service struct {
SessionAffinity AffinityType `json:"sessionAffinity,omitempty" description:"enable client IP based session affinity; must be ClientIP or None; defaults to None"`
}
// EndpointObjectReference is a reference to an object exposing the endpoint
type EndpointObjectReference struct {
Endpoint string `json:"endpoint" description:"endpoint exposed by the referenced object"`
ObjectReference `json:"targetRef" description:"reference to the object providing the entry point"`
}
// Endpoints is a collection of endpoints that implement the actual service, for example:
// Name: "mysql", Endpoints: ["10.10.1.1:1909", "10.10.2.2:8834"]
type Endpoints struct {
@@ -610,6 +616,8 @@ type Endpoints struct {
// "UDP". Defaults to "TCP".
Protocol Protocol `json:"protocol,omitempty" description:"IP protocol for endpoint ports; must be UDP or TCP; TCP if unspecified"`
Endpoints []string `json:"endpoints" description:"list of endpoints corresponding to a service, of the form address:port, such as 10.10.1.1:1909"`
// Optional: The kubernetes object related to the entry point.
TargetRefs []EndpointObjectReference `json:"targetRefs,omitempty" description:"list of references to objects providing the endpoints"`
}
// EndpointsList is a list of endpoints.

View File

@@ -36,6 +36,7 @@ func init() {
newer.Scheme.AddStructFieldConversion(newer.TypeMeta{}, "TypeMeta", TypeMeta{}, "TypeMeta")
newer.Scheme.AddStructFieldConversion(newer.ObjectMeta{}, "ObjectMeta", TypeMeta{}, "TypeMeta")
newer.Scheme.AddStructFieldConversion(newer.ListMeta{}, "ListMeta", TypeMeta{}, "TypeMeta")
newer.Scheme.AddStructFieldConversion(newer.Endpoints{}, "Endpoints", Endpoints{}, "Endpoints")
// TODO: scope this to a specific type once that becomes available and remove the Event conversion functions below
// newer.Scheme.AddStructFieldConversion(string(""), "Status", string(""), "Condition")
@@ -1093,7 +1094,17 @@ func init() {
}
for i := range in.Endpoints {
ep := &in.Endpoints[i]
out.Endpoints = append(out.Endpoints, net.JoinHostPort(ep.IP, strconv.Itoa(ep.Port)))
hostPort := net.JoinHostPort(ep.IP, strconv.Itoa(ep.Port))
out.Endpoints = append(out.Endpoints, hostPort)
if ep.TargetRef != nil {
target := EndpointObjectReference{
Endpoint: hostPort,
}
if err := s.Convert(ep.TargetRef, &target.ObjectReference, 0); err != nil {
return err
}
out.TargetRefs = append(out.TargetRefs, target)
}
}
return nil
},
@@ -1120,6 +1131,15 @@ func init() {
return err
}
ep.Port = pn
for j := range in.TargetRefs {
if in.TargetRefs[j].Endpoint != in.Endpoints[i] {
continue
}
ep.TargetRef = &newer.ObjectReference{}
if err := s.Convert(&in.TargetRefs[j], ep.TargetRef, 0); err != nil {
return err
}
}
}
return nil
},

View File

@@ -607,6 +607,12 @@ type Service struct {
SessionAffinity AffinityType `json:"sessionAffinity,omitempty" description:"enable client IP based session affinity; must be ClientIP or None; defaults to None"`
}
// EndpointObjectReference is a reference to an object exposing the endpoint
type EndpointObjectReference struct {
Endpoint string `json:"endpoint" description:"endpoint exposed by the referenced object"`
ObjectReference `json:"targetRef" description:"reference to the object providing the entry point"`
}
// Endpoints is a collection of endpoints that implement the actual service, for example:
// Name: "mysql", Endpoints: ["10.10.1.1:1909", "10.10.2.2:8834"]
type Endpoints struct {
@@ -615,6 +621,8 @@ type Endpoints struct {
// "UDP". Defaults to "TCP".
Protocol Protocol `json:"protocol,omitempty" description:"IP protocol for endpoint ports; must be UDP or TCP; TCP if unspecified"`
Endpoints []string `json:"endpoints" description:"list of endpoints corresponding to a service, of the form address:port, such as 10.10.1.1:1909"`
// Optional: The kubernetes object related to the entry point.
TargetRefs []EndpointObjectReference `json:"targetRefs,omitempty" description:"list of references to objects providing the endpoints"`
}
// EndpointsList is a list of endpoints.

View File

@@ -798,6 +798,9 @@ type Endpoint struct {
// Required: The destination port to access.
Port int `json:"port" description:"destination port of this endpoint"`
// Optional: The kubernetes object related to the entry point.
TargetRef *ObjectReference `json:"targetRef,omitempty" description:"reference to object providing the endpoint"`
}
// EndpointsList is a list of endpoints.