k8s.io/kubernetes@v1.29.3/pkg/proxy/types.go (about) 1 /* 2 Copyright 2015 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 proxy 18 19 import ( 20 "fmt" 21 "net" 22 23 v1 "k8s.io/api/core/v1" 24 "k8s.io/apimachinery/pkg/types" 25 "k8s.io/apimachinery/pkg/util/sets" 26 "k8s.io/kubernetes/pkg/proxy/config" 27 ) 28 29 // Provider is the interface provided by proxier implementations. 30 type Provider interface { 31 config.EndpointSliceHandler 32 config.ServiceHandler 33 config.NodeHandler 34 35 // Sync immediately synchronizes the Provider's current state to proxy rules. 36 Sync() 37 // SyncLoop runs periodic work. 38 // This is expected to run as a goroutine or as the main loop of the app. 39 // It does not return. 40 SyncLoop() 41 } 42 43 // ServicePortName carries a namespace + name + portname. This is the unique 44 // identifier for a load-balanced service. 45 type ServicePortName struct { 46 types.NamespacedName 47 Port string 48 Protocol v1.Protocol 49 } 50 51 func (spn ServicePortName) String() string { 52 return fmt.Sprintf("%s%s", spn.NamespacedName.String(), fmtPortName(spn.Port)) 53 } 54 55 func fmtPortName(in string) string { 56 if in == "" { 57 return "" 58 } 59 return fmt.Sprintf(":%s", in) 60 } 61 62 // ServicePort is an interface which abstracts information about a service. 63 type ServicePort interface { 64 // String returns service string. An example format can be: `IP:Port/Protocol`. 65 String() string 66 // ClusterIP returns service cluster IP in net.IP format. 67 ClusterIP() net.IP 68 // Port returns service port if present. If return 0 means not present. 69 Port() int 70 // SessionAffinityType returns service session affinity type 71 SessionAffinityType() v1.ServiceAffinity 72 // StickyMaxAgeSeconds returns service max connection age 73 StickyMaxAgeSeconds() int 74 // ExternalIPStrings returns service ExternalIPs as a string array. 75 ExternalIPStrings() []string 76 // LoadBalancerVIPStrings returns service LoadBalancerIPs which are VIP mode as a string array. 77 LoadBalancerVIPStrings() []string 78 // Protocol returns service protocol. 79 Protocol() v1.Protocol 80 // LoadBalancerSourceRanges returns service LoadBalancerSourceRanges if present empty array if not 81 LoadBalancerSourceRanges() []string 82 // HealthCheckNodePort returns service health check node port if present. If return 0, it means not present. 83 HealthCheckNodePort() int 84 // NodePort returns a service Node port if present. If return 0, it means not present. 85 NodePort() int 86 // ExternalPolicyLocal returns if a service has only node local endpoints for external traffic. 87 ExternalPolicyLocal() bool 88 // InternalPolicyLocal returns if a service has only node local endpoints for internal traffic. 89 InternalPolicyLocal() bool 90 // InternalTrafficPolicy returns service InternalTrafficPolicy 91 InternalTrafficPolicy() *v1.ServiceInternalTrafficPolicy 92 // HintsAnnotation returns the value of the v1.DeprecatedAnnotationTopologyAwareHints annotation. 93 HintsAnnotation() string 94 // ExternallyAccessible returns true if the service port is reachable via something 95 // other than ClusterIP (NodePort/ExternalIP/LoadBalancer) 96 ExternallyAccessible() bool 97 // UsesClusterEndpoints returns true if the service port ever sends traffic to 98 // endpoints based on "Cluster" traffic policy 99 UsesClusterEndpoints() bool 100 // UsesLocalEndpoints returns true if the service port ever sends traffic to 101 // endpoints based on "Local" traffic policy 102 UsesLocalEndpoints() bool 103 } 104 105 // Endpoint in an interface which abstracts information about an endpoint. 106 // TODO: Rename functions to be consistent with ServicePort. 107 type Endpoint interface { 108 // String returns endpoint string. An example format can be: `IP:Port`. 109 // We take the returned value as ServiceEndpoint.Endpoint. 110 String() string 111 // IP returns IP part of the endpoint. 112 IP() string 113 // Port returns the Port part of the endpoint. 114 Port() int 115 116 // IsLocal returns true if the endpoint is running on the same host as kube-proxy. 117 IsLocal() bool 118 // IsReady returns true if an endpoint is ready and not terminating, or 119 // if PublishNotReadyAddresses is set on the service. 120 IsReady() bool 121 // IsServing returns true if an endpoint is ready. It does not account 122 // for terminating state. 123 IsServing() bool 124 // IsTerminating returns true if an endpoint is terminating. For pods, 125 // that is any pod with a deletion timestamp. 126 IsTerminating() bool 127 128 // ZoneHints returns the zone hint for the endpoint. This is based on 129 // endpoint.hints.forZones[0].name in the EndpointSlice API. 130 ZoneHints() sets.Set[string] 131 } 132 133 // ServiceEndpoint is used to identify a service and one of its endpoint pair. 134 type ServiceEndpoint struct { 135 Endpoint string 136 ServicePortName ServicePortName 137 }