Skip to content

Commit 18dadc4

Browse files
authored
Merge pull request #90 from xrstf/byenami
Use upstream approach and images to installing etcd
2 parents ab5c966 + e8624f2 commit 18dadc4

File tree

9 files changed

+197
-17
lines changed

9 files changed

+197
-17
lines changed

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ KUSTOMIZE_VERSION ?= v5.4.3
88
CONTROLLER_TOOLS_VERSION ?= v0.16.1
99
GOLANGCI_LINT_VERSION ?= 2.1.6
1010
PROTOKOL_VERSION ?= 0.7.2
11+
HELM_VERSION ?= 3.18.6
1112

1213
# Image URL to use all building/pushing image targets
1314
IMG ?= ghcr.io/kcp-dev/kcp-operator
@@ -153,6 +154,7 @@ GOLANGCI_LINT = $(TOOLS_DIR)/golangci-lint
153154
PROTOKOL = $(TOOLS_DIR)/protokol
154155
RECONCILER_GEN := $(TOOLS_DIR)/reconciler-gen
155156
OPENSHIFT_GOIMPORTS := $(TOOLS_DIR)/openshift-goimports
157+
HELM := $(TOOLS_DIR)/helm
156158

157159
.PHONY: kubectl
158160
kubectl: $(KUBECTL) ## Download kubectl locally if necessary.
@@ -196,6 +198,13 @@ openshift-goimports: $(OPENSHIFT_GOIMPORTS) ## Download openshift-goimports loca
196198
$(OPENSHIFT_GOIMPORTS):
197199
@GO_MODULE=true hack/download-tool.sh github.com/openshift-eng/openshift-goimports openshift-goimports $(OPENSHIFT_GOIMPORTS_VER)
198200

201+
.PHONY: helm
202+
helm: $(HELM) ## Download Helm locally if necessary.
203+
204+
.PHONY: $(HELM)
205+
$(HELM):
206+
@hack/download-tool.sh https://get.helm.sh/helm-v${HELM_VERSION}-$(shell go env GOOS)-$(shell go env GOARCH).tar.gz helm $(HELM_VERSION)
207+
199208
##@ Documentation
200209

201210
VENVDIR=$(abspath docs/venv)

