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

Commit a2cecf1

Browse files
Implement the NestedAPIServer controller (#37)
1 parent 7beb578 commit a2cecf1

23 files changed

+1155
-421
lines changed

PROJECT

+5
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,9 @@ resources:
1212
group: controlplane
1313
kind: NestedEtcd
1414
version: v1alpha4
15+
- api:
16+
crdVersion: v1
17+
group: controlplane
18+
kind: NestedAPIServer
19+
version: v1alpha4
1520
version: 3-alpha
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
Copyright 2021 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha4
18+
19+
import (
20+
corev1 "k8s.io/api/core/v1"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
addonv1alpha1 "sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/addon/pkg/apis/v1alpha1"
23+
)
24+
25+
// NestedAPIServerSpec defines the desired state of NestedAPIServer
26+
type NestedAPIServerSpec struct {
27+
// NestedComponentSpec contains the common and user-specified information that are
28+
// required for creating the component
29+
// +optional
30+
NestedComponentSpec `json:",inline"`
31+
}
32+
33+
// NestedAPIServerStatus defines the observed state of NestedAPIServer
34+
type NestedAPIServerStatus struct {
35+
// APIServerService is the reference to the service that expose the APIServer
36+
// +optional
37+
APIServerService *corev1.ObjectReference `json:"apiserverService,omitempty"`
38+
39+
// CommonStatus allows addons status monitoring
40+
addonv1alpha1.CommonStatus `json:",inline"`
41+
}
42+
43+
//+kubebuilder:object:root=true
44+
//+kubebuilder:resource:scope=Namespaced,path=nestedapiservers,shortName=napiserver
45+
//+kubebuilder:categories=capi,capn
46+
//+kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase"
47+
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
48+
//+kubebuilder:subresource:status
49+
50+
// NestedAPIServer is the Schema for the nestedapiservers API
51+
type NestedAPIServer struct {
52+
metav1.TypeMeta `json:",inline"`
53+
metav1.ObjectMeta `json:"metadata,omitempty"`
54+
55+
Spec NestedAPIServerSpec `json:"spec,omitempty"`
56+
Status NestedAPIServerStatus `json:"status,omitempty"`
57+
}
58+
59+
//+kubebuilder:object:root=true
60+
61+
// NestedAPIServerList contains a list of NestedAPIServer
62+
type NestedAPIServerList struct {
63+
metav1.TypeMeta `json:",inline"`
64+
metav1.ListMeta `json:"metadata,omitempty"`
65+
Items []NestedAPIServer `json:"items"`
66+
}
67+
68+
func init() {
69+
SchemeBuilder.Register(&NestedAPIServer{}, &NestedAPIServerList{})
70+
}

apis/controlplane/v1alpha4/nestedcomponentspec_types.go renamed to apis/controlplane/v1alpha4/nestedcomponent_types.go

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

24+
// NestedComponentSpec defines the common fields for nested components
2425
type NestedComponentSpec struct {
2526
// NestedComponentSpec defines the common information for creating the
2627
// component
@@ -40,3 +41,18 @@ type NestedComponentSpec struct {
4041
// +optional
4142
Replicas int32 `json:"replicas,omitempty"`
4243
}
44+
45+
type ComponentPhase string
46+
47+
const (
48+
Ready ComponentPhase = "Ready"
49+
Unready ComponentPhase = "Unready"
50+
)
51+
52+
type ComponentKind string
53+
54+
const (
55+
APIServer ComponentKind = "NestedAPIServer"
56+
Etcd ComponentKind = "NestedEtcd"
57+
ControllerManager ComponentKind = "NestedControllerManager"
58+
)

apis/controlplane/v1alpha4/nestedetcd_types.go

-7
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@ 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-
3124
// NestedEtcdSpec defines the desired state of NestedEtcd
3225
type NestedEtcdSpec struct {
3326
// NestedComponentSpec contains the common and user-specified information

apis/controlplane/v1alpha4/zz_generated.deepcopy.go

+96
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,15 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: {{.nestedAPIServerName}}
5+
namespace: {{.nestedAPIServerNamespace}}
6+
labels:
7+
component-name: {{.nestedAPIServerName}}
8+
spec:
9+
selector:
10+
component-name: {{.nestedAPIServerName}}
11+
type: NodePort
12+
ports:
13+
- port: 6443
14+
protocol: TCP
15+
targetPort: api
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
apiVersion: apps/v1
2+
kind: StatefulSet
3+
metadata:
4+
name: {{.nestedAPIServerName}}
5+
namespace: {{.nestedAPIServerNamespace}}
6+
spec:
7+
revisionHistoryLimit: 10
8+
serviceName: {{.nestedAPIServerName}}
9+
selector:
10+
matchLabels:
11+
component-name: apiserver
12+
# apiserver will not be updated, unless it is deleted
13+
updateStrategy:
14+
type: OnDelete
15+
template:
16+
metadata:
17+
labels:
18+
component-name: {{.nestedAPIServerName}}
19+
spec:
20+
hostname: apiserver
21+
subdomain: apiserver-svc
22+
containers:
23+
- name: {{.nestedAPIServerName}}
24+
image: virtualcluster/apiserver-v1.16.2
25+
imagePullPolicy: Always
26+
command:
27+
- kube-apiserver
28+
args:
29+
- --bind-address=0.0.0.0
30+
- --allow-privileged=true
31+
- --anonymous-auth=true
32+
- --client-ca-file=/etc/kubernetes/pki/root/tls.crt
33+
- --tls-cert-file=/etc/kubernetes/pki/apiserver/tls.crt
34+
- --tls-private-key-file=/etc/kubernetes/pki/apiserver/tls.key
35+
- --kubelet-https=true
36+
- --kubelet-client-certificate=/etc/kubernetes/pki/apiserver/tls.crt
37+
- --kubelet-client-key=/etc/kubernetes/pki/apiserver/tls.key
38+
- --enable-bootstrap-token-auth=true
39+
- --etcd-servers=https://{{.nestedEtcdName}}-0.{{.nestedEtcdName}}:2379
40+
- --etcd-cafile=/etc/kubernetes/pki/root/tls.crt
41+
- --etcd-certfile=/etc/kubernetes/pki/apiserver/tls.crt
42+
- --etcd-keyfile=/etc/kubernetes/pki/apiserver/tls.key
43+
- --service-account-key-file=/etc/kubernetes/pki/service-account/tls.key
44+
- --service-cluster-ip-range=10.32.0.0/16
45+
- --service-node-port-range=30000-32767
46+
- --authorization-mode=Node,RBAC
47+
- --runtime-config=api/all
48+
- --enable-admission-plugins=NamespaceLifecycle,NodeRestriction,LimitRanger,ServiceAccount,DefaultStorageClass,ResourceQuota
49+
- --apiserver-count=1
50+
- --endpoint-reconciler-type=master-count
51+
- --v=2
52+
ports:
53+
- containerPort: 6443
54+
protocol: TCP
55+
name: api
56+
livenessProbe:
57+
# since we set anonymous-auth to false, we use tcp instead of https
58+
tcpSocket:
59+
port: 6443
60+
failureThreshold: 8
61+
initialDelaySeconds: 15
62+
periodSeconds: 10
63+
timeoutSeconds: 15
64+
readinessProbe:
65+
httpGet:
66+
port: 6443
67+
path: /healthz
68+
scheme: HTTPS
69+
failureThreshold: 8
70+
initialDelaySeconds: 5
71+
periodSeconds: 2
72+
timeoutSeconds: 30
73+
volumeMounts:
74+
- mountPath: /etc/kubernetes/pki/apiserver
75+
name: {{.nestedControlPlaneName}}-apiserver-client-crt
76+
readOnly: true
77+
- mountPath: /etc/kubernetes/pki/root
78+
name: {{.nestedControlPlaneName}}-apiserver
79+
readOnly: true
80+
- mountPath: /etc/kubernetes/pki/service-account
81+
name: {{.nestedControlPlaneName}}-sa
82+
readOnly: true
83+
terminationGracePeriodSeconds: 30
84+
dnsConfig:
85+
searches:
86+
- cluster.local
87+
volumes:
88+
- name: {{.nestedControlPlaneName}}-apiserver-client-crt
89+
secret:
90+
defaultMode: 420
91+
secretName: {{.nestedControlPlaneName}}-apiserver-client-crt
92+
- name: {{.nestedControlPlaneName}}-apiserver
93+
secret:
94+
defaultMode: 420
95+
secretName: {{.nestedControlPlaneName}}-apiserver
96+
- name: {{.nestedControlPlaneName}}-sa
97+
secret:
98+
defaultMode: 420
99+
secretName: {{.nestedControlPlaneName}}-sa

config/component-templates/nested-etcd/nested-etcd-statefulset-template.yaml

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
apiVersion: apps/v1
22
kind: StatefulSet
33
metadata:
4-
name: {{.nestedetcdName}}
5-
namespace: {{.nestedetcdNamespace}}
4+
name: {{.nestedEtcdName}}
5+
namespace: {{.nestedEtcdNamespace}}
66
spec:
7-
replicas: {{.nestedetcdStsReplicas}}
87
revisionHistoryLimit: 10
9-
serviceName: {{.nestedetcdName}}
8+
serviceName: {{.nestedEtcdName}}
109
selector:
1110
matchLabels:
12-
component-name: {{.nestedetcdName}}
11+
component-name: {{.nestedEtcdName}}
1312
# etcd will not be updated, unless it is deleted
1413
updateStrategy:
1514
type: OnDelete
1615
template:
1716
metadata:
1817
labels:
19-
component-name: {{.nestedetcdName}}
18+
component-name: {{.nestedEtcdName}}
2019
spec:
2120
subdomain: etcd
2221
containers:
23-
- name: {{.nestedetcdName}}
22+
- name: {{.nestedEtcdName}}
2423
image: virtualcluster/etcd-v3.4.0
2524
imagePullPolicy: Always
2625
command:
@@ -43,9 +42,9 @@ spec:
4342
- --peer-key-file=/etc/kubernetes/pki/etcd/tls.key
4443
- --listen-peer-urls=https://0.0.0.0:2380
4544
- --listen-client-urls=https://0.0.0.0:2379
46-
- --initial-advertise-peer-urls=https://$(HOSTNAME).{{.nestedetcdName}}:2380
45+
- --initial-advertise-peer-urls=https://$(HOSTNAME).{{.nestedEtcdName}}:2380
4746
# we use a headless service to encapsulate each pod
48-
- --advertise-client-urls=https://$(HOSTNAME).{{.nestedetcdName}}:2379
47+
- --advertise-client-urls=https://$(HOSTNAME).{{.nestedEtcdName}}:2379
4948
- --initial-cluster-state=new
5049
- --initial-cluster-token=vc-etcd
5150
- --data-dir=/var/lib/etcd/data

0 commit comments

Comments
 (0)