...

Source file src/k8s.io/kubernetes/pkg/proxy/healthcheck/common.go

Documentation: k8s.io/kubernetes/pkg/proxy/healthcheck

     1  /*
     2  Copyright 2016 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package healthcheck
    18  
    19  import (
    20  	"net"
    21  	"net/http"
    22  )
    23  
    24  // listener allows for testing of ServiceHealthServer and ProxierHealthServer.
    25  type listener interface {
    26  	// Listen is very much like net.Listen, except the first arg (network) is
    27  	// fixed to be "tcp".
    28  	Listen(addr string) (net.Listener, error)
    29  }
    30  
    31  // httpServerFactory allows for testing of ServiceHealthServer and ProxierHealthServer.
    32  type httpServerFactory interface {
    33  	// New creates an instance of a type satisfying HTTPServer.  This is
    34  	// designed to include http.Server.
    35  	New(addr string, handler http.Handler) httpServer
    36  }
    37  
    38  // httpServer allows for testing of ServiceHealthServer and ProxierHealthServer.
    39  // It is designed so that http.Server satisfies this interface,
    40  type httpServer interface {
    41  	Serve(listener net.Listener) error
    42  	Close() error
    43  }
    44  
    45  // Implement listener in terms of net.Listen.
    46  type stdNetListener struct{}
    47  
    48  func (stdNetListener) Listen(addr string) (net.Listener, error) {
    49  	return net.Listen("tcp", addr)
    50  }
    51  
    52  var _ listener = stdNetListener{}
    53  
    54  // Implement httpServerFactory in terms of http.Server.
    55  type stdHTTPServerFactory struct{}
    56  
    57  func (stdHTTPServerFactory) New(addr string, handler http.Handler) httpServer {
    58  	return &http.Server{
    59  		Addr:    addr,
    60  		Handler: handler,
    61  	}
    62  }
    63  
    64  var _ httpServerFactory = stdHTTPServerFactory{}
    65  

View as plain text