types.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. Copyright 2015 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 proxy
  14. import (
  15. "fmt"
  16. "k8s.io/api/core/v1"
  17. "k8s.io/apimachinery/pkg/types"
  18. "k8s.io/kubernetes/pkg/proxy/config"
  19. )
  20. // ProxyProvider is the interface provided by proxier implementations.
  21. type ProxyProvider interface {
  22. config.EndpointsHandler
  23. config.ServiceHandler
  24. // Sync immediately synchronizes the ProxyProvider's current state to proxy rules.
  25. Sync()
  26. // SyncLoop runs periodic work.
  27. // This is expected to run as a goroutine or as the main loop of the app.
  28. // It does not return.
  29. SyncLoop()
  30. }
  31. // ServicePortName carries a namespace + name + portname. This is the unique
  32. // identifier for a load-balanced service.
  33. type ServicePortName struct {
  34. types.NamespacedName
  35. Port string
  36. }
  37. func (spn ServicePortName) String() string {
  38. return fmt.Sprintf("%s:%s", spn.NamespacedName.String(), spn.Port)
  39. }
  40. // ServicePort is an interface which abstracts information about a service.
  41. type ServicePort interface {
  42. // String returns service string. An example format can be: `IP:Port/Protocol`.
  43. String() string
  44. // ClusterIPString returns service cluster IP in string format.
  45. ClusterIPString() string
  46. // ExternalIPStrings returns service ExternalIPs as a string array.
  47. ExternalIPStrings() []string
  48. // LoadBalancerIPStrings returns service LoadBalancerIPs as a string array.
  49. LoadBalancerIPStrings() []string
  50. // GetProtocol returns service protocol.
  51. GetProtocol() v1.Protocol
  52. // GetHealthCheckNodePort returns service health check node port if present. If return 0, it means not present.
  53. GetHealthCheckNodePort() int
  54. // GetNodePort returns a service Node port if present. If return 0, it means not present.
  55. GetNodePort() int
  56. }
  57. // Endpoint in an interface which abstracts information about an endpoint.
  58. // TODO: Rename functions to be consistent with ServicePort.
  59. type Endpoint interface {
  60. // String returns endpoint string. An example format can be: `IP:Port`.
  61. // We take the returned value as ServiceEndpoint.Endpoint.
  62. String() string
  63. // GetIsLocal returns true if the endpoint is running in same host as kube-proxy, otherwise returns false.
  64. GetIsLocal() bool
  65. // IP returns IP part of the endpoint.
  66. IP() string
  67. // Port returns the Port part of the endpoint.
  68. Port() (int, error)
  69. // Equal checks if two endpoints are equal.
  70. Equal(Endpoint) bool
  71. }
  72. // ServiceEndpoint is used to identify a service and one of its endpoint pair.
  73. type ServiceEndpoint struct {
  74. Endpoint string
  75. ServicePortName ServicePortName
  76. }