Class: Kube::Cluster::Standard::GatewayApi::HTTPRoute

Inherits:
Object
  • Object
show all
Defined in:
lib/kube/cluster/standard/gateway_api/http_route.rb

Overview

A single-rule HTTPRoute attached to the cluster's one traefik-gateway.

Every route in ns/ shares the same parentRefs (the traefik-gateway in kube-system) and differs only by listener section, host(s), the backing Service, the path matches, and an optional chain of traefik middlewares. This collapses that boilerplate to a keyword call.

Deliberately models exactly ONE rule: one set of matches -> one backend (or a terminal redirect), with one filter chain. Routes that need distinct backends or filters per path (fanout) are expressed as several instances on the same host -- the gateway merges them and the more-specific match wins.

Standard::GatewayApi::HTTPRoute.new(
name:    "sourcebot",
gateway: "kremlin-email-https",
domains: ["sg.kremlin.email"],
service: { namespace: "sourcebot", name: "sourcebot", port: 3000 },
middleware: "forwardauth-oauth2-proxy-kremlin",
)

Many matches -> one backend (forgejo git smart-HTTP):

Standard::GatewayApi::HTTPRoute.new(
name: "forgejo-git", gateway: "cia-net-https", domains: ["git.cia.net"],
regex:  ["/.+/info/refs", "/.+/git-upload-pack", "/.+/git-receive-pack"],
prefix: ["/api", "/v2"],
service: { namespace: "default", name: "forgejo-http", port: 3000 },
timeouts: { request: "600s", backendRequest: "600s" },
)

Terminal http->https redirect (the -http sibling):

Standard::GatewayApi::HTTPRoute.new(
name: "sourcebot-http", gateway: "kremlin-email-http",
domains: ["sg.kremlin.email"], prefix: ["/"], redirect: true,
)

Constant Summary collapse

GATEWAY_GROUP =
"gateway.networking.k8s.io"
GATEWAY_NAME =
"traefik-gateway"
GATEWAY_NS =
"kube-system"
MIDDLEWARE_GROUP =

traefik middlewares are attached to a rule via an ExtensionRef filter.

"traefik.io"
MIDDLEWARE_KIND =
"Middleware"
PATH_TYPES =
{
  prefix: "PathPrefix",
  exact:  "Exact",
  regex:  "RegularExpression",
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(name:, gateway:, domains:, service: nil, prefix: nil, exact: nil, regex: nil, headers: nil, middleware: nil, redirect: nil, header_modifier: nil, timeouts: nil, namespace: "kube-system", &block) ⇒ HTTPRoute

Returns a new instance of HTTPRoute.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/kube/cluster/standard/gateway_api/http_route.rb', line 62

def initialize(
  name:,
  gateway:,
  domains:,
  service:         nil,
  prefix:          nil,
  exact:           nil,
  regex:           nil,
  headers:         nil,
  middleware:      nil,
  redirect:        nil,
  header_modifier: nil,
  timeouts:        nil,
  namespace:       "kube-system",
  &block
)
  hostnames = Array(domains)
  matches   = _matches(prefix: prefix, exact: exact, regex: regex, headers: headers)
  filters   = _filters(middleware: middleware, redirect: redirect, header_modifier: header_modifier)

  rule = { matches: matches }
  rule[:filters]     = filters                unless filters.empty?
  rule[:backendRefs] = [_backend(service)]    if service
  rule[:timeouts]    = timeouts               if timeouts

  super() {
    .name      = name
    .namespace = namespace

    spec.hostnames  = hostnames
    spec.parentRefs = [{
      group:       GATEWAY_GROUP,
      kind:        "Gateway",
      name:        GATEWAY_NAME,
      namespace:   GATEWAY_NS,
      sectionName: gateway,
    }]
    spec.rules = [rule]

    instance_exec(&block) if block_given?
  }
end