1 /* 2 Copyright 2019 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 v1 18 19 import ( 20 v1 "k8s.io/api/core/v1" 21 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 22 ) 23 24 // +genclient 25 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 26 27 // EndpointSlice represents a subset of the endpoints that implement a service. 28 // For a given service there may be multiple EndpointSlice objects, selected by 29 // labels, which must be joined to produce the full set of endpoints. 30 type EndpointSlice struct { 31 metav1.TypeMeta `json:",inline"` 32 33 // Standard object's metadata. 34 // +optional 35 metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 36 37 // addressType specifies the type of address carried by this EndpointSlice. 38 // All addresses in this slice must be the same type. This field is 39 // immutable after creation. The following address types are currently 40 // supported: 41 // * IPv4: Represents an IPv4 Address. 42 // * IPv6: Represents an IPv6 Address. 43 // * FQDN: Represents a Fully Qualified Domain Name. 44 AddressType AddressType `json:"addressType" protobuf:"bytes,4,rep,name=addressType"` 45 46 // endpoints is a list of unique endpoints in this slice. Each slice may 47 // include a maximum of 1000 endpoints. 48 // +listType=atomic 49 Endpoints []Endpoint `json:"endpoints" protobuf:"bytes,2,rep,name=endpoints"` 50 51 // ports specifies the list of network ports exposed by each endpoint in 52 // this slice. Each port must have a unique name. When ports is empty, it 53 // indicates that there are no defined ports. When a port is defined with a 54 // nil port value, it indicates "all ports". Each slice may include a 55 // maximum of 100 ports. 56 // +optional 57 // +listType=atomic 58 Ports []EndpointPort `json:"ports" protobuf:"bytes,3,rep,name=ports"` 59 } 60 61 // AddressType represents the type of address referred to by an endpoint. 62 // +enum 63 type AddressType string 64 65 const ( 66 // AddressTypeIPv4 represents an IPv4 Address. 67 AddressTypeIPv4 = AddressType(v1.IPv4Protocol) 68 69 // AddressTypeIPv6 represents an IPv6 Address. 70 AddressTypeIPv6 = AddressType(v1.IPv6Protocol) 71 72 // AddressTypeFQDN represents a FQDN. 73 AddressTypeFQDN = AddressType("FQDN") 74 ) 75 76 // Endpoint represents a single logical "backend" implementing a service. 77 type Endpoint struct { 78 // addresses of this endpoint. The contents of this field are interpreted 79 // according to the corresponding EndpointSlice addressType field. Consumers 80 // must handle different types of addresses in the context of their own 81 // capabilities. This must contain at least one address but no more than 82 // 100. These are all assumed to be fungible and clients may choose to only 83 // use the first element. Refer to: https://issue.k8s.io/106267 84 // +listType=set 85 Addresses []string `json:"addresses" protobuf:"bytes,1,rep,name=addresses"` 86 87 // conditions contains information about the current status of the endpoint. 88 Conditions EndpointConditions `json:"conditions,omitempty" protobuf:"bytes,2,opt,name=conditions"` 89 90 // hostname of this endpoint. This field may be used by consumers of 91 // endpoints to distinguish endpoints from each other (e.g. in DNS names). 92 // Multiple endpoints which use the same hostname should be considered 93 // fungible (e.g. multiple A values in DNS). Must be lowercase and pass DNS 94 // Label (RFC 1123) validation. 95 // +optional 96 Hostname *string `json:"hostname,omitempty" protobuf:"bytes,3,opt,name=hostname"` 97 98 // targetRef is a reference to a Kubernetes object that represents this 99 // endpoint. 100 // +optional 101 TargetRef *v1.ObjectReference `json:"targetRef,omitempty" protobuf:"bytes,4,opt,name=targetRef"` 102 103 // deprecatedTopology contains topology information part of the v1beta1 104 // API. This field is deprecated, and will be removed when the v1beta1 105 // API is removed (no sooner than kubernetes v1.24). While this field can 106 // hold values, it is not writable through the v1 API, and any attempts to 107 // write to it will be silently ignored. Topology information can be found 108 // in the zone and nodeName fields instead. 109 // +optional 110 DeprecatedTopology map[string]string `json:"deprecatedTopology,omitempty" protobuf:"bytes,5,opt,name=deprecatedTopology"` 111 112 // nodeName represents the name of the Node hosting this endpoint. This can 113 // be used to determine endpoints local to a Node. 114 // +optional 115 NodeName *string `json:"nodeName,omitempty" protobuf:"bytes,6,opt,name=nodeName"` 116 117 // zone is the name of the Zone this endpoint exists in. 118 // +optional 119 Zone *string `json:"zone,omitempty" protobuf:"bytes,7,opt,name=zone"` 120 121 // hints contains information associated with how an endpoint should be 122 // consumed. 123 // +optional 124 Hints *EndpointHints `json:"hints,omitempty" protobuf:"bytes,8,opt,name=hints"` 125 } 126 127 // EndpointConditions represents the current condition of an endpoint. 128 type EndpointConditions struct { 129 // ready indicates that this endpoint is prepared to receive traffic, 130 // according to whatever system is managing the endpoint. A nil value 131 // indicates an unknown state. In most cases consumers should interpret this 132 // unknown state as ready. For compatibility reasons, ready should never be 133 // "true" for terminating endpoints, except when the normal readiness 134 // behavior is being explicitly overridden, for example when the associated 135 // Service has set the publishNotReadyAddresses flag. 136 // +optional 137 Ready *bool `json:"ready,omitempty" protobuf:"bytes,1,name=ready"` 138 139 // serving is identical to ready except that it is set regardless of the 140 // terminating state of endpoints. This condition should be set to true for 141 // a ready endpoint that is terminating. If nil, consumers should defer to 142 // the ready condition. 143 // +optional 144 Serving *bool `json:"serving,omitempty" protobuf:"bytes,2,name=serving"` 145 146 // terminating indicates that this endpoint is terminating. A nil value 147 // indicates an unknown state. Consumers should interpret this unknown state 148 // to mean that the endpoint is not terminating. 149 // +optional 150 Terminating *bool `json:"terminating,omitempty" protobuf:"bytes,3,name=terminating"` 151 } 152 153 // EndpointHints provides hints describing how an endpoint should be consumed. 154 type EndpointHints struct { 155 // forZones indicates the zone(s) this endpoint should be consumed by to 156 // enable topology aware routing. 157 // +listType=atomic 158 ForZones []ForZone `json:"forZones,omitempty" protobuf:"bytes,1,name=forZones"` 159 } 160 161 // ForZone provides information about which zones should consume this endpoint. 162 type ForZone struct { 163 // name represents the name of the zone. 164 Name string `json:"name" protobuf:"bytes,1,name=name"` 165 } 166 167 // EndpointPort represents a Port used by an EndpointSlice 168 // +structType=atomic 169 type EndpointPort struct { 170 // name represents the name of this port. All ports in an EndpointSlice must have a unique name. 171 // If the EndpointSlice is derived from a Kubernetes service, this corresponds to the Service.ports[].name. 172 // Name must either be an empty string or pass DNS_LABEL validation: 173 // * must be no more than 63 characters long. 174 // * must consist of lower case alphanumeric characters or '-'. 175 // * must start and end with an alphanumeric character. 176 // Default is empty string. 177 Name *string `json:"name,omitempty" protobuf:"bytes,1,name=name"` 178 179 // protocol represents the IP protocol for this port. 180 // Must be UDP, TCP, or SCTP. 181 // Default is TCP. 182 Protocol *v1.Protocol `json:"protocol,omitempty" protobuf:"bytes,2,name=protocol"` 183 184 // port represents the port number of the endpoint. 185 // If this is not specified, ports are not restricted and must be 186 // interpreted in the context of the specific consumer. 187 Port *int32 `json:"port,omitempty" protobuf:"bytes,3,opt,name=port"` 188 189 // The application protocol for this port. 190 // This is used as a hint for implementations to offer richer behavior for protocols that they understand. 191 // This field follows standard Kubernetes label syntax. 192 // Valid values are either: 193 // 194 // * Un-prefixed protocol names - reserved for IANA standard service names (as per 195 // RFC-6335 and https://www.iana.org/assignments/service-names). 196 // 197 // * Kubernetes-defined prefixed names: 198 // * 'kubernetes.io/h2c' - HTTP/2 prior knowledge over cleartext as described in https://www.rfc-editor.org/rfc/rfc9113.html#name-starting-http-2-with-prior- 199 // * 'kubernetes.io/ws' - WebSocket over cleartext as described in https://www.rfc-editor.org/rfc/rfc6455 200 // * 'kubernetes.io/wss' - WebSocket over TLS as described in https://www.rfc-editor.org/rfc/rfc6455 201 // 202 // * Other protocols should use implementation-defined prefixed names such as 203 // mycompany.com/my-custom-protocol. 204 // +optional 205 AppProtocol *string `json:"appProtocol,omitempty" protobuf:"bytes,4,name=appProtocol"` 206 } 207 208 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 209 210 // EndpointSliceList represents a list of endpoint slices 211 type EndpointSliceList struct { 212 metav1.TypeMeta `json:",inline"` 213 214 // Standard list metadata. 215 // +optional 216 metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 217 218 // items is the list of endpoint slices 219 Items []EndpointSlice `json:"items" protobuf:"bytes,2,rep,name=items"` 220 } 221