endpointslice: reduce visibility of vars/funcs

Reduce the visibility of various public identifiers that are only used
within the scope of a package.

This was originally motivated by KEP-3685 in order to reduce the public
API surface and improve supportability.
This commit is contained in:
Akhil Velagapudi
2023-04-16 12:47:45 -07:00
parent f3cf92b79b
commit 69eccd41b8
9 changed files with 129 additions and 120 deletions

View File

@@ -138,8 +138,8 @@ func newEndpointSlice(service *v1.Service, endpointMeta *endpointMeta) *discover
OwnerReferences: []metav1.OwnerReference{*ownerRef},
Namespace: service.Namespace,
},
Ports: endpointMeta.Ports,
AddressType: endpointMeta.AddressType,
Ports: endpointMeta.ports,
AddressType: endpointMeta.addressType,
Endpoints: []discovery.Endpoint{},
}
// add parent service labels
@@ -246,7 +246,7 @@ func setEndpointSliceLabels(epSlice *discovery.EndpointSlice, service *v1.Servic
// check if the endpoint slice and the service have the same labels
// clone current slice labels except the reserved labels
for key, value := range epSlice.Labels {
if IsReservedLabelKey(key) {
if isReservedLabelKey(key) {
continue
}
// copy endpoint slice labels
@@ -254,7 +254,7 @@ func setEndpointSliceLabels(epSlice *discovery.EndpointSlice, service *v1.Servic
}
for key, value := range service.Labels {
if IsReservedLabelKey(key) {
if isReservedLabelKey(key) {
klog.Warningf("Service %s/%s using reserved endpoint slices label, skipping label %s: %s", service.Namespace, service.Name, key, value)
continue
}
@@ -281,8 +281,8 @@ func setEndpointSliceLabels(epSlice *discovery.EndpointSlice, service *v1.Servic
return svcLabels, updated
}
// IsReservedLabelKey return true if the label is one of the reserved label for slices
func IsReservedLabelKey(label string) bool {
// isReservedLabelKey return true if the label is one of the reserved label for slices
func isReservedLabelKey(label string) bool {
if label == discovery.LabelServiceName ||
label == discovery.LabelManagedBy ||
label == v1.IsHeadlessService {
@@ -405,3 +405,13 @@ func managedByController(endpointSlice *discovery.EndpointSlice) bool {
managedBy, _ := endpointSlice.Labels[discovery.LabelManagedBy]
return managedBy == controllerName
}
// isNodeReady returns true if a node is ready; false otherwise.
func isNodeReady(node *v1.Node) bool {
for _, c := range node.Status.Conditions {
if c.Type == v1.NodeReady {
return c.Status == v1.ConditionTrue
}
}
return false
}