Skip to content

Commit

Permalink
feat(*) refactor and simplify parsing of ingress rules to kong config
Browse files Browse the repository at this point in the history
Breaking changes
-  KongIngress overrides for Service and Upstream will now be picked up
  from annotation on the service and not the route.

Changelog:
- Directly translate to Kong configuration objects
  Previously, the Ingress rules were parsed into Nginx Server and
  Location blocks, and then translated to Kong configuration. This was
  more complicated and information was lost during translation.
- Translation is now done to an intermediate Kong state and then further
  translated to the final format. The final format will differ, based on
  if Kong is running in a db or a db-less mode.
- Method based routes are now supported (#202)
- Default backend in Ingress rules is now respected and a default
  fallback route in Kong will be created if a default backend exists in
  one of the Ingress objects. If multiple Ingress objects have a default
  backed, the Ingress created first will be respected.

Fix #202
Fix #241
  • Loading branch information
hbagdi committed Apr 1, 2019
1 parent fd5d29d commit 1c45744
Show file tree
Hide file tree
Showing 18 changed files with 2,147 additions and 2,793 deletions.
312 changes: 132 additions & 180 deletions Gopkg.lock

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ required = [
name = "github.com/golang/glog"
branch = "master"

[[constraint]]
name = "github.com/imdario/mergo"
version = "0.2.4"

[[constraint]]
name = "github.com/pkg/errors"
version = "0.8.0"
Expand Down Expand Up @@ -83,3 +79,11 @@ source = "https://github.com/fsnotify/fsnotify.git"
[[constraint]]
name = "github.com/hbagdi/go-kong"
version = "0.3.0"

[[constraint]]
name = "github.com/hbagdi/deck"
version = "0.1.0"

[[constraint]]
name = "github.com/imdario/mergo"
version = "0.3.7"
68 changes: 4 additions & 64 deletions internal/apis/configuration/v1/types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1

import (
"github.com/hbagdi/go-kong/kong"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -15,9 +16,9 @@ type KongIngress struct {
// +optional
metav1.ObjectMeta `json:"metadata,omitempty"`

Upstream *Upstream `json:"upstream,omitempty"`
Proxy *Proxy `json:"proxy,omitempty"`
Route *Route `json:"route,omitempty"`
Upstream *kong.Upstream `json:"upstream,omitempty"`
Proxy *kong.Service `json:"proxy,omitempty"`
Route *kong.Route `json:"route,omitempty"`
}

// KongIngressList is a top-level list type. The client methods for
Expand All @@ -30,64 +31,3 @@ type KongIngressList struct {
// +optional
Items []KongIngress `json:"items"`
}

// Route defines optional settings defined in Kong Routes
type Route struct {
Methods []string `json:"methods"`
RegexPriority int `json:"regex_priority"`
StripPath bool `json:"strip_path"`
PreserveHost bool `json:"preserve_host"`
Protocols []string `json:"protocols"`
}

type Upstream struct {
HashOn string `json:"hash_on"`
HashOnCookie string `json:"hash_on_cookie"`
HashOnCookiePath string `json:"hash_on_cookie_path"`
HashOnHeader string `json:"hash_on_header"`
HashFallback string `json:"hash_fallback"`
HashFallbackHeader string `json:"hash_fallback_header"`
Healthchecks *Healthchecks `json:"healthchecks,omitempty"`
Slots int `json:"slots"`
}

type Proxy struct {
Protocol string `json:"protocol"`
Path string `json:"path"`
ConnectTimeout int `json:"connect_timeout"`
Retries *int `json:"retries"`
ReadTimeout int `json:"read_timeout"`
WriteTimeout int `json:"write_timeout"`
}

type Healthchecks struct {
Active *ActiveHealthCheck `json:"active,omitempty"`
Passive *Passive `json:"passive,omitempty"`
}

type ActiveHealthCheck struct {
Concurrency int `json:"concurrency"`
Healthy *Healthy `json:"healthy"`
HTTPPath string `json:"http_path"`
Timeout int `json:"timeout"`
Unhealthy *Unhealthy `json:"unhealthy"`
}

type Passive struct {
Healthy *Healthy `json:"healthy,omitempty"`
Unhealthy *Unhealthy `json:"unhealthy,omitempty"`
}

type Healthy struct {
HTTPStatuses []int `json:"http_statuses"`
Interval int `json:"interval"`
Successes int `json:"successes"`
}

type Unhealthy struct {
HTTPFailures int `json:"http_failures"`
HTTPStatuses []int `json:"http_statuses"`
Interval int `json:"interval"`
TCPFailures int `json:"tcp_failures"`
Timeouts int `json:"timeouts"`
}
227 changes: 4 additions & 223 deletions internal/apis/configuration/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1c45744

Please sign in to comment.