/
twemproxy_types.go
106 lines (97 loc) · 3.9 KB
/
twemproxy_types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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
104
105
106
package v1alpha1
import (
"time"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"
)
var (
// Twemproxy defaults
defaultTwemproxyLivenessProbe defaultProbeSpec = defaultProbeSpec{
InitialDelaySeconds: pointer.Int32Ptr(0),
TimeoutSeconds: pointer.Int32Ptr(1),
PeriodSeconds: pointer.Int32Ptr(5),
SuccessThreshold: pointer.Int32Ptr(1),
FailureThreshold: pointer.Int32Ptr(3),
}
defaultTwemproxyReadinessProbe defaultProbeSpec = defaultProbeSpec{
InitialDelaySeconds: pointer.Int32Ptr(0),
TimeoutSeconds: pointer.Int32Ptr(1),
PeriodSeconds: pointer.Int32Ptr(5),
SuccessThreshold: pointer.Int32Ptr(1),
FailureThreshold: pointer.Int32Ptr(3),
}
// TODO: add requirements
defaultTwemproxyResources defaultResourceRequirementsSpec = defaultResourceRequirementsSpec{}
defaultTwemproxyImage defaultImageSpec = defaultImageSpec{
Name: pointer.StringPtr("quay.io/3scale/twemproxy"),
Tag: pointer.StringPtr("v0.5.0"),
PullPolicy: (*corev1.PullPolicy)(pointer.StringPtr(string(corev1.PullIfNotPresent))),
}
twemproxyDefaultLogLevel int32 = 6
twemproxyDefaultMetricsPort int32 = 9151
twemproxyDefaultStatsInterval metav1.Duration = metav1.Duration{Duration: 10 * time.Second}
)
// TwemproxySpec configures twemproxy sidecars
// to access a sharded redis
type TwemproxySpec struct {
// Image specification for the component
// +operator-sdk:csv:customresourcedefinitions:type=spec
// +optional
Image *ImageSpec `json:"image,omitempty"`
// Resource requirements for the component
// +operator-sdk:csv:customresourcedefinitions:type=spec
// +optional
Resources *ResourceRequirementsSpec `json:"resources,omitempty"`
// Liveness probe for the component
// +operator-sdk:csv:customresourcedefinitions:type=spec
// +optional
LivenessProbe *ProbeSpec `json:"livenessProbe,omitempty"`
// Readiness probe for the component
// +operator-sdk:csv:customresourcedefinitions:type=spec
// +optional
ReadinessProbe *ProbeSpec `json:"readinessProbe,omitempty"`
// TwemproxyConfigRef is a reference to a TwemproxyConfig
// resource in the same Namespace
// +operator-sdk:csv:customresourcedefinitions:type=spec
TwemproxyConfigRef string `json:"twemproxyConfigRef"`
// Options
// +operator-sdk:csv:customresourcedefinitions:type=spec
// +optional
Options *TwemproxyOptions `json:"options,omitempty"`
}
func (spec *TwemproxySpec) ConfigMapName() string {
return spec.TwemproxyConfigRef
}
// Default implements defaulting for the each backend cron
func (spec *TwemproxySpec) Default() {
spec.Image = InitializeImageSpec(spec.Image, defaultTwemproxyImage)
spec.Resources = InitializeResourceRequirementsSpec(spec.Resources, defaultTwemproxyResources)
spec.LivenessProbe = InitializeProbeSpec(spec.LivenessProbe, defaultTwemproxyLivenessProbe)
spec.ReadinessProbe = InitializeProbeSpec(spec.ReadinessProbe, defaultTwemproxyReadinessProbe)
if spec.Options == nil {
spec.Options = &TwemproxyOptions{}
}
spec.Options.Default()
}
type TwemproxyOptions struct {
// Set logging level to N. (default: 5, min: 0, max: 11)
// +operator-sdk:csv:customresourcedefinitions:type=spec
// +optional
LogLevel *int32 `json:"logLevel,omitempty"`
// Set stats monitoring port to port. (default: 22222)
// +operator-sdk:csv:customresourcedefinitions:type=spec
// +optional
MetricsPort *int32 `json:"metricsAddress,omitempty"`
// Set stats aggregation interval in msec to interval. (default: 30s)
// +operator-sdk:csv:customresourcedefinitions:type=spec
// +optional
StatsInterval *metav1.Duration `json:"statsInterval,omitempty"`
}
func (opts *TwemproxyOptions) Default() {
opts.LogLevel = intOrDefault(opts.LogLevel, &twemproxyDefaultLogLevel)
opts.MetricsPort = intOrDefault(opts.MetricsPort, &twemproxyDefaultMetricsPort)
if opts.StatsInterval == nil {
opts.StatsInterval = &twemproxyDefaultStatsInterval
}
}