Skip to content

Commit

Permalink
fact(NSC): differentiate headless services
Browse files Browse the repository at this point in the history
Differentiate headless services from ClusterIP being none, in
preparation for handling the service.kubernetes.io/headless label. One
might thing that handling these is similar, which it sort of is and sort
of isn't. ClusterIP is an immutable field, whereas labels are mutable.
This changes our handling of ClusterIP none-ness from the presence of
the headless label.

When we consider what to do with ClusterIP being none, that is
fundamentally different, because once it is None, the k8s API guarantees
that the service won't ever change.

Whereas the label can be added and removed.
  • Loading branch information
aauren committed Jan 5, 2024
1 parent 30d3769 commit 8afdee8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pkg/controllers/proxy/network_services_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ func (nsc *NetworkServicesController) OnEndpointsUpdate(es *discovery.EndpointSl
klog.Warningf("failed to lookup any service as an owner for %s/%s", es.Namespace, es.Name)
return
}
if utils.ServiceIsHeadless(svc) {
if utils.ServiceHasNoClusterIP(svc) {
klog.V(1).Infof("The service associated with endpoint: %s/%s is headless, skipping...",
es.Namespace, es.Name)
return
Expand Down Expand Up @@ -839,7 +839,7 @@ func (nsc *NetworkServicesController) OnServiceUpdate(svc *v1.Service) {
// skip processing as we only work with VIPs in the next section. Since the ClusterIP field is immutable we don't
// need to consider previous versions of the service here as we are guaranteed if is a ClusterIP now, it was a
// ClusterIP before.
if utils.ServiceIsHeadless(svc) {
if utils.ServiceHasNoClusterIP(svc) {
klog.V(1).Infof("%s/%s is headless, skipping...", svc.Namespace, svc.Name)
return
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/routing/ecmp_vip.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func (nrc *NetworkRoutingController) tryHandleServiceUpdate(objOld, objNew inter
// skip processing as we only work with VIPs in the next section. Since the ClusterIP field is immutable we
// don't need to consider previous versions of the service here as we are guaranteed if is a ClusterIP now,
// it was a ClusterIP before.
if utils.ServiceIsHeadless(objNew) {
if utils.ServiceHasNoClusterIP(objNew) {
klog.V(1).Infof("%s/%s is headless, skipping...", svcNew.Namespace, svcNew.Name)
return
}
Expand All @@ -228,7 +228,7 @@ func (nrc *NetworkRoutingController) tryHandleServiceDelete(oldObj interface{},
klog.V(1).Infof(logMsgFormat, oldSvc.Namespace, oldSvc.Name)

// If the service is headless skip processing as we only work with VIPs in the next section.
if utils.ServiceIsHeadless(oldObj) {
if utils.ServiceHasNoClusterIP(oldObj) {
klog.V(1).Infof("%s/%s is headless, skipping...", oldSvc.Namespace, oldSvc.Name)
return
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/utils/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ func ServiceForEndpointSlice(ci *cache.Indexer, es *discovery.EndpointSlice) (in
return item, true, nil
}

// ServiceIsHeadless decides whether or not the this service is a headless service which is often useful to kube-router
// as there is no need to execute logic on most headless changes. Function takes a generic interface as its input
// parameter so that it can be used more easily in early processing if needed. If a non-service object is given,
// ServiceHasNoClusterIP decides whether or not the this service is a headless service which is often useful to
// kube-router as there is no need to execute logic on most headless changes. Function takes a generic interface as its
// input parameter so that it can be used more easily in early processing if needed. If a non-service object is given,
// function will return false.
func ServiceIsHeadless(obj interface{}) bool {
func ServiceHasNoClusterIP(obj interface{}) bool {
if svc, _ := obj.(*v1core.Service); svc != nil {
if svc.Spec.Type == v1core.ServiceTypeClusterIP {
if ClusterIPIsNone(svc.Spec.ClusterIP) && containsOnlyNone(svc.Spec.ClusterIPs) {
Expand Down

0 comments on commit 8afdee8

Please sign in to comment.