Skip to content
This repository was archived by the owner on Oct 28, 2024. It is now read-only.

Commit a89320b

Browse files
implement the NestedEtcd controller
1 parent f22df4e commit a89320b

12 files changed

+878
-15
lines changed

Makefile

+5-5
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ apidiff: $(GO_APIDIFF) ## Check for API differences
143143
generate: ## Generate code
144144
$(MAKE) generate-manifests
145145
$(MAKE) generate-go
146-
$(MAKE) generate-bindata
146+
# $(MAKE) generate-bindata
147147

148148
.PHONY: generate-go
149149
generate-go: ## Runs Go related generate targets
@@ -163,8 +163,8 @@ generate-manifests: ## Generate manifests e.g. CRD, RBAC etc.
163163
output:webhook:dir=./config/webhook \
164164
webhook
165165
## Copy files in CI folders.
166-
cp -f ./config/rbac/*.yaml ./config/ci/rbac/
167-
cp -f ./config/manager/manager*.yaml ./config/ci/manager/
166+
# cp -f ./config/rbac/*.yaml ./config/ci/rbac/
167+
# cp -f ./config/manager/manager*.yaml ./config/ci/manager/
168168

169169
.PHONY: modules
170170
modules: ## Runs go mod to ensure modules are up to date.
@@ -184,8 +184,8 @@ docker-pull-prerequisites:
184184
.PHONY: docker-build
185185
docker-build: docker-pull-prerequisites ## Build the docker images for controller managers
186186
DOCKER_BUILDKIT=1 docker build --build-arg goproxy=$(GOPROXY) --build-arg ARCH=$(ARCH) --build-arg ldflags="$(LDFLAGS)" . -t $(CONTROLLER_IMG)-$(ARCH):$(TAG)
187-
$(MAKE) set-manifest-image MANIFEST_IMG=$(CONTROLLER_IMG)-$(ARCH) MANIFEST_TAG=$(TAG) TARGET_RESOURCE="./config/manager/manager_image_patch.yaml"
188-
$(MAKE) set-manifest-pull-policy TARGET_RESOURCE="./config/manager/manager_pull_policy.yaml"
187+
# $(MAKE) set-manifest-image MANIFEST_IMG=$(CONTROLLER_IMG)-$(ARCH) MANIFEST_TAG=$(TAG) TARGET_RESOURCE="./config/manager/manager_image_patch.yaml"
188+
# $(MAKE) set-manifest-pull-policy TARGET_RESOURCE="./config/manager/manager_pull_policy.yaml"
189189

190190
.PHONY: docker-push
191191
docker-push: ## Push the docker images

apis/controlplane/v1alpha4/nestedcomponentspec_types.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ type NestedComponentSpec struct {
3232

3333
// Resources defines the amount of computing resources that will be used by this component
3434
// +optional
35-
Resources corev1.ResourceRequirements `json:"resources",omitempty`
35+
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
3636

3737
// Replicas defines the number of replicas in the component's workload
3838
// +optional
39-
Replicas int32 `json:"replicas",omitempty`
39+
Replicas int32 `json:"replicas,omitempty"`
4040
}

apis/controlplane/v1alpha4/nestedetcd_types.go

+3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ type NestedEtcdAddress struct {
5656
}
5757

5858
//+kubebuilder:object:root=true
59+
//+kubebuilder:resource:scope=Namespaced,path=nestedetcds,shortName=netcd,categories=all
60+
//+kubebuilder:printcolumn:name="Ready",type="bool",JSONPath=".status.Ready"
61+
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
5962
//+kubebuilder:subresource:status
6063

6164
// NestedEtcd is the Schema for the nestedetcds API

apis/controlplane/v1alpha4/zz_generated.deepcopy.go

+130-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: {{.nestedetcdName}}
5+
namespace: {{.nestedetcdNamespace}}
6+
labels:
7+
component-name: {{.nestedetcdName}}
8+
spec:
9+
publishNotReadyAddresses: true
10+
clusterIP: None
11+
selector:
12+
component-name: {{.nestedetcdName}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
apiVersion: apps/v1
2+
kind: StatefulSet
3+
metadata:
4+
name: {{.nestedetcdName}}
5+
namespace: {{.nestedetcdNamespace}}
6+
spec:
7+
replicas: 1
8+
revisionHistoryLimit: 10
9+
serviceName: {{.nestedetcdName}}
10+
selector:
11+
matchLabels:
12+
component-name: {{.nestedetcdName}}
13+
# etcd will not be updated, unless it is deleted
14+
updateStrategy:
15+
type: OnDelete
16+
template:
17+
metadata:
18+
labels:
19+
component-name: {{.nestedetcdName}}
20+
spec:
21+
subdomain: etcd
22+
containers:
23+
- name: {{.nestedetcdName}}
24+
image: virtualcluster/etcd-v3.4.0
25+
imagePullPolicy: Always
26+
command:
27+
- etcd
28+
# pass the pod name(hostname) to container for composing the advertise-urls args
29+
env:
30+
- name: HOSTNAME
31+
valueFrom:
32+
fieldRef:
33+
fieldPath: metadata.name
34+
args:
35+
- --name=$(HOSTNAME)
36+
- --trusted-ca-file=/etc/kubernetes/pki/root/tls.crt
37+
- --client-cert-auth
38+
- --cert-file=/etc/kubernetes/pki/etcd/tls.crt
39+
- --key-file=/etc/kubernetes/pki/etcd/tls.key
40+
- --peer-client-cert-auth
41+
- --peer-trusted-ca-file=/etc/kubernetes/pki/root/tls.crt
42+
- --peer-cert-file=/etc/kubernetes/pki/etcd/tls.crt
43+
- --peer-key-file=/etc/kubernetes/pki/etcd/tls.key
44+
- --listen-peer-urls=https://0.0.0.0:2380
45+
- --listen-client-urls=https://0.0.0.0:2379
46+
- --initial-advertise-peer-urls=https://$(HOSTNAME).{{.nestedetcdName}}:2380
47+
# we use a headless service to encapsulate each pod
48+
- --advertise-client-urls=https://$(HOSTNAME).{{.nestedetcdName}}:2379
49+
- --initial-cluster-state=new
50+
- --initial-cluster-token=vc-etcd
51+
- --data-dir=/var/lib/etcd/data
52+
# --initial-cluster option will be set during runtime based on the number of replicas
53+
livenessProbe:
54+
exec:
55+
command:
56+
- sh
57+
- -c
58+
- ETCDCTL_API=3 etcdctl --endpoints=https://127.0.0.1:2379 --cacert=/etc/kubernetes/pki/root/tls.crt --cert=/etc/kubernetes/pki/etcd/tls.crt --key=/etc/kubernetes/pki/etcd/tls.key endpoint health
59+
failureThreshold: 8
60+
initialDelaySeconds: 60
61+
timeoutSeconds: 15
62+
readinessProbe:
63+
exec:
64+
command:
65+
- sh
66+
- -c
67+
- ETCDCTL_API=3 etcdctl --endpoints=https://127.0.0.1:2379 --cacert=/etc/kubernetes/pki/root/tls.crt --cert=/etc/kubernetes/pki/etcd/tls.crt --key=/etc/kubernetes/pki/etcd/tls.key endpoint health
68+
failureThreshold: 8
69+
initialDelaySeconds: 15
70+
periodSeconds: 2
71+
timeoutSeconds: 15
72+
volumeMounts:
73+
- mountPath: /etc/kubernetes/pki/etcd
74+
name: {{.nestedControlPlaneName}}-etcd-crt
75+
readOnly: true
76+
- mountPath: /etc/kubernetes/pki/root
77+
name: {{.nestedControlPlaneName}}-etcd
78+
readOnly: true
79+
volumes:
80+
- name: {{.nestedControlPlaneName}}-etcd-crt
81+
secret:
82+
defaultMode: 420
83+
secretName: {{.nestedControlPlaneName}}-etcd-crt
84+
- name: {{.nestedControlPlaneName}}-etcd
85+
secret:
86+
defaultMode: 420
87+
secretName: {{.nestedControlPlaneName}}-etcd

config/crd/bases/controlplane.cluster.x-k8s.io_nestedetcds.yaml

+12-1
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,24 @@ metadata:
1010
spec:
1111
group: controlplane.cluster.x-k8s.io
1212
names:
13+
categories:
14+
- all
1315
kind: NestedEtcd
1416
listKind: NestedEtcdList
1517
plural: nestedetcds
18+
shortNames:
19+
- netcd
1620
singular: nestedetcd
1721
scope: Namespaced
1822
versions:
19-
- name: v1alpha4
23+
- additionalPrinterColumns:
24+
- jsonPath: .status.Ready
25+
name: Ready
26+
type: bool
27+
- jsonPath: .metadata.creationTimestamp
28+
name: Age
29+
type: date
30+
name: v1alpha4
2031
schema:
2132
openAPIV3Schema:
2233
description: NestedEtcd is the Schema for the nestedetcds API

config/rbac/kustomization.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ resources:
66
# Comment the following 4 lines if you want to disable
77
# the auth proxy (https://github.com/brancz/kube-rbac-proxy)
88
# which protects your /metrics endpoint.
9-
- auth_proxy_service.yaml
10-
- auth_proxy_role.yaml
11-
- auth_proxy_role_binding.yaml
12-
- auth_proxy_client_clusterrole.yaml
9+
# - auth_proxy_service.yaml
10+
# - auth_proxy_role.yaml
11+
# - auth_proxy_role_binding.yaml
12+
# - auth_proxy_client_clusterrole.yaml

config/rbac/role.yaml

+20
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,26 @@ metadata:
66
creationTimestamp: null
77
name: manager-role
88
rules:
9+
- apiGroups:
10+
- apps
11+
resources:
12+
- statefulset
13+
verbs:
14+
- create
15+
- delete
16+
- get
17+
- list
18+
- patch
19+
- update
20+
- watch
21+
- apiGroups:
22+
- apps
23+
resources:
24+
- statefulset/status
25+
verbs:
26+
- get
27+
- patch
28+
- update
929
- apiGroups:
1030
- controlplane.cluster.x-k8s.io
1131
resources:

0 commit comments

Comments
 (0)