Skip to content

Commit 91f85d9

Browse files
committed
RFE-7051: add unsupported dedicated events etcd
This PR contains a dedicated in-memory etcd deployment that will run on one control plane host and configures the kube-apiserver to send events to it. Signed-off-by: Thomas Jungblut <[email protected]>
1 parent f93a306 commit 91f85d9

File tree

7 files changed

+419
-1
lines changed

7 files changed

+419
-1
lines changed
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: dedicated-event-etcd
5+
namespace: openshift-etcd
6+
labels:
7+
app: dedicated-event-etcd
8+
k8s-app: dedicated-event-etcd
9+
spec:
10+
strategy:
11+
type: "Recreate"
12+
replicas: 1
13+
selector:
14+
matchLabels:
15+
app: dedicated-event-etcd
16+
k8s-app: dedicated-event-etcd
17+
template:
18+
metadata:
19+
name: dedicated-event-etcd
20+
annotations:
21+
kubectl.kubernetes.io/default-container: etcdctl
22+
labels:
23+
app: dedicated-event-etcd
24+
k8s-app: dedicated-event-etcd
25+
spec:
26+
hostNetwork: true
27+
nodeSelector:
28+
node-role.kubernetes.io/control-plane: ''
29+
kubernetes.io/hostname: {{.NodeName}}
30+
tolerations:
31+
- operator: "Exists"
32+
containers:
33+
- name: etcdctl
34+
image: {{.Image}}
35+
imagePullPolicy: IfNotPresent
36+
terminationMessagePolicy: FallbackToLogsOnError
37+
command:
38+
- "/bin/bash"
39+
- "-c"
40+
- "trap TERM INT; sleep infinity & wait"
41+
volumeMounts:
42+
- mountPath: /var/lib/etcd/
43+
name: data-dir
44+
- mountPath: /etcd-all-bundles
45+
name: etcd-ca-bundle
46+
- mountPath: /etcd-all-certs
47+
name: etcd-all-certs
48+
env:
49+
# export ETCDCTL_ENDPOINTS="https://${MY_POD_IP}:20379"
50+
# export ETCDCTL_CACERT="/etcd-all-bundles/ca-bundle.crt"
51+
# export ETCDCTL_CERT="/etcd-all-certs/etcd-peer-${MY_NODE_NAME}.crt"
52+
# export ETCDCTL_KEY="/etcd-all-certs/etcd-peer-${MY_NODE_NAME}.key"
53+
54+
- name: MY_POD_IP
55+
valueFrom:
56+
fieldRef:
57+
fieldPath: status.podIP
58+
- name: MY_NODE_NAME
59+
valueFrom:
60+
fieldRef:
61+
fieldPath: spec.nodeName
62+
- name: ETCD_DATA_DIR
63+
value: "/var/lib/etcd"
64+
- name: ETCDCTL_ENDPOINTS
65+
value: "https://${MY_POD_IP}:20379"
66+
- name: ETCDCTL_CACERT
67+
value: "/etcd-all-bundles/ca-bundle.crt"
68+
- name: ETCDCTL_CERT
69+
value: "/etcd-all-certs/etcd-peer-${MY_NODE_NAME}.crt"
70+
- name: ETCDCTL_KEY
71+
value: "/etcd-all-certs/etcd-peer-${MY_NODE_NAME}.key"
72+
- name: etcd
73+
image: {{.Image}}
74+
imagePullPolicy: IfNotPresent
75+
terminationMessagePolicy: FallbackToLogsOnError
76+
env:
77+
- name: MY_POD_IP
78+
valueFrom:
79+
fieldRef:
80+
fieldPath: status.podIP
81+
- name: MY_NODE_NAME
82+
valueFrom:
83+
fieldRef:
84+
fieldPath: spec.nodeName
85+
command:
86+
- /bin/sh
87+
- -c
88+
- |
89+
#!/bin/sh
90+
set -euo pipefail
91+
set -x
92+
93+
export ETCD_NAME=events-etcd
94+
95+
echo "----------------"
96+
env | grep ETCD | grep -v NODE
97+
echo "----------------"
98+
echo "$MY_NODE_NAME"
99+
echo "$MY_POD_IP"
100+
echo "----------------"
101+
ls -l /etcd-all-certs
102+
echo "----------------"
103+
ls -l /etcd-all-bundles
104+
echo "----------------"
105+
106+
etcd \
107+
--data-dir=/var/lib/etcd \
108+
--logger=zap \
109+
--log-level=WARN \
110+
--snapshot-count=10000 \
111+
--quota-backend-bytes 8589934592 \
112+
--cert-file="/etcd-all-certs/etcd-serving-${MY_NODE_NAME}.crt" \
113+
--key-file="/etcd-all-certs/etcd-serving-${MY_NODE_NAME}.key" \
114+
--trusted-ca-file="/etcd-all-bundles/ca-bundle.crt" \
115+
--client-cert-auth=true \
116+
--initial-cluster="${ETCD_NAME}=https://${MY_POD_IP}:20380" \
117+
--initial-advertise-peer-urls="https://${MY_POD_IP}:20380" \
118+
--listen-peer-urls="https://${MY_POD_IP}:20380" \
119+
--peer-cert-file="/etcd-all-certs/etcd-peer-${MY_NODE_NAME}.crt"\
120+
--peer-key-file="/etcd-all-certs/etcd-peer-${MY_NODE_NAME}.key" \
121+
--peer-trusted-ca-file="/etcd-all-bundles/ca-bundle.crt" \
122+
--peer-client-cert-auth=true \
123+
--advertise-client-urls=https://${MY_POD_IP}:20379 \
124+
--listen-client-urls=https://0.0.0.0:20379
125+
126+
ports:
127+
- containerPort: 20379
128+
name: events-etcd
129+
protocol: TCP
130+
- containerPort: 20380
131+
# shortened to fit into 15 chars
132+
name: events-etcdpeer
133+
protocol: TCP
134+
resources:
135+
limits:
136+
memory: 8Gi
137+
securityContext:
138+
privileged: true
139+
readOnlyRootFilesystem: true
140+
volumeMounts:
141+
- mountPath: /var/lib/etcd/
142+
name: data-dir
143+
- mountPath: /etcd-all-bundles
144+
name: etcd-ca-bundle
145+
- mountPath: /etcd-all-certs
146+
name: etcd-all-certs
147+
volumes:
148+
- configMap:
149+
name: etcd-ca-bundle
150+
name: etcd-ca-bundle
151+
- secret:
152+
secretName: etcd-all-certs
153+
name: etcd-all-certs
154+
- name: data-dir
155+
emptyDir:
156+
medium: Memory
157+
sizeLimit: 8Gi
158+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
namespace: openshift-etcd
5+
name: events-etcd
6+
annotations:
7+
prometheus.io/scrape: "false"
8+
prometheus.io/scheme: https
9+
labels:
10+
k8s-app: dedicated-event-etcd
11+
spec:
12+
selector:
13+
k8s-app: dedicated-event-etcd
14+
ports:
15+
- name: events-etcd
16+
port: 20379
17+
protocol: TCP

