@@ -143,10 +143,11 @@ func ListenAndServeKubeletServer(
143
143
enableCAdvisorJSONEndpoints ,
144
144
enableDebuggingHandlers ,
145
145
enableContentionProfiling ,
146
- redirectContainerStreaming bool ,
146
+ redirectContainerStreaming ,
147
+ enableSystemLogHandler bool ,
147
148
criHandler http.Handler ) {
148
149
klog .Infof ("Starting to listen on %s:%d" , address , port )
149
- handler := NewServer (host , resourceAnalyzer , auth , enableCAdvisorJSONEndpoints , enableDebuggingHandlers , enableContentionProfiling , redirectContainerStreaming , criHandler )
150
+ handler := NewServer (host , resourceAnalyzer , auth , enableCAdvisorJSONEndpoints , enableDebuggingHandlers , enableContentionProfiling , redirectContainerStreaming , enableSystemLogHandler , criHandler )
150
151
s := & http.Server {
151
152
Addr : net .JoinHostPort (address .String (), strconv .FormatUint (uint64 (port ), 10 )),
152
153
Handler : & handler ,
@@ -168,7 +169,7 @@ func ListenAndServeKubeletServer(
168
169
// ListenAndServeKubeletReadOnlyServer initializes a server to respond to HTTP network requests on the Kubelet.
169
170
func ListenAndServeKubeletReadOnlyServer (host HostInterface , resourceAnalyzer stats.ResourceAnalyzer , address net.IP , port uint , enableCAdvisorJSONEndpoints bool ) {
170
171
klog .V (1 ).Infof ("Starting to listen read-only on %s:%d" , address , port )
171
- s := NewServer (host , resourceAnalyzer , nil , enableCAdvisorJSONEndpoints , false , false , false , nil )
172
+ s := NewServer (host , resourceAnalyzer , nil , enableCAdvisorJSONEndpoints , false , false , false , false , nil )
172
173
173
174
server := & http.Server {
174
175
Addr : net .JoinHostPort (address .String (), strconv .FormatUint (uint64 (port ), 10 )),
@@ -222,7 +223,8 @@ func NewServer(
222
223
enableCAdvisorJSONEndpoints ,
223
224
enableDebuggingHandlers ,
224
225
enableContentionProfiling ,
225
- redirectContainerStreaming bool ,
226
+ redirectContainerStreaming ,
227
+ enableSystemLogHandler bool ,
226
228
criHandler http.Handler ) Server {
227
229
server := Server {
228
230
host : host ,
@@ -239,6 +241,9 @@ func NewServer(
239
241
server .InstallDefaultHandlers (enableCAdvisorJSONEndpoints )
240
242
if enableDebuggingHandlers {
241
243
server .InstallDebuggingHandlers (criHandler )
244
+ // To maintain backward compatibility serve logs only when enableDebuggingHandlers is also enabled
245
+ // see https://github.com/kubernetes/kubernetes/pull/87273
246
+ server .InstallSystemLogHandler (enableSystemLogHandler )
242
247
if enableContentionProfiling {
243
248
goruntime .SetBlockProfileRate (1 )
244
249
}
@@ -470,19 +475,6 @@ func (s *Server) InstallDebuggingHandlers(criHandler http.Handler) {
470
475
Operation ("getPortForward" ))
471
476
s .restfulCont .Add (ws )
472
477
473
- s .addMetricsBucketMatcher ("logs" )
474
- ws = new (restful.WebService )
475
- ws .
476
- Path (logsPath )
477
- ws .Route (ws .GET ("" ).
478
- To (s .getLogs ).
479
- Operation ("getLogs" ))
480
- ws .Route (ws .GET ("/{logpath:*}" ).
481
- To (s .getLogs ).
482
- Operation ("getLogs" ).
483
- Param (ws .PathParameter ("logpath" , "path to the log" ).DataType ("string" )))
484
- s .restfulCont .Add (ws )
485
-
486
478
s .addMetricsBucketMatcher ("containerLogs" )
487
479
ws = new (restful.WebService )
488
480
ws .
@@ -561,6 +553,28 @@ func (s *Server) InstallDebuggingDisabledHandlers() {
561
553
}
562
554
}
563
555
556
+ // InstallSystemLogHandler registers the HTTP request patterns for logs endpoint.
557
+ func (s * Server ) InstallSystemLogHandler (enableSystemLogHandler bool ) {
558
+ s .addMetricsBucketMatcher ("logs" )
559
+ if enableSystemLogHandler {
560
+ ws := new (restful.WebService )
561
+ ws .Path (logsPath )
562
+ ws .Route (ws .GET ("" ).
563
+ To (s .getLogs ).
564
+ Operation ("getLogs" ))
565
+ ws .Route (ws .GET ("/{logpath:*}" ).
566
+ To (s .getLogs ).
567
+ Operation ("getLogs" ).
568
+ Param (ws .PathParameter ("logpath" , "path to the log" ).DataType ("string" )))
569
+ s .restfulCont .Add (ws )
570
+ } else {
571
+ h := http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
572
+ http .Error (w , "logs endpoint is disabled." , http .StatusMethodNotAllowed )
573
+ })
574
+ s .restfulCont .Handle (logsPath , h )
575
+ }
576
+ }
577
+
564
578
// Checks if kubelet's sync loop that updates containers is working.
565
579
func (s * Server ) syncLoopHealthCheck (req * http.Request ) error {
566
580
duration := s .host .ResyncInterval () * 2
0 commit comments