/provider/k8s/ingress.go

https://gitlab.com/wilane/traefik · Go · 151 lines · 42 code · 18 blank · 91 comment · 0 complexity · 34b03021f4f4dccc5d973577e5ecf9c9 MD5 · raw file

  1. package k8s
  2. // Ingress is a collection of rules that allow inbound connections to reach the
  3. // endpoints defined by a backend. An Ingress can be configured to give services
  4. // externally-reachable urls, load balance traffic, terminate SSL, offer name
  5. // based virtual hosting etc.
  6. type Ingress struct {
  7. TypeMeta `json:",inline"`
  8. // Standard object's metadata.
  9. // More info: http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#metadata
  10. ObjectMeta `json:"metadata,omitempty"`
  11. // Spec is the desired state of the Ingress.
  12. // More info: http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#spec-and-status
  13. Spec IngressSpec `json:"spec,omitempty"`
  14. // Status is the current state of the Ingress.
  15. // More info: http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#spec-and-status
  16. Status IngressStatus `json:"status,omitempty"`
  17. }
  18. // IngressList is a collection of Ingress.
  19. type IngressList struct {
  20. TypeMeta `json:",inline"`
  21. // Standard object's metadata.
  22. // More info: http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#metadata
  23. ListMeta `json:"metadata,omitempty"`
  24. // Items is the list of Ingress.
  25. Items []Ingress `json:"items"`
  26. }
  27. // IngressSpec describes the Ingress the user wishes to exist.
  28. type IngressSpec struct {
  29. // A default backend capable of servicing requests that don't match any
  30. // rule. At least one of 'backend' or 'rules' must be specified. This field
  31. // is optional to allow the loadbalancer controller or defaulting logic to
  32. // specify a global default.
  33. Backend *IngressBackend `json:"backend,omitempty"`
  34. // TLS configuration. Currently the Ingress only supports a single TLS
  35. // port, 443. If multiple members of this list specify different hosts, they
  36. // will be multiplexed on the same port according to the hostname specified
  37. // through the SNI TLS extension, if the ingress controller fulfilling the
  38. // ingress supports SNI.
  39. TLS []IngressTLS `json:"tls,omitempty"`
  40. // A list of host rules used to configure the Ingress. If unspecified, or
  41. // no rule matches, all traffic is sent to the default backend.
  42. Rules []IngressRule `json:"rules,omitempty"`
  43. // TODO: Add the ability to specify load-balancer IP through claims
  44. }
  45. // IngressTLS describes the transport layer security associated with an Ingress.
  46. type IngressTLS struct {
  47. // Hosts are a list of hosts included in the TLS certificate. The values in
  48. // this list must match the name/s used in the tlsSecret. Defaults to the
  49. // wildcard host setting for the loadbalancer controller fulfilling this
  50. // Ingress, if left unspecified.
  51. Hosts []string `json:"hosts,omitempty"`
  52. // SecretName is the name of the secret used to terminate SSL traffic on 443.
  53. // Field is left optional to allow SSL routing based on SNI hostname alone.
  54. // If the SNI host in a listener conflicts with the "Host" header field used
  55. // by an IngressRule, the SNI host is used for termination and value of the
  56. // Host header is used for routing.
  57. SecretName string `json:"secretName,omitempty"`
  58. // TODO: Consider specifying different modes of termination, protocols etc.
  59. }
  60. // IngressStatus describe the current state of the Ingress.
  61. type IngressStatus struct {
  62. // LoadBalancer contains the current status of the load-balancer.
  63. LoadBalancer LoadBalancerStatus `json:"loadBalancer,omitempty"`
  64. }
  65. // IngressRule represents the rules mapping the paths under a specified host to
  66. // the related backend services. Incoming requests are first evaluated for a host
  67. // match, then routed to the backend associated with the matching IngressRuleValue.
  68. type IngressRule struct {
  69. // Host is the fully qualified domain name of a network host, as defined
  70. // by RFC 3986. Note the following deviations from the "host" part of the
  71. // URI as defined in the RFC:
  72. // 1. IPs are not allowed. Currently an IngressRuleValue can only apply to the
  73. // IP in the Spec of the parent Ingress.
  74. // 2. The `:` delimiter is not respected because ports are not allowed.
  75. // Currently the port of an Ingress is implicitly :80 for http and
  76. // :443 for https.
  77. // Both these may change in the future.
  78. // Incoming requests are matched against the host before the IngressRuleValue.
  79. // If the host is unspecified, the Ingress routes all traffic based on the
  80. // specified IngressRuleValue.
  81. Host string `json:"host,omitempty"`
  82. // IngressRuleValue represents a rule to route requests for this IngressRule.
  83. // If unspecified, the rule defaults to a http catch-all. Whether that sends
  84. // just traffic matching the host to the default backend or all traffic to the
  85. // default backend, is left to the controller fulfilling the Ingress. Http is
  86. // currently the only supported IngressRuleValue.
  87. IngressRuleValue `json:",inline,omitempty"`
  88. }
  89. // IngressRuleValue represents a rule to apply against incoming requests. If the
  90. // rule is satisfied, the request is routed to the specified backend. Currently
  91. // mixing different types of rules in a single Ingress is disallowed, so exactly
  92. // one of the following must be set.
  93. type IngressRuleValue struct {
  94. //TODO:
  95. // 1. Consider renaming this resource and the associated rules so they
  96. // aren't tied to Ingress. They can be used to route intra-cluster traffic.
  97. // 2. Consider adding fields for ingress-type specific global options
  98. // usable by a loadbalancer, like http keep-alive.
  99. HTTP *HTTPIngressRuleValue `json:"http,omitempty"`
  100. }
  101. // HTTPIngressRuleValue is a list of http selectors pointing to backends.
  102. // In the example: http://<host>/<path>?<searchpart> -> backend where
  103. // where parts of the url correspond to RFC 3986, this resource will be used
  104. // to match against everything after the last '/' and before the first '?'
  105. // or '#'.
  106. type HTTPIngressRuleValue struct {
  107. // A collection of paths that map requests to backends.
  108. Paths []HTTPIngressPath `json:"paths"`
  109. // TODO: Consider adding fields for ingress-type specific global
  110. // options usable by a loadbalancer, like http keep-alive.
  111. }
  112. // HTTPIngressPath associates a path regex with a backend. Incoming urls matching
  113. // the path are forwarded to the backend.
  114. type HTTPIngressPath struct {
  115. // Path is a extended POSIX regex as defined by IEEE Std 1003.1,
  116. // (i.e this follows the egrep/unix syntax, not the perl syntax)
  117. // matched against the path of an incoming request. Currently it can
  118. // contain characters disallowed from the conventional "path"
  119. // part of a URL as defined by RFC 3986. Paths must begin with
  120. // a '/'. If unspecified, the path defaults to a catch all sending
  121. // traffic to the backend.
  122. Path string `json:"path,omitempty"`
  123. // Backend defines the referenced service endpoint to which the traffic
  124. // will be forwarded to.
  125. Backend IngressBackend `json:"backend"`
  126. }
  127. // IngressBackend describes all endpoints for a given service and port.
  128. type IngressBackend struct {
  129. // Specifies the name of the referenced service.
  130. ServiceName string `json:"serviceName"`
  131. // Specifies the port of the referenced service.
  132. ServicePort IntOrString `json:"servicePort"`
  133. }