pkg/operator/ceohelpers/podsubstitution.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func GetPodSubstitution(
125125
}
126126

127127
// RenderTemplate renders a Pod template from the Assets with the data from a PodSubstitutionTemplate
128-
func RenderTemplate(templateName string, subs *PodSubstitutionTemplate) (string, error) {
128+
func RenderTemplate[T interface{}](templateName string, subs *T) (string, error) {
129129
fm := template.FuncMap{"quote": func(arg reflect.Value) string {
130130
return "\"" + arg.String() + "\""
131131
}}

pkg/operator/ceohelpers/unsupported_override.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ func isUnsupportedUnsafeEtcd(spec *operatorv1.StaticPodOperatorSpec) (bool, erro
1616
return tryGetUnsupportedValue(spec, "useUnsupportedUnsafeNonHANonProductionUnstableEtcd")
1717
}
1818

19+
// IsDedicatedEtcdForEventsEnabled returns true if useUnsupportedDedicatedEtcdForEvents key is set to any parsable value
20+
func IsDedicatedEtcdForEventsEnabled(spec *operatorv1.StaticPodOperatorSpec) (bool, error) {
21+
return tryGetUnsupportedValue(spec, "useUnsupportedDedicatedEtcdForEvents")
22+
}
23+
1924
func tryGetUnsupportedValue(spec *operatorv1.StaticPodOperatorSpec, key string) (bool, error) {
2025
unsupportedConfig := map[string]interface{}{}
2126
if spec.UnsupportedConfigOverrides.Raw == nil {

0 commit comments

Comments
 (0)