plugin/kubernetes: Remove Endpoint and EndpointSlice v1beta Support (#6147)
* remove endpoint and endpointslicev1beta watch support Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * adjust readme Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * informer object changes Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * remove unused funcs Signed-off-by: Chris O'Haver <cohaver@infoblox.com> --------- Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
This commit is contained in:
parent
6e6fc650ce
commit
06cd843918
4 changed files with 1 additions and 276 deletions
|
@ -3,9 +3,7 @@ package object
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
api "k8s.io/api/core/v1"
|
||||
discovery "k8s.io/api/discovery/v1"
|
||||
discoveryV1beta1 "k8s.io/api/discovery/v1beta1"
|
||||
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
)
|
||||
|
@ -48,60 +46,6 @@ type EndpointPort struct {
|
|||
// EndpointsKey returns a string using for the index.
|
||||
func EndpointsKey(name, namespace string) string { return name + "." + namespace }
|
||||
|
||||
// ToEndpoints converts an *api.Endpoints to a *Endpoints.
|
||||
func ToEndpoints(obj meta.Object) (meta.Object, error) {
|
||||
end, ok := obj.(*api.Endpoints)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected object %v", obj)
|
||||
}
|
||||
e := &Endpoints{
|
||||
Version: end.GetResourceVersion(),
|
||||
Name: end.GetName(),
|
||||
Namespace: end.GetNamespace(),
|
||||
Index: EndpointsKey(end.GetName(), end.GetNamespace()),
|
||||
Subsets: make([]EndpointSubset, len(end.Subsets)),
|
||||
}
|
||||
for i, eps := range end.Subsets {
|
||||
sub := EndpointSubset{
|
||||
Addresses: make([]EndpointAddress, len(eps.Addresses)),
|
||||
}
|
||||
if len(eps.Ports) == 0 {
|
||||
// Add sentinel if there are no ports.
|
||||
sub.Ports = []EndpointPort{{Port: -1}}
|
||||
} else {
|
||||
sub.Ports = make([]EndpointPort, len(eps.Ports))
|
||||
}
|
||||
|
||||
for j, a := range eps.Addresses {
|
||||
ea := EndpointAddress{IP: a.IP, Hostname: a.Hostname}
|
||||
if a.NodeName != nil {
|
||||
ea.NodeName = *a.NodeName
|
||||
}
|
||||
if a.TargetRef != nil {
|
||||
ea.TargetRefName = a.TargetRef.Name
|
||||
}
|
||||
sub.Addresses[j] = ea
|
||||
}
|
||||
|
||||
for k, p := range eps.Ports {
|
||||
ep := EndpointPort{Port: p.Port, Name: p.Name, Protocol: string(p.Protocol)}
|
||||
sub.Ports[k] = ep
|
||||
}
|
||||
|
||||
e.Subsets[i] = sub
|
||||
}
|
||||
|
||||
for _, eps := range end.Subsets {
|
||||
for _, a := range eps.Addresses {
|
||||
e.IndexIP = append(e.IndexIP, a.IP)
|
||||
}
|
||||
}
|
||||
|
||||
*end = api.Endpoints{}
|
||||
|
||||
return e, nil
|
||||
}
|
||||
|
||||
// EndpointSliceToEndpoints converts a *discovery.EndpointSlice to a *Endpoints.
|
||||
func EndpointSliceToEndpoints(obj meta.Object) (meta.Object, error) {
|
||||
ends, ok := obj.(*discovery.EndpointSlice)
|
||||
|
@ -153,55 +97,6 @@ func EndpointSliceToEndpoints(obj meta.Object) (meta.Object, error) {
|
|||
return e, nil
|
||||
}
|
||||
|
||||
// EndpointSliceV1beta1ToEndpoints converts a v1beta1 *discovery.EndpointSlice to a *Endpoints.
|
||||
func EndpointSliceV1beta1ToEndpoints(obj meta.Object) (meta.Object, error) {
|
||||
ends, ok := obj.(*discoveryV1beta1.EndpointSlice)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected object %v", obj)
|
||||
}
|
||||
e := &Endpoints{
|
||||
Version: ends.GetResourceVersion(),
|
||||
Name: ends.GetName(),
|
||||
Namespace: ends.GetNamespace(),
|
||||
Index: EndpointsKey(ends.Labels[discovery.LabelServiceName], ends.GetNamespace()),
|
||||
Subsets: make([]EndpointSubset, 1),
|
||||
}
|
||||
|
||||
if len(ends.Ports) == 0 {
|
||||
// Add sentinel if there are no ports.
|
||||
e.Subsets[0].Ports = []EndpointPort{{Port: -1}}
|
||||
} else {
|
||||
e.Subsets[0].Ports = make([]EndpointPort, len(ends.Ports))
|
||||
for k, p := range ends.Ports {
|
||||
ep := EndpointPort{Port: *p.Port, Name: *p.Name, Protocol: string(*p.Protocol)}
|
||||
e.Subsets[0].Ports[k] = ep
|
||||
}
|
||||
}
|
||||
|
||||
for _, end := range ends.Endpoints {
|
||||
if !endpointsliceReady(end.Conditions.Ready) {
|
||||
continue
|
||||
}
|
||||
for _, a := range end.Addresses {
|
||||
ea := EndpointAddress{IP: a}
|
||||
if end.Hostname != nil {
|
||||
ea.Hostname = *end.Hostname
|
||||
}
|
||||
// ignore pod names that are too long to be a valid label
|
||||
if end.TargetRef != nil && len(end.TargetRef.Name) < 64 {
|
||||
ea.TargetRefName = end.TargetRef.Name
|
||||
}
|
||||
// EndpointSlice does not contain NodeName, leave blank
|
||||
e.Subsets[0].Addresses = append(e.Subsets[0].Addresses, ea)
|
||||
e.IndexIP = append(e.IndexIP, a)
|
||||
}
|
||||
}
|
||||
|
||||
*ends = discoveryV1beta1.EndpointSlice{}
|
||||
|
||||
return e, nil
|
||||
}
|
||||
|
||||
func endpointsliceReady(ready *bool) bool {
|
||||
// Per API docs: a nil value indicates an unknown state. In most cases consumers
|
||||
// should interpret this unknown state as ready.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue