Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions apis/config/v1alpha1/backend_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ type BackendSpec struct {
// Redispatch enable or disable session redistribution in case of connection failure
// +optional
Redispatch *bool `json:"redispatch,omitempty"`
// Options contains additional backend options.
// +optional
Options *BackendOptions `json:"options,omitempty"`
// HashType specifies a method to use for mapping hashes to servers
// +optional
HashType *HashType `json:"hashType,omitempty"`
Expand All @@ -52,6 +55,12 @@ type BackendSpec struct {
TCPCheck *bool `json:"tcpCheck,omitempty"`
}

type BackendOptions struct {
// LogHealthChecks enables logging of health checks.
// +optional
LogHealthChecks *bool `json:"logHealthChecks,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name=Mode,type=string,JSONPath=`.spec.mode`
Expand Down Expand Up @@ -126,6 +135,14 @@ func (b *Backend) Model() (models.Backend, error) {
}
}

if b.Spec.Options != nil && b.Spec.Options.LogHealthChecks != nil {
if *b.Spec.Options.LogHealthChecks {
model.LogHealthChecks = models.BackendBaseLogHealthChecksEnabled
} else {
model.LogHealthChecks = models.BackendBaseLogHealthChecksDisabled
}
}

if b.Spec.HashType != nil {
ht, err := b.Spec.HashType.Model()
if err == nil {
Expand Down
12 changes: 12 additions & 0 deletions apis/config/v1alpha1/backend_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ var _ = Describe("Backend", Label("type"), func() {
Ω(backend.AddToParser(p)).ShouldNot(HaveOccurred())
Ω(p.String()).Should(ContainSubstring("server server 10.0.0.4:8080 check port 80"))
})
It("should set option log-health-checks", func() {
backend := &configv1alpha1.Backend{
ObjectMeta: metav1.ObjectMeta{Name: "foo"},
Spec: configv1alpha1.BackendSpec{
Options: &configv1alpha1.BackendOptions{
LogHealthChecks: ptr.To(true),
},
},
}
Ω(backend.AddToParser(p)).ShouldNot(HaveOccurred())
Ω(p.String()).Should(ContainSubstring("option log-health-checks"))
})
It("should set hash-type", func() {
backend := &configv1alpha1.Backend{
ObjectMeta: metav1.ObjectMeta{Name: "foo"},
Expand Down
25 changes: 25 additions & 0 deletions apis/config/v1alpha1/zz_generated.deepcopy.go

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

62 changes: 62 additions & 0 deletions apis/proxy/v1alpha1/instance_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/go-openapi/strfmt"
parser "github.com/haproxytech/client-native/v6/config-parser"
configparseropts "github.com/haproxytech/client-native/v6/config-parser/options"
parsertypes "github.com/haproxytech/client-native/v6/config-parser/types"
"github.com/haproxytech/client-native/v6/configuration"
"github.com/haproxytech/client-native/v6/configuration/options"
"github.com/haproxytech/client-native/v6/models"
Expand Down Expand Up @@ -665,6 +666,7 @@ type DefaultsConfiguration struct {
// Logging is used to configure default logging for all proxies.
// +optional
Logging *DefaultsLoggingConfiguration `json:"logging,omitempty"`
// Options contains additional defaults options.
// Options configures additional HAProxy defaults options.
// +optional
Options *DefaultsOptions `json:"options,omitempty"`
Expand All @@ -677,6 +679,21 @@ type DefaultsConfiguration struct {
}

type DefaultsOptions struct {
// LogSeparateErrors causes error and normal logs to be emitted separately.
// +optional
LogSeparateErrors *bool `json:"logSeparateErrors,omitempty"`
// LogHealthChecks enables logging of health checks.
// +optional
LogHealthChecks *bool `json:"logHealthChecks,omitempty"`
// Dontlognull controls logging of null connections.
// +optional
Dontlognull *bool `json:"dontlognull,omitempty"`
// DontlogNormal controls logging of normal traffic.
// +optional
DontlogNormal *bool `json:"dontlogNormal,omitempty"`
// HTTPLogCLF enables HTTP logging in CLF format.
// +optional
HTTPLogCLF *bool `json:"httpLogClf,omitempty"`
// Redispatch enables or disables redispatching in defaults.
// +optional
Redispatch *bool `json:"redispatch,omitempty"`
Expand Down Expand Up @@ -758,6 +775,45 @@ func (d *DefaultsConfiguration) Model() (models.Defaults, error) {
defaults.H1CaseAdjustBogusServer = models.DefaultsBaseH1CaseAdjustBogusServerEnabled
}

if d.Options != nil {
if d.Options.LogSeparateErrors != nil {
if *d.Options.LogSeparateErrors {
defaults.LogSeparateErrors = models.DefaultsBaseLogSeparateErrorsEnabled
} else {
defaults.LogSeparateErrors = models.DefaultsBaseLogSeparateErrorsDisabled
}
}

if d.Options.LogHealthChecks != nil {
if *d.Options.LogHealthChecks {
defaults.LogHealthChecks = models.DefaultsBaseLogHealthChecksEnabled
} else {
defaults.LogHealthChecks = models.DefaultsBaseLogHealthChecksDisabled
}
}

if d.Options.Dontlognull != nil {
if *d.Options.Dontlognull {
defaults.Dontlognull = models.DefaultsBaseDontlognullEnabled
} else {
defaults.Dontlognull = models.DefaultsBaseDontlognullDisabled
}
}

if d.Options.DontlogNormal != nil {
if *d.Options.DontlogNormal {
defaults.DontlogNormal = models.DefaultsBaseDontlogNormalEnabled
} else {
defaults.DontlogNormal = models.DefaultsBaseDontlogNormalDisabled
}
}

if ptr.Deref(d.Options.HTTPLogCLF, false) {
defaults.Httplog = true
defaults.Clflog = true
}
}

return defaults, defaults.Validate(strfmt.Default)
}

Expand All @@ -776,6 +832,12 @@ func (d *DefaultsConfiguration) AddToParser(p parser.Parser) error {
return err
}

if d.Options != nil && ptr.Deref(d.Options.HTTPLogCLF, false) {
if err := p.Set(parser.Defaults, defaultsSectionName, "option httplog", &parsertypes.OptionHTTPLog{Clf: true}, 0); err != nil {
return err
}
}

if d.Logging != nil && d.Logging.Enabled {
logTarget, err := d.Logging.Model()
if err != nil {
Expand Down
104 changes: 104 additions & 0 deletions apis/proxy/v1alpha1/instance_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

parser "github.com/haproxytech/client-native/v6/config-parser"
"github.com/haproxytech/client-native/v6/models"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
)
Expand Down Expand Up @@ -155,3 +156,106 @@ func TestDefaultsConfiguration_AddToParser_H1CaseAdjustBogusServerDisabledByDefa
t.Fatalf("did not expect h1-case-adjust-bogus-server option in defaults section, got:\n%s", cfg)
}
}

func TestDefaultsConfigurationModelWithOptions(t *testing.T) {
d := &DefaultsConfiguration{
Mode: "http",
Timeouts: map[string]metav1.Duration{},
Options: &DefaultsOptions{
LogSeparateErrors: ptr.To(true),
LogHealthChecks: ptr.To(true),
Dontlognull: ptr.To(false),
DontlogNormal: ptr.To(false),
HTTPLogCLF: ptr.To(true),
Redispatch: ptr.To(true),
},
}

model, err := d.Model()
if err != nil {
t.Fatalf("Model() returned error: %v", err)
}
if model.LogSeparateErrors != models.DefaultsBaseLogSeparateErrorsEnabled {
t.Fatalf("unexpected log-separate-errors value: %s", model.LogSeparateErrors)
}
if model.LogHealthChecks != models.DefaultsBaseLogHealthChecksEnabled {
t.Fatalf("unexpected log-health-checks value: %s", model.LogHealthChecks)
}
if model.Dontlognull != models.DefaultsBaseDontlognullDisabled {
t.Fatalf("unexpected dontlognull value: %s", model.Dontlognull)
}
if model.DontlogNormal != models.DefaultsBaseDontlogNormalDisabled {
t.Fatalf("unexpected dontlog-normal value: %s", model.DontlogNormal)
}
if !model.Httplog {
t.Fatalf("expected httplog to be enabled")
}
if !model.Clflog {
t.Fatalf("expected clflog to be enabled")
}
if model.Redispatch == nil || model.Redispatch.Enabled == nil || *model.Redispatch.Enabled != models.RedispatchEnabledEnabled {
t.Fatalf("expected redispatch to be enabled")
}
}

func TestDefaultsConfigurationAddToParserWithOptions(t *testing.T) {
d := &DefaultsConfiguration{
Mode: "http",
Timeouts: map[string]metav1.Duration{},
Options: &DefaultsOptions{
LogSeparateErrors: ptr.To(true),
LogHealthChecks: ptr.To(true),
Dontlognull: ptr.To(false),
DontlogNormal: ptr.To(false),
HTTPLogCLF: ptr.To(true),
},
}

p, err := parser.New()
if err != nil {
t.Fatalf("parser.New() returned error: %v", err)
}

if err := d.AddToParser(p); err != nil {
t.Fatalf("AddToParser() returned error: %v", err)
}

cfg := p.String()
checks := []string{
"option httplog",
"option log-separate-errors",
"option log-health-checks",
"no option dontlognull",
"no option dontlog-normal",
}

for _, check := range checks {
if !strings.Contains(cfg, check) {
t.Fatalf("expected generated config to contain %q, got:\n%s", check, cfg)
}
}
}

func TestDefaultsConfigurationAddToParserWithHTTPLogCLF(t *testing.T) {
d := &DefaultsConfiguration{
Mode: "http",
Timeouts: map[string]metav1.Duration{},
Options: &DefaultsOptions{
HTTPLogCLF: ptr.To(true),
},
}

p, err := parser.New()
if err != nil {
t.Fatalf("parser.New() returned error: %v", err)
}

if err := d.AddToParser(p); err != nil {
t.Fatalf("AddToParser() returned error: %v", err)
}

cfg := p.String()
if !strings.Contains(cfg, "option httplog clf") {
t.Fatalf("expected generated config to contain %q, got:\n%s", "option httplog clf", cfg)
}
}
25 changes: 25 additions & 0 deletions apis/proxy/v1alpha1/zz_generated.deepcopy.go

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

36 changes: 36 additions & 0 deletions docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,28 @@ _Appears in:_
| `hostRegex` _string_ | HostRegex specifies a regular expression used for backend switching rules. | | Optional: \{\} <br /> |
| `hostCertificate` _[CertificateListElement](#certificatelistelement)_ | HostCertificate specifies a certificate for that host used in the crt-list of a frontend | | Optional: \{\} <br /> |
| `redispatch` _boolean_ | Redispatch enable or disable session redistribution in case of connection failure | | Optional: \{\} <br /> |
| `options` _[BackendOptions](#backendoptions)_ | Options contains additional backend options. | | Optional: \{\} <br /> |
| `hashType` _[HashType](#hashtype)_ | HashType specifies a method to use for mapping hashes to servers | | Optional: \{\} <br /> |
| `cookie` _[Cookie](#cookie)_ | Cookie enables cookie-based persistence in a backend. | | Optional: \{\} <br /> |
| `httpchk` _[HTTPChk](#httpchk)_ | HTTPChk Enables HTTP protocol to check on the servers health | | Optional: \{\} <br /> |
| `tcpCheck` _boolean_ | TCPCheck Perform health checks using tcp-check send/expect sequences | | Optional: \{\} <br /> |


#### BackendOptions






_Appears in:_
- [BackendSpec](#backendspec)

| Field | Description | Default | Validation |
| --- | --- | --- | --- |
| `logHealthChecks` _boolean_ | LogHealthChecks enables logging of health checks. | | Optional: \{\} <br /> |


#### BackendSwitchingRule


Expand Down Expand Up @@ -1303,6 +1319,26 @@ _Appears in:_
| `tcpLog` _boolean_ | TCPLog enables advanced logging of TCP connections with session state and timers. By default, the log output format<br />is very poor, as it only contains the source and destination addresses, and the instance name. | | Optional: \{\} <br /> |


#### DefaultsOptions






_Appears in:_
- [DefaultsConfiguration](#defaultsconfiguration)

| Field | Description | Default | Validation |
| --- | --- | --- | --- |
| `logSeparateErrors` _boolean_ | LogSeparateErrors causes error and normal logs to be emitted separately. | | Optional: \{\} <br /> |
| `logHealthChecks` _boolean_ | LogHealthChecks enables logging of health checks. | | Optional: \{\} <br /> |
| `dontlognull` _boolean_ | Dontlognull controls logging of null connections. | | Optional: \{\} <br /> |
| `dontlogNormal` _boolean_ | DontlogNormal controls logging of normal traffic. | | Optional: \{\} <br /> |
| `httpLogClf` _boolean_ | HTTPLogCLF enables HTTP logging in CLF format (emits `option httplog clf`). | | Optional: \{\} <br /> |
| `redispatch` _boolean_ | Redispatch enables or disables redispatching in defaults. | | Optional: \{\} <br /> |


#### GlobalConfiguration


Expand Down
Loading
Loading