@@ -48,6 +48,7 @@ import (
48
48
"knative.dev/pkg/controller"
49
49
"knative.dev/pkg/logging"
50
50
"knative.dev/pkg/logging/logkey"
51
+ "knative.dev/pkg/network"
51
52
"knative.dev/pkg/reconciler"
52
53
"knative.dev/serving/pkg/apis/serving"
53
54
revisioninformer "knative.dev/serving/pkg/client/injection/informers/serving/v1/revision"
@@ -62,9 +63,9 @@ import (
62
63
// ClusterIPDest will be set to non empty string and Dests will be nil. Otherwise Dests will be set
63
64
// to a slice of healthy l4 dests for reaching the revision.
64
65
type revisionDestsUpdate struct {
65
- Rev types.NamespacedName
66
- ClusterIPDest string
67
- Dests sets.Set [string ]
66
+ Rev types.NamespacedName
67
+ PrivateService string
68
+ Dests sets.Set [string ]
68
69
}
69
70
70
71
type dests struct {
@@ -91,7 +92,7 @@ const (
91
92
defaultProbeFrequency time.Duration = 200 * time .Millisecond
92
93
)
93
94
94
- // revisionWatcher watches the podIPs and ClusterIP of the service for a revision. It implements the logic
95
+ // revisionWatcher watches the podIPs/ service of a revision. It implements the logic
95
96
// to supply revisionDestsUpdate events on updateCh
96
97
type revisionWatcher struct {
97
98
stopCh <- chan struct {}
@@ -103,8 +104,9 @@ type revisionWatcher struct {
103
104
104
105
// Stores the list of pods that have been successfully probed.
105
106
healthyPods sets.Set [string ]
106
- // Stores whether the service ClusterIP has been seen as healthy.
107
- clusterIPHealthy bool
107
+
108
+ // Stores whether the private k8s service has been seen as healthy.
109
+ privateServiceHealthy bool
108
110
109
111
transport http.RoundTripper
110
112
destsCh chan dests
@@ -200,23 +202,22 @@ func (rw *revisionWatcher) probe(ctx context.Context, dest string) (pass bool, n
200
202
return match , notMesh , err
201
203
}
202
204
203
- func (rw * revisionWatcher ) getDest () (string , error ) {
204
- svc , err := rw .serviceLister .Services (rw .rev .Namespace ).Get (names .PrivateService (rw .rev .Name ))
205
+ func (rw * revisionWatcher ) getPrivateServiceDest () (string , error ) {
206
+ svcName := names .PrivateService (rw .rev .Name )
207
+ svc , err := rw .serviceLister .Services (rw .rev .Namespace ).Get (svcName )
205
208
if err != nil {
206
209
return "" , err
207
210
}
208
- if svc .Spec .ClusterIP == "" {
209
- return "" , fmt .Errorf ("private service %s/%s clusterIP is nil, this should never happen" , svc .ObjectMeta .Namespace , svc .ObjectMeta .Name )
210
- }
211
211
212
- svcPort , ok := getServicePort (rw .protocol , svc )
212
+ svcHostname := network .GetServiceHostname (svcName , rw .rev .Namespace )
213
+ svcPort , ok := getTargetPort (rw .protocol , svc )
213
214
if ! ok {
214
215
return "" , fmt .Errorf ("unable to find port in service %s/%s" , svc .Namespace , svc .Name )
215
216
}
216
- return net .JoinHostPort (svc . Spec . ClusterIP , strconv .Itoa (svcPort )), nil
217
+ return net .JoinHostPort (svcHostname , strconv .Itoa (svcPort )), nil
217
218
}
218
219
219
- func (rw * revisionWatcher ) probeClusterIP (dest string ) (bool , error ) {
220
+ func (rw * revisionWatcher ) probePrivateService (dest string ) (bool , error ) {
220
221
ctx , cancel := context .WithTimeout (context .Background (), probeTimeout )
221
222
defer cancel ()
222
223
match , _ , err := rw .probe (ctx , dest )
@@ -296,12 +297,12 @@ func (rw *revisionWatcher) probePodIPs(ready, notReady sets.Set[string]) (succee
296
297
return healthy , unchanged , sawNotMesh .Load (), err
297
298
}
298
299
299
- func (rw * revisionWatcher ) sendUpdate (clusterIP string , dests sets.Set [string ]) {
300
+ func (rw * revisionWatcher ) sendUpdate (privateService string , dests sets.Set [string ]) {
300
301
select {
301
302
case <- rw .stopCh :
302
303
return
303
304
default :
304
- rw .updateCh <- revisionDestsUpdate {Rev : rw .rev , ClusterIPDest : clusterIP , Dests : dests }
305
+ rw .updateCh <- revisionDestsUpdate {Rev : rw .rev , PrivateService : privateService , Dests : dests }
305
306
}
306
307
}
307
308
@@ -310,9 +311,9 @@ func (rw *revisionWatcher) sendUpdate(clusterIP string, dests sets.Set[string])
310
311
func (rw * revisionWatcher ) checkDests (curDests , prevDests dests ) {
311
312
if len (curDests .ready ) == 0 && len (curDests .notReady ) == 0 {
312
313
// We must have scaled down.
313
- rw .clusterIPHealthy = false
314
+ rw .privateServiceHealthy = false
314
315
rw .healthyPods = nil
315
- rw .logger .Debug ("ClusterIP is no longer healthy." )
316
+ rw .logger .Debug ("Private service is no longer healthy." )
316
317
// Send update that we are now inactive (both params invalid).
317
318
rw .sendUpdate ("" , nil )
318
319
return
@@ -351,7 +352,7 @@ func (rw *revisionWatcher) checkDests(curDests, prevDests dests) {
351
352
// Note: it's important that this copies (via hs.Union) the healthy pods
352
353
// set before sending the update to avoid concurrent modifications
353
354
// affecting the throttler, which iterates over the set.
354
- rw .sendUpdate ("" /*clusterIP*/ , hs .Union (nil ))
355
+ rw .sendUpdate ("" , hs .Union (nil ))
355
356
return
356
357
}
357
358
// no-op, and we have successfully probed at least one pod.
@@ -380,28 +381,28 @@ func (rw *revisionWatcher) checkDests(curDests, prevDests dests) {
380
381
// If we failed to probe even a single pod, check the clusterIP.
381
382
// NB: We can't cache the IP address, since user might go rogue
382
383
// and delete the K8s service. We'll fix it, but the cluster IP will be different.
383
- dest , err := rw .getDest ()
384
+ dest , err := rw .getPrivateServiceDest ()
384
385
if err != nil {
385
386
rw .logger .Errorw ("Failed to determine service destination" , zap .Error (err ))
386
387
return
387
388
}
388
389
389
- // If cluster IP is healthy and we haven't scaled down, short circuit.
390
- if rw .clusterIPHealthy {
391
- rw .logger .Debugf ("ClusterIP %s already probed (ready backends: %d)" , dest , len (curDests .ready ))
390
+ // If service hostname is healthy and we haven't scaled down, short circuit.
391
+ if rw .privateServiceHealthy {
392
+ rw .logger .Debugf ("service hostname %s already probed (ready backends: %d)" , dest , len (curDests .ready ))
392
393
rw .sendUpdate (dest , curDests .ready )
393
394
return
394
395
}
395
396
396
- // If clusterIP is healthy send this update and we are done.
397
- if ok , err := rw .probeClusterIP (dest ); err != nil {
398
- rw .logger .Errorw ("Failed to probe clusterIP " + dest , zap .Error (err ))
397
+ // If service via hostname is healthy send this update and we are done.
398
+ if ok , err := rw .probePrivateService (dest ); err != nil {
399
+ rw .logger .Errorw ("Failed to probe private service: " + dest , zap .Error (err ))
399
400
} else if ok {
400
401
// We can reach here only iff pods are not successfully individually probed
401
- // but ClusterIP conversely has been successfully probed.
402
+ // but PrivateService conversely has been successfully probed.
402
403
rw .podsAddressable = false
403
- rw .logger .Debugf ("ClusterIP is successfully probed: %s (ready backends: %d)" , dest , len (curDests .ready ))
404
- rw .clusterIPHealthy = true
404
+ rw .logger .Debugf ("Private service is successfully probed: %s (ready backends: %d)" , dest , len (curDests .ready ))
405
+ rw .privateServiceHealthy = true
405
406
rw .healthyPods = nil
406
407
rw .sendUpdate (dest , curDests .ready )
407
408
}
@@ -421,8 +422,8 @@ func (rw *revisionWatcher) run(probeFrequency time.Duration) {
421
422
// then we want to probe on timer.
422
423
rw .logger .Debugw ("Revision state" , zap .Object ("dests" , curDests ),
423
424
zap .Object ("healthy" , logging .StringSet (rw .healthyPods )),
424
- zap .Bool ("clusterIPHealthy " , rw .clusterIPHealthy ))
425
- if len (curDests .ready )+ len (curDests .notReady ) > 0 && ! (rw .clusterIPHealthy ||
425
+ zap .Bool ("clusterHealthy " , rw .privateServiceHealthy ))
426
+ if len (curDests .ready )+ len (curDests .notReady ) > 0 && ! (rw .privateServiceHealthy ||
426
427
curDests .ready .Union (curDests .notReady ).Equal (rw .healthyPods )) {
427
428
rw .logger .Debug ("Probing on timer" )
428
429
tickCh = timer .C
0 commit comments