-
Notifications
You must be signed in to change notification settings - Fork 24
/
config.go
49 lines (40 loc) · 1.25 KB
/
config.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
package haproxy
import (
"github.com/flosch/pongo2"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
apiv1alpha1 "github.com/percona/percona-server-mysql-operator/api/v1alpha1"
)
const (
CustomConfigKey = "haproxy.cfg"
configVolumeName = "config"
configMountPath = "/etc/haproxy-custom/"
)
type Configurable apiv1alpha1.PerconaServerMySQL
func (c *Configurable) GetConfigMapName() string {
cr := apiv1alpha1.PerconaServerMySQL(*c)
return Name(&cr)
}
func (c *Configurable) GetConfigMapKey() string {
return CustomConfigKey
}
func (c *Configurable) GetConfiguration() string {
cr := apiv1alpha1.PerconaServerMySQL(*c)
return cr.Spec.Proxy.HAProxy.Configuration
}
func (c *Configurable) GetResources() corev1.ResourceRequirements {
cr := apiv1alpha1.PerconaServerMySQL(*c)
return cr.Spec.Proxy.HAProxy.Resources
}
func (c *Configurable) ExecuteConfigurationTemplate(input string, memory *resource.Quantity) (string, error) {
tmpl, err := pongo2.FromString(input)
if err != nil {
return "", errors.Wrap(err, "parse template")
}
result, err := tmpl.Execute(pongo2.Context{"containerMemoryLimit": memory.Value()})
if err != nil {
return "", errors.Wrap(err, "execute template")
}
return result, nil
}