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

Commit 3d78676

Browse files
implement the NestedEtcd controller
1 parent f22df4e commit 3d78676

File tree

10 files changed

+668
-22
lines changed

10 files changed

+668
-22
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

+6-4
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,21 @@ import (
2222
)
2323

2424
type NestedComponentSpec struct {
25-
// NestedComponentSpec defines the common information for creating the component
25+
// NestedComponentSpec defines the common information for creating the
26+
// component
2627
// +optional
2728
addonv1alpha1.CommonSpec `json:",inline"`
2829

2930
// PatchSpecs includes the user specifed settings
3031
// +optional
3132
addonv1alpha1.PatchSpec `json:",inline"`
3233

33-
// Resources defines the amount of computing resources that will be used by this component
34+
// Resources defines the amount of computing resources that will be used
35+
// by this component
3436
// +optional
35-
Resources corev1.ResourceRequirements `json:"resources",omitempty`
37+
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
3638

3739
// Replicas defines the number of replicas in the component's workload
3840
// +optional
39-
Replicas int32 `json:"replicas",omitempty`
41+
Replicas int32 `json:"replicas,omitempty"`
4042
}

apis/controlplane/v1alpha4/nestedetcd_types.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,23 @@ import (
2121
addonv1alpha1 "sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/addon/pkg/apis/v1alpha1"
2222
)
2323

24+
type NestedEtcdPhase string
25+
26+
const (
27+
NestedEtcdReady NestedEtcdPhase = "ready"
28+
NestedEtcdUnready NestedEtcdPhase = "unready"
29+
)
30+
2431
// NestedEtcdSpec defines the desired state of NestedEtcd
2532
type NestedEtcdSpec struct {
26-
// NestedComponentSpec contains the common and user-specified information that are
27-
// required for creating the component
33+
// NestedComponentSpec contains the common and user-specified information
34+
// that are required for creating the component
2835
// +optional
2936
NestedComponentSpec `json:",inline"`
3037
}
3138

3239
// NestedEtcdStatus defines the observed state of NestedEtcd
3340
type NestedEtcdStatus struct {
34-
// Ready is set if all resources have been created
35-
Ready bool `json:"ready,omitempty"`
36-
3741
// EtcdDomain defines how to address the etcd instance
3842
Addresses []NestedEtcdAddress `json:"addresses,omitempty"`
3943

@@ -56,6 +60,9 @@ type NestedEtcdAddress struct {
5660
}
5761

5862
//+kubebuilder:object:root=true
63+
//+kubebuilder:resource:scope=Namespaced,path=nestedetcds,shortName=netcd,categories=all,capn
64+
//+kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase"
65+
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
5966
//+kubebuilder:subresource:status
6067

6168
// 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-client-cert
75+
readOnly: true
76+
- mountPath: /etc/kubernetes/pki/root
77+
name: {{.nestedControlPlaneName}}-etcd
78+
readOnly: true
79+
volumes:
80+
- name: {{.nestedControlPlaneName}}-etcd-client-cert
81+
secret:
82+
defaultMode: 420
83+
secretName: {{.nestedControlPlaneName}}-etcd-client-cert
84+
- name: {{.nestedControlPlaneName}}-etcd
85+
secret:
86+
defaultMode: 420
87+
secretName: {{.nestedControlPlaneName}}-etcd

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

+12-4
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.phase
25+
name: Phase
26+
type: string
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
@@ -97,9 +108,6 @@ spec:
97108
type: boolean
98109
phase:
99110
type: string
100-
ready:
101-
description: Ready is set if all resources have been created
102-
type: boolean
103111
required:
104112
- healthy
105113
type: object

0 commit comments

Comments
 (0)