types.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. "net"
  17. v1 "k8s.io/api/core/v1"
  18. "k8s.io/apimachinery/pkg/types"
  19. "k8s.io/kubernetes/pkg/proxy/config"
  20. )
  21. // Provider is the interface provided by proxier implementations.
  22. type Provider interface {
  23. config.EndpointsHandler
  24. config.EndpointSliceHandler
  25. config.ServiceHandler
  26. config.NodeHandler
  27. // Sync immediately synchronizes the Provider's current state to proxy rules.
  28. Sync()
  29. // SyncLoop runs periodic work.
  30. // This is expected to run as a goroutine or as the main loop of the app.
  31. // It does not return.
  32. SyncLoop()
  33. }
  34. // ServicePortName carries a namespace + name + portname. This is the unique
  35. // identifier for a load-balanced service.
  36. type ServicePortName struct {
  37. types.NamespacedName
  38. Port string
  39. Protocol v1.Protocol
  40. }
  41. func (spn ServicePortName) String() string {
  42. return fmt.Sprintf("%s:%s", spn.NamespacedName.String(), spn.Port)
  43. }
  44. // ServicePort is an interface which abstracts information about a service.
  45. type ServicePort interface {
  46. // String returns service string. An example format can be: `IP:Port/Protocol`.
  47. String() string
  48. // GetClusterIP returns service cluster IP in net.IP format.
  49. ClusterIP() net.IP
  50. // GetPort returns service port if present. If return 0 means not present.
  51. Port() int
  52. // GetSessionAffinityType returns service session affinity type
  53. SessionAffinityType() v1.ServiceAffinity
  54. // GetStickyMaxAgeSeconds returns service max connection age
  55. StickyMaxAgeSeconds() int
  56. // ExternalIPStrings returns service ExternalIPs as a string array.
  57. ExternalIPStrings() []string
  58. // LoadBalancerIPStrings returns service LoadBalancerIPs as a string array.
  59. LoadBalancerIPStrings() []string
  60. // GetProtocol returns service protocol.
  61. Protocol() v1.Protocol
  62. // LoadBalancerSourceRanges returns service LoadBalancerSourceRanges if present empty array if not
  63. LoadBalancerSourceRanges() []string
  64. // GetHealthCheckNodePort returns service health check node port if present. If return 0, it means not present.
  65. HealthCheckNodePort() int
  66. // GetNodePort returns a service Node port if present. If return 0, it means not present.
  67. NodePort() int
  68. // GetOnlyNodeLocalEndpoints returns if a service has only node local endpoints
  69. OnlyNodeLocalEndpoints() bool
  70. // TopologyKeys returns service TopologyKeys as a string array.
  71. TopologyKeys() []string
  72. }
  73. // Endpoint in an interface which abstracts information about an endpoint.
  74. // TODO: Rename functions to be consistent with ServicePort.
  75. type Endpoint interface {
  76. // String returns endpoint string. An example format can be: `IP:Port`.
  77. // We take the returned value as ServiceEndpoint.Endpoint.
  78. String() string
  79. // GetIsLocal returns true if the endpoint is running in same host as kube-proxy, otherwise returns false.
  80. GetIsLocal() bool
  81. // GetTopology returns the topology information of the endpoint.
  82. GetTopology() map[string]string
  83. // IP returns IP part of the endpoint.
  84. IP() string
  85. // Port returns the Port part of the endpoint.
  86. Port() (int, error)
  87. // Equal checks if two endpoints are equal.
  88. Equal(Endpoint) bool
  89. }
  90. // ServiceEndpoint is used to identify a service and one of its endpoint pair.
  91. type ServiceEndpoint struct {
  92. Endpoint string
  93. ServicePortName ServicePortName
  94. }