docs/content/setup/quickstart.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ kcp-operator has to be installed according to the instructions given in [Setup](
1212
!!! warning
1313
Never deploy etcd like below in production as it sets up an etcd instance without authentication or TLS.
1414

15-
Running a root shard requires a running etcd instance/cluster. A simple one can be set up with Helm and the Bitnami etcd chart:
15+
Running a root shard requires a running etcd instance/cluster. A simple one can be set up with Helm and the CI chart used by the kcp-operator for testing itself:
1616

1717
```sh
18-
helm install etcd oci://registry-1.docker.io/bitnamicharts/etcd --set auth.rbac.enabled=false --set auth.rbac.create=false
18+
git clone https://github.com/kcp-dev/kcp-operator
19+
helm install etcd ./kcp-operator/hack/ci/testdata/etcd
1920
```
2021

2122
## Create Root Shard
@@ -85,7 +86,7 @@ spec:
8586
spec:
8687
# expose this front-proxy via a load balancer
8788
type: LoadBalancer
88-
```
89+
```
8990

9091
kcp-operator will deploy a kcp-front-proxy installation based on this and connect it to the `root` root shard created before.
9192

@@ -166,7 +167,7 @@ To create a workspace, run:
166167

167168
```sh
168169
kubectl create-workspace test
169-
```
170+
```
170171

171172
Output should look like this:
172173

hack/ci/run-e2e-tests.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ chmod 600 "$KUBECONFIG"
6767
make protokol
6868
_tools/protokol --output "$ARTIFACTS/logs" --namespace 'kcp-*' --namespace 'e2e-*' >/dev/null 2>&1 &
6969

70+
# need Helm to setup etcd
71+
make helm
72+
7073
# load the operator image into the kind cluster
7174
image="ghcr.io/kcp-dev/kcp-operator:$IMAGE_TAG"
7275
archive=operator.tar
@@ -84,10 +87,10 @@ kubectl --namespace kcp-operator-system wait pod --all --for condition=Ready
8487
# deploying cert-manager
8588
echo "Deploying cert-manager…"
8689

87-
helm repo add jetstack https://charts.jetstack.io --force-update
88-
helm repo update
90+
_tools/helm repo add jetstack https://charts.jetstack.io --force-update
91+
_tools/helm repo update
8992

90-
helm upgrade \
93+
_tools/helm upgrade \
9194
--install \
9295
--namespace cert-manager \
9396
--create-namespace \
@@ -98,6 +101,10 @@ helm upgrade \
98101
kubectl apply --filename hack/ci/testdata/clusterissuer.yaml
99102

100103
echo "Running e2e tests…"
104+
105+
export HELM_BINARY="$(realpath _tools/helm)"
106+
export ETCD_HELM_CHART="$(realpath hack/ci/testdata/etcd)"
107+
101108
(set -x; go test -tags e2e -timeout 2h -v ./test/e2e/...)
102109

103110
echo "Done. :-)"

hack/ci/testdata/etcd/Chart.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v2
2+
name: etcd
3+
version: 1.0.0
4+
appVersion: "3.5.21"
5+
sources:
6+
- https://etcd.io/docs/v3.5/op-guide/kubernetes/
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
name: '{{ .Release.Name }}'
5+
automountServiceAccountToken: false
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: '{{ .Release.Name }}-headless'
5+
annotations:
6+
service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
7+
spec:
8+
type: ClusterIP
9+
clusterIP: None
10+
publishNotReadyAddresses: true
11+
selector:
12+
app.kubernetes.io/instance: '{{ .Release.Name }}'
13+
app.kubernetes.io/name: etcd
14+
ports:
15+
- name: client
16+
port: 2379
17+
targetPort: client
18+
- name: peer
19+
port: 2380
20+
targetPort: peer
21+
22+
---
23+
apiVersion: v1
24+
kind: Service
25+
metadata:
26+
name: '{{ .Release.Name }}'
27+
spec:
28+
type: ClusterIP
29+
selector:
30+
app.kubernetes.io/instance: '{{ .Release.Name }}'
31+
app.kubernetes.io/name: etcd
32+
ports:
33+
- name: client
34+
port: 2379
35+
targetPort: client
36+
nodePort: null
37+
- name: peer
38+
port: 2380
39+
targetPort: peer
40+
nodePort: null
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
apiVersion: apps/v1
2+
kind: StatefulSet
3+
metadata:
4+
name: '{{ .Release.Name }}'
5+
spec:
6+
replicas: 1
7+
selector:
8+
matchLabels:
9+
app.kubernetes.io/instance: '{{ .Release.Name }}'
10+
app.kubernetes.io/name: etcd
11+
serviceName: '{{ .Release.Name }}-headless'
12+
updateStrategy:
13+
type: RollingUpdate
14+
template:
15+
metadata:
16+
labels:
17+
app.kubernetes.io/instance: '{{ .Release.Name }}'
18+
app.kubernetes.io/name: etcd
19+
spec:
20+
automountServiceAccountToken: false
21+
securityContext:
22+
fsGroup: 1001
23+
fsGroupChangePolicy: Always
24+
serviceAccountName: '{{ .Release.Name }}'
25+
containers:
26+
- name: etcd
27+
image: quay.io/coreos/etcd:v3.5.21
28+
imagePullPolicy: IfNotPresent
29+
command:
30+
- /usr/local/bin/etcd
31+
args:
32+
- --name=$(HOSTNAME)
33+
- --data-dir=/data
34+
- --wal-dir=/data/wal
35+
- --listen-peer-urls=$(URI_SCHEME)://0.0.0.0:2380
36+
- --listen-client-urls=$(URI_SCHEME)://0.0.0.0:2379
37+
- --advertise-client-urls=$(URI_SCHEME)://$(HOSTNAME).$(SERVICE_NAME).svc.cluster.local:2379
38+
- --initial-cluster-state=new
39+
- --initial-cluster-token=$(HOSTNAME)
40+
- --initial-cluster=$(HOSTNAME)=$(URI_SCHEME)://$(HOSTNAME).$(SERVICE_NAME).svc.cluster.local:2380
41+
- --initial-advertise-peer-urls=$(URI_SCHEME)://$(HOSTNAME).$(SERVICE_NAME).svc.cluster.local:2380
42+
- --listen-metrics-urls=http://0.0.0.0:8080
43+
env:
44+
- name: HOSTNAME
45+
valueFrom:
46+
fieldRef:
47+
fieldPath: metadata.name
48+
- name: SERVICE_NAME
49+
value: '{{ .Release.Name }}-headless'
50+
- name: ETCDCTL_ENDPOINTS
51+
value: $(HOSTNAME).$(SERVICE_NAME):2379
52+
- name: URI_SCHEME
53+
value: "http"
54+
ports:
55+
- name: client
56+
containerPort: 2379
57+
protocol: TCP
58+
- name: peer
59+
containerPort: 2380
60+
protocol: TCP
61+
- name: metrics
62+
containerPort: 8080
63+
protocol: TCP
64+
livenessProbe:
65+
httpGet:
66+
path: /livez
67+
port: metrics
68+
initialDelaySeconds: 15
69+
periodSeconds: 10
70+
timeoutSeconds: 5
71+
failureThreshold: 3
72+
readinessProbe:
73+
httpGet:
74+
path: /readyz
75+
port: metrics
76+
initialDelaySeconds: 10
77+
periodSeconds: 5
78+
timeoutSeconds: 5
79+
successThreshold: 1
80+
failureThreshold: 30
81+
resources:
82+
requests:
83+
cpu: 250m
84+
memory: 256Mi
85+
volumeMounts:
86+
- name: data
87+
mountPath: /data
88+
securityContext:
89+
allowPrivilegeEscalation: false
90+
capabilities:
91+
drop:
92+
- ALL
93+
privileged: false
94+
readOnlyRootFilesystem: true
95+
runAsGroup: 1001
96+
runAsNonRoot: true
97+
runAsUser: 1001
98+
seccompProfile:
99+
type: RuntimeDefault
100+
volumeClaimTemplates:
101+
- metadata:
102+
name: data
103+
spec:
104+
accessModes:
105+
- ReadWriteOnce
106+
resources:
107+
requests:
108+
storage: 8Gi

hack/ci/testdata/etcd/values.yaml

Whitespace-only changes.

test/utils/deploy.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,17 @@ import (
3232
func DeployEtcd(t *testing.T, name, namespace string) string {
3333
t.Helper()
3434

35+
helmChart := os.Getenv("ETCD_HELM_CHART")
36+
3537
t.Logf("Installing etcd %q into %s…", name, namespace)
36-
args := []string{
37-
"install",
38-
name,
39-
"oci://registry-1.docker.io/bitnamicharts/etcd",
40-
"--namespace", namespace,
41-
"--version", "10.7.1", // latest version at the time of writing
42-
"--set", "auth.rbac.enabled=false",
43-
"--set", "auth.rbac.create=false",
38+
args := []string{"install", "--namespace", namespace, "--atomic", name, helmChart}
39+
40+
helmCommand := os.Getenv("HELM_BINARY")
41+
if helmCommand == "" {
42+
helmCommand = "helm"
4443
}
4544

46-
if err := exec.Command("helm", args...).Run(); err != nil {
45+
if err := exec.Command(helmCommand, args...).Run(); err != nil {
4746
t.Fatalf("Failed to deploy etcd: %v", err)
4847
}
4948

@@ -57,7 +56,12 @@ func DeployEtcd(t *testing.T, name, namespace string) string {
5756
"--timeout", "3m",
5857
}
5958

60-
if err := exec.Command("kubectl", args...).Run(); err != nil {
59+
kubectlCommand := os.Getenv("KUBECTL_BINARY")
60+
if kubectlCommand == "" {
61+
kubectlCommand = "kubectl"
62+
}
63+
64+
if err := exec.Command(kubectlCommand, args...).Run(); err != nil {
6165
t.Fatalf("Failed to wait for etcd to become ready: %v", err)
6266
}
6367

0 commit comments

Comments
 (0)