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 v1beta1 |
| 18 | |
| 19 | import ( |
| 20 | v1 "k8s.io/api/core/v1" |
| 21 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 22 | "k8s.io/apimachinery/pkg/util/intstr" |
| 23 | ) |
| 24 | |
| 25 | // +genclient |
| 26 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 27 | // +k8s:prerelease-lifecycle-gen:introduced=1.14 |
| 28 | // +k8s:prerelease-lifecycle-gen:deprecated=1.19 |
| 29 | // +k8s:prerelease-lifecycle-gen:replacement=networking.k8s.io,v1,Ingress |
| 30 | |
| 31 | // Ingress is a collection of rules that allow inbound connections to reach the |
| 32 | // endpoints defined by a backend. An Ingress can be configured to give services |
| 33 | // externally-reachable urls, load balance traffic, terminate SSL, offer name |
| 34 | // based virtual hosting etc. |
| 35 | type Ingress struct { |
| 36 | metav1.TypeMeta `json:",inline"` |
| 37 | // Standard object's metadata. |
| 38 | // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata |
| 39 | // +optional |
| 40 | metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` |
| 41 | |
| 42 | // Spec is the desired state of the Ingress. |
| 43 | // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status |
| 44 | // +optional |
| 45 | Spec IngressSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"` |
| 46 | |
| 47 | // Status is the current state of the Ingress. |
| 48 | // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status |
| 49 | // +optional |
| 50 | Status IngressStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"` |
| 51 | } |
| 52 | |
| 53 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 54 | // +k8s:prerelease-lifecycle-gen:introduced=1.14 |
| 55 | // +k8s:prerelease-lifecycle-gen:deprecated=1.19 |
| 56 | // +k8s:prerelease-lifecycle-gen:replacement=networking.k8s.io,v1,IngressList |
| 57 | |
| 58 | // IngressList is a collection of Ingress. |
| 59 | type IngressList struct { |
| 60 | metav1.TypeMeta `json:",inline"` |
| 61 | // Standard object's metadata. |
| 62 | // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata |
| 63 | // +optional |
| 64 | metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` |
| 65 | |
| 66 | // Items is the list of Ingress. |
| 67 | Items []Ingress `json:"items" protobuf:"bytes,2,rep,name=items"` |
| 68 | } |
| 69 | |
| 70 | // IngressSpec describes the Ingress the user wishes to exist. |
| 71 | type IngressSpec struct { |
| 72 | // IngressClassName is the name of the IngressClass cluster resource. The |
| 73 | // associated IngressClass defines which controller will implement the |
| 74 | // resource. This replaces the deprecated `kubernetes.io/ingress.class` |
| 75 | // annotation. For backwards compatibility, when that annotation is set, it |
| 76 | // must be given precedence over this field. The controller may emit a |
| 77 | // warning if the field and annotation have different values. |
| 78 | // Implementations of this API should ignore Ingresses without a class |
| 79 | // specified. An IngressClass resource may be marked as default, which can |
| 80 | // be used to set a default value for this field. For more information, |
| 81 | // refer to the IngressClass documentation. |
| 82 | // +optional |
| 83 | IngressClassName *string `json:"ingressClassName,omitempty" protobuf:"bytes,4,opt,name=ingressClassName"` |
| 84 | |
| 85 | // A default backend capable of servicing requests that don't match any |
| 86 | // rule. At least one of 'backend' or 'rules' must be specified. This field |
| 87 | // is optional to allow the loadbalancer controller or defaulting logic to |
| 88 | // specify a global default. |
| 89 | // +optional |
| 90 | Backend *IngressBackend `json:"backend,omitempty" protobuf:"bytes,1,opt,name=backend"` |
| 91 | |
| 92 | // TLS configuration. Currently the Ingress only supports a single TLS |
| 93 | // port, 443. If multiple members of this list specify different hosts, they |
| 94 | // will be multiplexed on the same port according to the hostname specified |
| 95 | // through the SNI TLS extension, if the ingress controller fulfilling the |
| 96 | // ingress supports SNI. |
| 97 | // +optional |
| 98 | TLS []IngressTLS `json:"tls,omitempty" protobuf:"bytes,2,rep,name=tls"` |
| 99 | |
| 100 | // A list of host rules used to configure the Ingress. If unspecified, or |
| 101 | // no rule matches, all traffic is sent to the default backend. |
| 102 | // +optional |
| 103 | Rules []IngressRule `json:"rules,omitempty" protobuf:"bytes,3,rep,name=rules"` |
| 104 | // TODO: Add the ability to specify load-balancer IP through claims |
| 105 | } |
| 106 | |
| 107 | // IngressTLS describes the transport layer security associated with an Ingress. |
| 108 | type IngressTLS struct { |
| 109 | // Hosts are a list of hosts included in the TLS certificate. The values in |
| 110 | // this list must match the name/s used in the tlsSecret. Defaults to the |
| 111 | // wildcard host setting for the loadbalancer controller fulfilling this |
| 112 | // Ingress, if left unspecified. |
| 113 | // +optional |
| 114 | Hosts []string `json:"hosts,omitempty" protobuf:"bytes,1,rep,name=hosts"` |
| 115 | // SecretName is the name of the secret used to terminate TLS traffic on |
| 116 | // port 443. Field is left optional to allow TLS routing based on SNI |
| 117 | // hostname alone. If the SNI host in a listener conflicts with the "Host" |
| 118 | // header field used by an IngressRule, the SNI host is used for termination |
| 119 | // and value of the Host header is used for routing. |
| 120 | // +optional |
| 121 | SecretName string `json:"secretName,omitempty" protobuf:"bytes,2,opt,name=secretName"` |
| 122 | // TODO: Consider specifying different modes of termination, protocols etc. |
| 123 | } |
| 124 | |
| 125 | // IngressStatus describe the current state of the Ingress. |
| 126 | type IngressStatus struct { |
| 127 | // LoadBalancer contains the current status of the load-balancer. |
| 128 | // +optional |
| 129 | LoadBalancer v1.LoadBalancerStatus `json:"loadBalancer,omitempty" protobuf:"bytes,1,opt,name=loadBalancer"` |
| 130 | } |
| 131 | |
| 132 | // IngressRule represents the rules mapping the paths under a specified host to |
| 133 | // the related backend services. Incoming requests are first evaluated for a host |
| 134 | // match, then routed to the backend associated with the matching IngressRuleValue. |
| 135 | type IngressRule struct { |
| 136 | // Host is the fully qualified domain name of a network host, as defined by RFC 3986. |
| 137 | // Note the following deviations from the "host" part of the |
| 138 | // URI as defined in RFC 3986: |
| 139 | // 1. IPs are not allowed. Currently an IngressRuleValue can only apply to |
| 140 | // the IP in the Spec of the parent Ingress. |
| 141 | // 2. The `:` delimiter is not respected because ports are not allowed. |
| 142 | // Currently the port of an Ingress is implicitly :80 for http and |
| 143 | // :443 for https. |
| 144 | // Both these may change in the future. |
| 145 | // Incoming requests are matched against the host before the |
| 146 | // IngressRuleValue. If the host is unspecified, the Ingress routes all |
| 147 | // traffic based on the specified IngressRuleValue. |
| 148 | // |
| 149 | // Host can be "precise" which is a domain name without the terminating dot of |
| 150 | // a network host (e.g. "foo.bar.com") or "wildcard", which is a domain name |
| 151 | // prefixed with a single wildcard label (e.g. "*.foo.com"). |
| 152 | // The wildcard character '*' must appear by itself as the first DNS label and |
| 153 | // matches only a single label. You cannot have a wildcard label by itself (e.g. Host == "*"). |
| 154 | // Requests will be matched against the Host field in the following way: |
| 155 | // 1. If Host is precise, the request matches this rule if the http host header is equal to Host. |
| 156 | // 2. If Host is a wildcard, then the request matches this rule if the http host header |
| 157 | // is to equal to the suffix (removing the first label) of the wildcard rule. |
| 158 | // +optional |
| 159 | Host string `json:"host,omitempty" protobuf:"bytes,1,opt,name=host"` |
| 160 | // IngressRuleValue represents a rule to route requests for this IngressRule. |
| 161 | // If unspecified, the rule defaults to a http catch-all. Whether that sends |
| 162 | // just traffic matching the host to the default backend or all traffic to the |
| 163 | // default backend, is left to the controller fulfilling the Ingress. Http is |
| 164 | // currently the only supported IngressRuleValue. |
| 165 | // +optional |
| 166 | IngressRuleValue `json:",inline,omitempty" protobuf:"bytes,2,opt,name=ingressRuleValue"` |
| 167 | } |
| 168 | |
| 169 | // IngressRuleValue represents a rule to apply against incoming requests. If the |
| 170 | // rule is satisfied, the request is routed to the specified backend. Currently |
| 171 | // mixing different types of rules in a single Ingress is disallowed, so exactly |
| 172 | // one of the following must be set. |
| 173 | type IngressRuleValue struct { |
| 174 | //TODO: |
| 175 | // 1. Consider renaming this resource and the associated rules so they |
| 176 | // aren't tied to Ingress. They can be used to route intra-cluster traffic. |
| 177 | // 2. Consider adding fields for ingress-type specific global options |
| 178 | // usable by a loadbalancer, like http keep-alive. |
| 179 | |
| 180 | // +optional |
| 181 | HTTP *HTTPIngressRuleValue `json:"http,omitempty" protobuf:"bytes,1,opt,name=http"` |
| 182 | } |
| 183 | |
| 184 | // HTTPIngressRuleValue is a list of http selectors pointing to backends. |
| 185 | // In the example: http://<host>/<path>?<searchpart> -> backend where |
| 186 | // where parts of the url correspond to RFC 3986, this resource will be used |
| 187 | // to match against everything after the last '/' and before the first '?' |
| 188 | // or '#'. |
| 189 | type HTTPIngressRuleValue struct { |
| 190 | // A collection of paths that map requests to backends. |
| 191 | Paths []HTTPIngressPath `json:"paths" protobuf:"bytes,1,rep,name=paths"` |
| 192 | // TODO: Consider adding fields for ingress-type specific global |
| 193 | // options usable by a loadbalancer, like http keep-alive. |
| 194 | } |
| 195 | |
| 196 | // PathType represents the type of path referred to by a HTTPIngressPath. |
| 197 | type PathType string |
| 198 | |
| 199 | const ( |
| 200 | // PathTypeExact matches the URL path exactly and with case sensitivity. |
| 201 | PathTypeExact = PathType("Exact") |
| 202 | |
| 203 | // PathTypePrefix matches based on a URL path prefix split by '/'. Matching |
| 204 | // is case sensitive and done on a path element by element basis. A path |
| 205 | // element refers to the list of labels in the path split by the '/' |
| 206 | // separator. A request is a match for path p if every p is an element-wise |
| 207 | // prefix of p of the request path. Note that if the last element of the |
| 208 | // path is a substring of the last element in request path, it is not a |
| 209 | // match (e.g. /foo/bar matches /foo/bar/baz, but does not match |
| 210 | // /foo/barbaz). If multiple matching paths exist in an Ingress spec, the |
| 211 | // longest matching path is given priority. |
| 212 | // Examples: |
| 213 | // - /foo/bar does not match requests to /foo/barbaz |
| 214 | // - /foo/bar matches request to /foo/bar and /foo/bar/baz |
| 215 | // - /foo and /foo/ both match requests to /foo and /foo/. If both paths are |
| 216 | // present in an Ingress spec, the longest matching path (/foo/) is given |
| 217 | // priority. |
| 218 | PathTypePrefix = PathType("Prefix") |
| 219 | |
| 220 | // PathTypeImplementationSpecific matching is up to the IngressClass. |
| 221 | // Implementations can treat this as a separate PathType or treat it |
| 222 | // identically to Prefix or Exact path types. |
| 223 | PathTypeImplementationSpecific = PathType("ImplementationSpecific") |
| 224 | ) |
| 225 | |
| 226 | // HTTPIngressPath associates a path with a backend. Incoming urls matching the |
| 227 | // path are forwarded to the backend. |
| 228 | type HTTPIngressPath struct { |
| 229 | // Path is matched against the path of an incoming request. Currently it can |
| 230 | // contain characters disallowed from the conventional "path" part of a URL |
| 231 | // as defined by RFC 3986. Paths must begin with a '/'. When unspecified, |
| 232 | // all paths from incoming requests are matched. |
| 233 | // +optional |
| 234 | Path string `json:"path,omitempty" protobuf:"bytes,1,opt,name=path"` |
| 235 | |
| 236 | // PathType determines the interpretation of the Path matching. PathType can |
| 237 | // be one of the following values: |
| 238 | // * Exact: Matches the URL path exactly. |
| 239 | // * Prefix: Matches based on a URL path prefix split by '/'. Matching is |
| 240 | // done on a path element by element basis. A path element refers is the |
| 241 | // list of labels in the path split by the '/' separator. A request is a |
| 242 | // match for path p if every p is an element-wise prefix of p of the |
| 243 | // request path. Note that if the last element of the path is a substring |
| 244 | // of the last element in request path, it is not a match (e.g. /foo/bar |
| 245 | // matches /foo/bar/baz, but does not match /foo/barbaz). |
| 246 | // * ImplementationSpecific: Interpretation of the Path matching is up to |
| 247 | // the IngressClass. Implementations can treat this as a separate PathType |
| 248 | // or treat it identically to Prefix or Exact path types. |
| 249 | // Implementations are required to support all path types. |
| 250 | // Defaults to ImplementationSpecific. |
| 251 | PathType *PathType `json:"pathType,omitempty" protobuf:"bytes,3,opt,name=pathType"` |
| 252 | |
| 253 | // Backend defines the referenced service endpoint to which the traffic |
| 254 | // will be forwarded to. |
| 255 | Backend IngressBackend `json:"backend" protobuf:"bytes,2,opt,name=backend"` |
| 256 | } |
| 257 | |
| 258 | // IngressBackend describes all endpoints for a given service and port. |
| 259 | type IngressBackend struct { |
| 260 | // Specifies the name of the referenced service. |
| 261 | // +optional |
| 262 | ServiceName string `json:"serviceName,omitempty" protobuf:"bytes,1,opt,name=serviceName"` |
| 263 | |
| 264 | // Specifies the port of the referenced service. |
| 265 | // +optional |
| 266 | ServicePort intstr.IntOrString `json:"servicePort,omitempty" protobuf:"bytes,2,opt,name=servicePort"` |
| 267 | |
| 268 | // Resource is an ObjectRef to another Kubernetes resource in the namespace |
| 269 | // of the Ingress object. If resource is specified, serviceName and servicePort |
| 270 | // must not be specified. |
| 271 | // +optional |
| 272 | Resource *v1.TypedLocalObjectReference `json:"resource,omitempty" protobuf:"bytes,3,opt,name=resource"` |
| 273 | } |
| 274 | |
| 275 | // +genclient |
| 276 | // +genclient:nonNamespaced |
| 277 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 278 | // +k8s:prerelease-lifecycle-gen:introduced=1.18 |
| 279 | // +k8s:prerelease-lifecycle-gen:deprecated=1.19 |
| 280 | // +k8s:prerelease-lifecycle-gen:replacement=networking.k8s.io,v1,IngressClassList |
| 281 | |
| 282 | // IngressClass represents the class of the Ingress, referenced by the Ingress |
| 283 | // Spec. The `ingressclass.kubernetes.io/is-default-class` annotation can be |
| 284 | // used to indicate that an IngressClass should be considered default. When a |
| 285 | // single IngressClass resource has this annotation set to true, new Ingress |
| 286 | // resources without a class specified will be assigned this default class. |
| 287 | type IngressClass struct { |
| 288 | metav1.TypeMeta `json:",inline"` |
| 289 | // Standard object's metadata. |
| 290 | // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata |
| 291 | // +optional |
| 292 | metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` |
| 293 | |
| 294 | // Spec is the desired state of the IngressClass. |
| 295 | // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status |
| 296 | // +optional |
| 297 | Spec IngressClassSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"` |
| 298 | } |
| 299 | |
| 300 | // IngressClassSpec provides information about the class of an Ingress. |
| 301 | type IngressClassSpec struct { |
| 302 | // Controller refers to the name of the controller that should handle this |
| 303 | // class. This allows for different "flavors" that are controlled by the |
| 304 | // same controller. For example, you may have different Parameters for the |
| 305 | // same implementing controller. This should be specified as a |
| 306 | // domain-prefixed path no more than 250 characters in length, e.g. |
| 307 | // "acme.io/ingress-controller". This field is immutable. |
| 308 | Controller string `json:"controller,omitempty" protobuf:"bytes,1,opt,name=controller"` |
| 309 | |
| 310 | // Parameters is a link to a custom resource containing additional |
| 311 | // configuration for the controller. This is optional if the controller does |
| 312 | // not require extra parameters. |
| 313 | // +optional |
| 314 | Parameters *v1.TypedLocalObjectReference `json:"parameters,omitempty" protobuf:"bytes,2,opt,name=parameters"` |
| 315 | } |
| 316 | |
| 317 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 318 | // +k8s:prerelease-lifecycle-gen:introduced=1.18 |
| 319 | // +k8s:prerelease-lifecycle-gen:deprecated=1.19 |
| 320 | // +k8s:prerelease-lifecycle-gen:replacement=networking.k8s.io,v1,IngressClassList |
| 321 | |
| 322 | // IngressClassList is a collection of IngressClasses. |
| 323 | type IngressClassList struct { |
| 324 | metav1.TypeMeta `json:",inline"` |
| 325 | // Standard list metadata. |
| 326 | // +optional |
| 327 | metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` |
| 328 | |
| 329 | // Items is the list of IngressClasses. |
| 330 | Items []IngressClass `json:"items" protobuf:"bytes,2,rep,name=items"` |
| 331 | } |