api.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. Copyright 2016 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package healthcheck
  14. import (
  15. "k8s.io/kubernetes/pkg/types"
  16. "k8s.io/kubernetes/pkg/util/sets"
  17. "k8s.io/kubernetes/pkg/util/wait"
  18. )
  19. // All public API Methods for this package
  20. // UpdateEndpoints Update the set of local endpoints for a service
  21. func UpdateEndpoints(serviceName types.NamespacedName, endpointUids sets.String) {
  22. req := &proxyMutationRequest{
  23. serviceName: serviceName,
  24. endpointUids: &endpointUids,
  25. }
  26. healthchecker.mutationRequestChannel <- req
  27. }
  28. func updateServiceListener(serviceName types.NamespacedName, listenPort int, add bool) bool {
  29. responseChannel := make(chan bool)
  30. req := &proxyListenerRequest{
  31. serviceName: serviceName,
  32. listenPort: uint16(listenPort),
  33. add: add,
  34. responseChannel: responseChannel,
  35. }
  36. healthchecker.listenerRequestChannel <- req
  37. return <-responseChannel
  38. }
  39. // AddServiceListener Request addition of a listener for a service's health check
  40. func AddServiceListener(serviceName types.NamespacedName, listenPort int) bool {
  41. return updateServiceListener(serviceName, listenPort, true)
  42. }
  43. // DeleteServiceListener Request deletion of a listener for a service's health check
  44. func DeleteServiceListener(serviceName types.NamespacedName, listenPort int) bool {
  45. return updateServiceListener(serviceName, listenPort, false)
  46. }
  47. // Run Start the healthchecker main loop
  48. func Run() {
  49. healthchecker = proxyHealthCheckFactory()
  50. // Wrap with a wait.Forever to handle panics.
  51. go wait.Forever(func() {
  52. healthchecker.handlerLoop()
  53. }, 0)
  54. }