Matteo Scandolo | a428586 | 2020-12-01 18:10:10 -0800 | [diff] [blame^] | 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 v1alpha1 |
| 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 | // Standard object's metadata. |
| 33 | // +optional |
| 34 | metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` |
| 35 | // addressType specifies the type of address carried by this EndpointSlice. |
| 36 | // All addresses in this slice must be the same type. This field is |
| 37 | // immutable after creation. The following address types are currently |
| 38 | // supported: |
| 39 | // * IPv4: Represents an IPv4 Address. |
| 40 | // * IPv6: Represents an IPv6 Address. |
| 41 | // * FQDN: Represents a Fully Qualified Domain Name. |
| 42 | AddressType AddressType `json:"addressType" protobuf:"bytes,4,rep,name=addressType"` |
| 43 | // endpoints is a list of unique endpoints in this slice. Each slice may |
| 44 | // include a maximum of 1000 endpoints. |
| 45 | // +listType=atomic |
| 46 | Endpoints []Endpoint `json:"endpoints" protobuf:"bytes,2,rep,name=endpoints"` |
| 47 | // ports specifies the list of network ports exposed by each endpoint in |
| 48 | // this slice. Each port must have a unique name. When ports is empty, it |
| 49 | // indicates that there are no defined ports. When a port is defined with a |
| 50 | // nil port value, it indicates "all ports". Each slice may include a |
| 51 | // maximum of 100 ports. |
| 52 | // +optional |
| 53 | // +listType=atomic |
| 54 | Ports []EndpointPort `json:"ports" protobuf:"bytes,3,rep,name=ports"` |
| 55 | } |
| 56 | |
| 57 | // AddressType represents the type of address referred to by an endpoint. |
| 58 | type AddressType string |
| 59 | |
| 60 | const ( |
| 61 | // AddressTypeIP represents an IP Address. |
| 62 | // This address type has been deprecated and has been replaced by the IPv4 |
| 63 | // and IPv6 adddress types. New resources with this address type will be |
| 64 | // considered invalid. This will be fully removed in 1.18. |
| 65 | // +deprecated |
| 66 | AddressTypeIP = AddressType("IP") |
| 67 | // AddressTypeIPv4 represents an IPv4 Address. |
| 68 | AddressTypeIPv4 = AddressType(v1.IPv4Protocol) |
| 69 | // AddressTypeIPv6 represents an IPv6 Address. |
| 70 | AddressTypeIPv6 = AddressType(v1.IPv6Protocol) |
| 71 | // AddressTypeFQDN represents a FQDN. |
| 72 | AddressTypeFQDN = AddressType("FQDN") |
| 73 | ) |
| 74 | |
| 75 | // Endpoint represents a single logical "backend" implementing a service. |
| 76 | type Endpoint struct { |
| 77 | // addresses of this endpoint. The contents of this field are interpreted |
| 78 | // according to the corresponding EndpointSlice addressType field. Consumers |
| 79 | // must handle different types of addresses in the context of their own |
| 80 | // capabilities. This must contain at least one address but no more than |
| 81 | // 100. |
| 82 | // +listType=set |
| 83 | Addresses []string `json:"addresses" protobuf:"bytes,1,rep,name=addresses"` |
| 84 | // conditions contains information about the current status of the endpoint. |
| 85 | Conditions EndpointConditions `json:"conditions,omitempty" protobuf:"bytes,2,opt,name=conditions"` |
| 86 | // hostname of this endpoint. This field may be used by consumers of |
| 87 | // endpoints to distinguish endpoints from each other (e.g. in DNS names). |
| 88 | // Multiple endpoints which use the same hostname should be considered |
| 89 | // fungible (e.g. multiple A values in DNS). Must pass DNS Label (RFC 1123) |
| 90 | // validation. |
| 91 | // +optional |
| 92 | Hostname *string `json:"hostname,omitempty" protobuf:"bytes,3,opt,name=hostname"` |
| 93 | // targetRef is a reference to a Kubernetes object that represents this |
| 94 | // endpoint. |
| 95 | // +optional |
| 96 | TargetRef *v1.ObjectReference `json:"targetRef,omitempty" protobuf:"bytes,4,opt,name=targetRef"` |
| 97 | // topology contains arbitrary topology information associated with the |
| 98 | // endpoint. These key/value pairs must conform with the label format. |
| 99 | // https://kubernetes.io/docs/concepts/overview/working-with-objects/labels |
| 100 | // Topology may include a maximum of 16 key/value pairs. This includes, but |
| 101 | // is not limited to the following well known keys: |
| 102 | // * kubernetes.io/hostname: the value indicates the hostname of the node |
| 103 | // where the endpoint is located. This should match the corresponding |
| 104 | // node label. |
| 105 | // * topology.kubernetes.io/zone: the value indicates the zone where the |
| 106 | // endpoint is located. This should match the corresponding node label. |
| 107 | // * topology.kubernetes.io/region: the value indicates the region where the |
| 108 | // endpoint is located. This should match the corresponding node label. |
| 109 | // +optional |
| 110 | Topology map[string]string `json:"topology,omitempty" protobuf:"bytes,5,opt,name=topology"` |
| 111 | } |
| 112 | |
| 113 | // EndpointConditions represents the current condition of an endpoint. |
| 114 | type EndpointConditions struct { |
| 115 | // ready indicates that this endpoint is prepared to receive traffic, |
| 116 | // according to whatever system is managing the endpoint. A nil value |
| 117 | // indicates an unknown state. In most cases consumers should interpret this |
| 118 | // unknown state as ready. |
| 119 | // +optional |
| 120 | Ready *bool `json:"ready,omitempty" protobuf:"bytes,1,name=ready"` |
| 121 | } |
| 122 | |
| 123 | // EndpointPort represents a Port used by an EndpointSlice |
| 124 | type EndpointPort struct { |
| 125 | // The name of this port. All ports in an EndpointSlice must have a unique |
| 126 | // name. If the EndpointSlice is dervied from a Kubernetes service, this |
| 127 | // corresponds to the Service.ports[].name. |
| 128 | // Name must either be an empty string or pass DNS_LABEL validation: |
| 129 | // * must be no more than 63 characters long. |
| 130 | // * must consist of lower case alphanumeric characters or '-'. |
| 131 | // * must start and end with an alphanumeric character. |
| 132 | // Default is empty string. |
| 133 | Name *string `json:"name,omitempty" protobuf:"bytes,1,name=name"` |
| 134 | // The IP protocol for this port. |
| 135 | // Must be UDP, TCP, or SCTP. |
| 136 | // Default is TCP. |
| 137 | Protocol *v1.Protocol `json:"protocol,omitempty" protobuf:"bytes,2,name=protocol"` |
| 138 | // The port number of the endpoint. |
| 139 | // If this is not specified, ports are not restricted and must be |
| 140 | // interpreted in the context of the specific consumer. |
| 141 | Port *int32 `json:"port,omitempty" protobuf:"bytes,3,opt,name=port"` |
| 142 | // The application protocol for this port. |
| 143 | // This field follows standard Kubernetes label syntax. |
| 144 | // Un-prefixed names are reserved for IANA standard service names (as per |
| 145 | // RFC-6335 and http://www.iana.org/assignments/service-names). |
| 146 | // Non-standard protocols should use prefixed names. |
| 147 | // Default is empty string. |
| 148 | AppProtocol *string `json:"appProtocol,omitempty" protobuf:"bytes,4,name=appProtocol"` |
| 149 | } |
| 150 | |
| 151 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 152 | |
| 153 | // EndpointSliceList represents a list of endpoint slices |
| 154 | type EndpointSliceList struct { |
| 155 | metav1.TypeMeta `json:",inline"` |
| 156 | // Standard list metadata. |
| 157 | // +optional |
| 158 | metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` |
| 159 | // List of endpoint slices |
| 160 | Items []EndpointSlice `json:"items" protobuf:"bytes,2,rep,name=items"` |
| 161 | } |