Skip to content

Commit

Permalink
Merge pull request #194 from jcmoraisjr/jm-config-frontend
Browse files Browse the repository at this point in the history
Add config-frontend configmap option
  • Loading branch information
jcmoraisjr authored Jul 26, 2018
2 parents 9078ab4 + ccabe4b commit 33ea4bc
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 16 deletions.
46 changes: 30 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,22 +155,6 @@ See also the [example](/examples/blue-green) page.

http://cbonte.github.io/haproxy-dconv/1.8/configuration.html#5.2-weight

### Configuration snippet

Add HAProxy configuration snippet to the configuration file. Use multiline content to add more than one
line of configuration.

Example:

```yaml
annotations:
ingress.kubernetes.io/config-backend: |
acl bar-url path /bar
http-request deny if bar-url
```
* `ingress.kubernetes.io/config-backend`: Add configuration snippet to the HAProxy backend section.

### CORS

Add CORS headers on OPTIONS http command (preflight) and reponses.
Expand Down Expand Up @@ -265,6 +249,7 @@ The following parameters are supported:
|`[0]`|[`bind-ip-addr-http`](#bind-ip-addr)|IP address|`*`|
|`[0]`|[`bind-ip-addr-stats`](#bind-ip-addr)|IP address|`*`|
|`[0]`|[`bind-ip-addr-tcp`](#bind-ip-addr)|IP address|`*`|
|`[1]`|[`config-frontend`](#configuration-snippet)|multiline HAProxy frontend config||
|`[0]`|[`cookie-key`](#cookie-key)|secret key|`Ingress`|
|`[1]`|[`dns-accepted-payload-size`](#dns-resolvers)|number|`8192`|
|`[1]`|[`dns-cluster-domain`](#dns-resolvers)|cluster name|`cluster.local`|
Expand Down Expand Up @@ -349,6 +334,35 @@ Define listening IPv4/IPv6 address on several HAProxy frontends. All IP addresse

http://cbonte.github.io/haproxy-dconv/1.8/configuration.html#4-bind

### Configuration snippet

Add HAProxy configuration snippet to the configuration file. Use multiline content to add more than one
line of configuration.

Examples - configmap:

```yaml
config-frontend: |
capture request header X-User-Id len 32
```
Ingress annotation:
```yaml
annotations:
ingress.kubernetes.io/config-backend: |
acl bar-url path /bar
http-request deny if bar-url
```
Global configmap option:
* `config-frontend`: Add configuration snippet to all frontend sections.

Annotation option:

* `ingress.kubernetes.io/config-backend`: Add configuration snippet to the HAProxy backend section.

### cookie-key

Define a secret key used with the IP address and port number of a backend server
Expand Down
10 changes: 10 additions & 0 deletions pkg/controller/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func newControllerConfig(ingressConfig *ingress.Configuration, haproxyController
}
cfg.createDNSResolvers()
return &types.ControllerConfig{
ConfigFrontend: cfg.configFrontend(),
Userlists: cfg.userlists,
Servers: cfg.ingress.Servers,
Backends: cfg.ingress.Backends,
Expand Down Expand Up @@ -117,6 +118,7 @@ func newHAProxyConfig(haproxyController *HAProxyController) *types.HAProxyConfig
BindIPAddrHealthz: "*",
Syslog: "",
BackendCheckInterval: "2s",
ConfigFrontend: "",
Forwardfor: "add",
MaxConn: 2000,
NoTLSRedirect: "/.well-known/acme-challenge",
Expand Down Expand Up @@ -240,6 +242,14 @@ func (cfg *haConfig) statsSSLCert() *ingress.SSLCert {
return sslCert
}

func (cfg *haConfig) configFrontend() []string {
config := cfg.haproxyConfig.ConfigFrontend
if config == "" {
return []string{}
}
return strings.Split(strings.TrimRight(config, "\n"), "\n")
}

func (cfg *haConfig) createHAProxyServers() {
haServers := make([]*types.HAProxyServer, 0, len(cfg.ingress.Servers))
haPassthrough := make([]*types.HAProxyPassthrough, 0, len(cfg.ingress.PassthroughBackends))
Expand Down
2 changes: 2 additions & 0 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type (
// ControllerConfig has ingress generated and some transformations
// compatible with HAProxy
ControllerConfig struct {
ConfigFrontend []string
Userlists map[string]Userlist
Servers []*ingress.Server
Backends []*ingress.Backend
Expand Down Expand Up @@ -70,6 +71,7 @@ type (
BindIPAddrHealthz string `json:"bind-ip-addr-healthz"`
Syslog string `json:"syslog-endpoint"`
BackendCheckInterval string `json:"backend-check-interval"`
ConfigFrontend string `json:"config-frontend"`
Forwardfor string `json:"forwardfor"`
MaxConn int `json:"max-connections"`
NoTLSRedirect string `json:"no-tls-redirect-locations"`
Expand Down
5 changes: 5 additions & 0 deletions rootfs/etc/haproxy/template/haproxy.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ frontend httpfront-{{ if $isShared }}shared-frontend{{ else if $isDefault }}defa
{{- end }}
{{- end }}

{{- /*------------------------------------*/}}
{{- range $snippet := $ing.ConfigFrontend }}
{{ $snippet }}
{{- end }}

{{- /*------------------------------------*/}}
http-request set-var(txn.hdr_host) req.hdr(host)
{{- if $hasHTTPStoHTTP }}
Expand Down

0 comments on commit 33ea4bc

Please sign in to comment.