Skip to content

Commit 64f8782

Browse files
authored
redis template for stage cache (#783)
1 parent 4f7cfa5 commit 64f8782

File tree

2 files changed

+145
-3
lines changed

2 files changed

+145
-3
lines changed

magefiles/secrets.go

+90-3
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,42 @@ import (
1111
)
1212

1313
const (
14-
secretsTemplateDir = "objstore"
14+
objStoreSecretsTemplateDir = "objstore"
15+
cacheTemplatesDir = "redis"
1516
)
1617

1718
// Secrets generates the secrets for the Production environment
1819
func (p Production) Secrets() {
19-
secrets(p.generator(secretsTemplateDir), p.namespace())
20+
secrets(p.generator(objStoreSecretsTemplateDir), p.namespace())
2021
}
2122

2223
// Secrets generates the secrets for the Stage environment
2324
func (s Stage) Secrets() {
24-
secrets(s.generator(secretsTemplateDir), s.namespace())
25+
ns := s.namespace()
26+
secrets(s.generator(objStoreSecretsTemplateDir), ns)
27+
var cacheObjs []runtime.Object
28+
for _, secret := range cacheSecretsStage(ns) {
29+
cacheObjs = append(cacheObjs, secret)
30+
}
31+
cacheSecrets(s.generator(cacheTemplatesDir), cacheObjs)
32+
}
33+
34+
func cacheSecrets(gen *mimic.Generator, secrets []runtime.Object) {
35+
gen.Add("cache.yaml", encoding.GhodssYAML(
36+
openshift.WrapInTemplate(
37+
secrets,
38+
metav1.ObjectMeta{Name: "redis-cache-secret"},
39+
[]templatev1.Parameter{
40+
{Name: "INDEX_CACHE_ADDR"},
41+
{Name: "INDEX_CACHE_PORT"},
42+
{Name: "INDEX_CACHE_AUTH_TOKEN"},
43+
{Name: "BUCKET_CACHE_ADDR"},
44+
{Name: "BUCKET_CACHE_PORT"},
45+
{Name: "BUCKET_CACHE_AUTH_TOKEN"},
46+
},
47+
),
48+
))
49+
gen.Generate()
2550
}
2651

2752
func secrets(gen *mimic.Generator, ns string) {
@@ -73,6 +98,68 @@ func (l Local) Secrets() {
7398
gen.Generate()
7499
}
75100

101+
const (
102+
indexCacheName = "thanos-index-cache"
103+
bucketCacheName = "thanos-bucket-cache"
104+
)
105+
106+
func cacheSecretsStage(namespace string) []*corev1.Secret {
107+
return []*corev1.Secret{
108+
{
109+
TypeMeta: metav1.TypeMeta{
110+
APIVersion: "v1",
111+
Kind: "Secret",
112+
},
113+
ObjectMeta: metav1.ObjectMeta{
114+
Name: indexCacheName,
115+
Namespace: namespace,
116+
Labels: map[string]string{
117+
"app.kubernetes.io/name": indexCacheName,
118+
},
119+
},
120+
Type: corev1.SecretTypeOpaque,
121+
StringData: map[string]string{
122+
"index-cache.yaml": `type: REDIS
123+
config:
124+
addr: ${INDEX_CACHE_ADDR}:${INDEX_CACHE_PORT}
125+
password: ${INDEX_CACHE_AUTH_TOKEN}
126+
db: 0
127+
max_item_size: 12428800 # 10 MiB
128+
ttl: 24h
129+
max_ascent_ttl: 24h
130+
max_size: 0 # Unlimited
131+
tls_enabled: true`,
132+
},
133+
},
134+
{
135+
TypeMeta: metav1.TypeMeta{
136+
APIVersion: "v1",
137+
Kind: "Secret",
138+
},
139+
ObjectMeta: metav1.ObjectMeta{
140+
Name: bucketCacheName,
141+
Namespace: namespace,
142+
Labels: map[string]string{
143+
"app.kubernetes.io/name": bucketCacheName,
144+
},
145+
},
146+
Type: corev1.SecretTypeOpaque,
147+
StringData: map[string]string{
148+
"bucket-cache.yaml": `type: REDIS
149+
config:
150+
addr: ${BUCKET_CACHE_ADDR}:${BUCKET_CACHE_PORT}
151+
password: ${BUCKET_CACHE_AUTH_TOKEN}
152+
db: 0
153+
max_item_size: 12428800 # 10 MiB
154+
ttl: 24h
155+
max_ascent_ttl: 24h
156+
max_size: 0 # Unlimited
157+
tls_enabled: true`,
158+
},
159+
},
160+
}
161+
}
162+
76163
// thanosObjectStoreTemplate creates a templated version for stage environment
77164
func thanosObjectStoreSecret(name, namespace string) *corev1.Secret {
78165
return &corev1.Secret{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
apiVersion: template.openshift.io/v1
2+
kind: Template
3+
metadata:
4+
creationTimestamp: null
5+
name: redis-cache-secret
6+
objects:
7+
- apiVersion: v1
8+
kind: Secret
9+
metadata:
10+
creationTimestamp: null
11+
labels:
12+
app.kubernetes.io/name: thanos-bucket-cache
13+
name: thanos-bucket-cache
14+
namespace: rhobs-stage
15+
stringData:
16+
bucket-cache.yaml: |-
17+
type: REDIS
18+
config:
19+
addr: ${BUCKET_CACHE_ADDR}:${BUCKET_CACHE_PORT}
20+
password: ${BUCKET_CACHE_AUTH_TOKEN}
21+
db: 0
22+
max_item_size: 12428800 # 10 MiB
23+
ttl: 24h
24+
max_ascent_ttl: 24h
25+
max_size: 0 # Unlimited
26+
tls_enabled: true
27+
type: Opaque
28+
- apiVersion: v1
29+
kind: Secret
30+
metadata:
31+
creationTimestamp: null
32+
labels:
33+
app.kubernetes.io/name: thanos-index-cache
34+
name: thanos-index-cache
35+
namespace: rhobs-stage
36+
stringData:
37+
index-cache.yaml: |-
38+
type: REDIS
39+
config:
40+
addr: ${INDEX_CACHE_ADDR}:${INDEX_CACHE_PORT}
41+
password: ${INDEX_CACHE_AUTH_TOKEN}
42+
db: 0
43+
max_item_size: 12428800 # 10 MiB
44+
ttl: 24h
45+
max_ascent_ttl: 24h
46+
max_size: 0 # Unlimited
47+
tls_enabled: true
48+
type: Opaque
49+
parameters:
50+
- name: INDEX_CACHE_ADDR
51+
- name: INDEX_CACHE_PORT
52+
- name: INDEX_CACHE_AUTH_TOKEN
53+
- name: BUCKET_CACHE_ADDR
54+
- name: BUCKET_CACHE_PORT
55+
- name: BUCKET_CACHE_AUTH_TOKEN

0 commit comments

Comments
 (0)