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

Commit 83f008b

Browse files
1. add the scaffolding code for NestedEtcd CRD and controller
2. fix some minor Makefile errors
1 parent 864ee02 commit 83f008b

18 files changed

+720
-5
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,12 @@ generate-go: ## Runs Go related generate targets
150150
go generate ./...
151151
$(CONTROLLER_GEN) \
152152
object:headerFile=./hack/boilerplate/boilerplate.generatego.txt \
153-
paths=./api/...
153+
paths=./apis/...
154154

155155
.PHONY: generate-manifests
156156
generate-manifests: ## Generate manifests e.g. CRD, RBAC etc.
157157
$(CONTROLLER_GEN) \
158-
paths=./api/... \
158+
paths=./apis/... \
159159
paths=./controllers/... \
160160
crd:crdVersions=v1 \
161161
rbac:roleName=manager-role \

PROJECT

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
domain: cluster.x-k8s.io
22
layout: go.kubebuilder.io/v3
3-
projectName: cluster-api-provider-nested
43
multigroup: true
4+
projectName: cluster-api-provider-nested
55
repo: sigs.k8s.io/cluster-api-provider-nested
66
resources:
77
- group: controlplane
88
kind: NestedControlPlane
99
version: v1alpha4
10+
- api:
11+
crdVersion: v1
12+
group: controlplane
13+
kind: NestedEtcd
14+
version: v1alpha4
1015
version: 3-alpha
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
addonv1alpha1 "sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/addon/pkg/apis/v1alpha1"
22+
)
23+
24+
type NestedComponentSpec struct {
25+
// NestedComponentSpec defines the common information for creating the component
26+
// +optional
27+
addonv1alpha1.CommonSpec `json:",inline"`
28+
29+
// PatchSpecs includes the user specifed settings
30+
// +optional
31+
addonv1alpha1.PatchSpec `json:",inline"`
32+
33+
// Resources defines the amount of computing resources that will be used by this component
34+
// +optional
35+
Resources corev1.ResourceRequirements `json:"resources",omitempty`
36+
37+
// Replicas defines the number of replicas in the component's workload
38+
// +optional
39+
Replicas int32 `json:"replicas",omitempty`
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
addonv1alpha1 "sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/addon/pkg/apis/v1alpha1"
22+
)
23+
24+
// NestedEtcdSpec defines the desired state of NestedEtcd
25+
type NestedEtcdSpec struct {
26+
// NestedComponentSpec contains the common and user-specified information that are
27+
// required for creating the component
28+
// +optional
29+
NestedComponentSpec `json:",inline"`
30+
}
31+
32+
// NestedEtcdStatus defines the observed state of NestedEtcd
33+
type NestedEtcdStatus struct {
34+
// Ready is set if all resources have been created
35+
Ready bool `json:"ready,omitempty"`
36+
37+
// EtcdDomain defines how to address the etcd instance
38+
Addresses []NestedEtcdAddress `json:"addresses,omitempty"`
39+
40+
// CommonStatus allows addons status monitoring
41+
addonv1alpha1.CommonStatus `json:",inline"`
42+
}
43+
44+
// EtcdAddress defines the observed addresses for etcd
45+
type NestedEtcdAddress struct {
46+
// IP Address of the etcd instance.
47+
// +optional
48+
IP string `json:"ip,omitempty"`
49+
50+
// Hostname of the etcd instance
51+
Hostname string `json:"hostname,omitempty"`
52+
53+
// Port of the etcd instance
54+
// +optional
55+
Port int32 `json:"port"`
56+
}
57+
58+
//+kubebuilder:object:root=true
59+
//+kubebuilder:subresource:status
60+
61+
// NestedEtcd is the Schema for the nestedetcds API
62+
type NestedEtcd struct {
63+
metav1.TypeMeta `json:",inline"`
64+
metav1.ObjectMeta `json:"metadata,omitempty"`
65+
66+
Spec NestedEtcdSpec `json:"spec,omitempty"`
67+
Status NestedEtcdStatus `json:"status,omitempty"`
68+
}
69+
70+
//+kubebuilder:object:root=true
71+
72+
// NestedEtcdList contains a list of NestedEtcd
73+
type NestedEtcdList struct {
74+
metav1.TypeMeta `json:",inline"`
75+
metav1.ListMeta `json:"metadata,omitempty"`
76+
Items []NestedEtcd `json:"items"`
77+
}
78+
79+
func init() {
80+
SchemeBuilder.Register(&NestedEtcd{}, &NestedEtcdList{})
81+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
---
3+
apiVersion: apiextensions.k8s.io/v1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
annotations:
7+
controller-gen.kubebuilder.io/version: v0.4.1-0.20201002000720-57250aac17f6
8+
creationTimestamp: null
9+
name: nestedcontrolplanes.controlplane.cluster.x-k8s.io
10+
spec:
11+
group: controlplane.cluster.x-k8s.io
12+
names:
13+
kind: NestedControlPlane
14+
listKind: NestedControlPlaneList
15+
plural: nestedcontrolplanes
16+
singular: nestedcontrolplane
17+
scope: Namespaced
18+
versions:
19+
- name: v1alpha4
20+
schema:
21+
openAPIV3Schema:
22+
description: NestedControlPlane is the Schema for the nestedcontrolplanes API
23+
properties:
24+
apiVersion:
25+
description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
26+
type: string
27+
kind:
28+
description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
29+
type: string
30+
metadata:
31+
type: object
32+
spec:
33+
description: NestedControlPlaneSpec defines the desired state of NestedControlPlane
34+
properties:
35+
foo:
36+
description: Foo is an example field of NestedControlPlane. Edit NestedControlPlane_types.go to remove/update
37+
type: string
38+
type: object
39+
status:
40+
description: NestedControlPlaneStatus defines the observed state of NestedControlPlane
41+
type: object
42+
type: object
43+
served: true
44+
storage: true
45+
subresources:
46+
status: {}
47+
status:
48+
acceptedNames:
49+
kind: ""
50+
plural: ""
51+
conditions: []
52+
storedVersions: []
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
2+
---
3+
apiVersion: apiextensions.k8s.io/v1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
annotations:
7+
controller-gen.kubebuilder.io/version: v0.4.1-0.20201002000720-57250aac17f6
8+
creationTimestamp: null
9+
name: nestedetcds.controlplane.cluster.x-k8s.io
10+
spec:
11+
group: controlplane.cluster.x-k8s.io
12+
names:
13+
kind: NestedEtcd
14+
listKind: NestedEtcdList
15+
plural: nestedetcds
16+
singular: nestedetcd
17+
scope: Namespaced
18+
versions:
19+
- name: v1alpha4
20+
schema:
21+
openAPIV3Schema:
22+
description: NestedEtcd is the Schema for the nestedetcds API
23+
properties:
24+
apiVersion:
25+
description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
26+
type: string
27+
kind:
28+
description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
29+
type: string
30+
metadata:
31+
type: object
32+
spec:
33+
description: NestedEtcdSpec defines the desired state of NestedEtcd
34+
properties:
35+
channel:
36+
description: 'Channel specifies a channel that can be used to resolve a specific addon, eg: stable It will be ignored if Version is specified'
37+
type: string
38+
patches:
39+
items:
40+
type: object
41+
type: array
42+
replicas:
43+
description: Replicas defines the number of replicas in the component's workload
44+
format: int32
45+
type: integer
46+
resources:
47+
description: Resources defines the amount of computing resources that will be used by this component
48+
properties:
49+
limits:
50+
additionalProperties:
51+
anyOf:
52+
- type: integer
53+
- type: string
54+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
55+
x-kubernetes-int-or-string: true
56+
description: 'Limits describes the maximum amount of compute resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
57+
type: object
58+
requests:
59+
additionalProperties:
60+
anyOf:
61+
- type: integer
62+
- type: string
63+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
64+
x-kubernetes-int-or-string: true
65+
description: 'Requests describes the minimum amount of compute resources required. If Requests is omitted for a container, it defaults to Limits if that is explicitly specified, otherwise to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
66+
type: object
67+
type: object
68+
version:
69+
description: Version specifies the exact addon version to be deployed, eg 1.2.3 It should not be specified if Channel is specified
70+
type: string
71+
type: object
72+
status:
73+
description: NestedEtcdStatus defines the observed state of NestedEtcd
74+
properties:
75+
addresses:
76+
description: EtcdDomain defines how to address the etcd instance
77+
items:
78+
description: EtcdAddress defines the observed addresses for etcd
79+
properties:
80+
hostname:
81+
description: Hostname of the etcd instance
82+
type: string
83+
ip:
84+
description: IP Address of the etcd instance.
85+
type: string
86+
port:
87+
description: Port of the etcd instance
88+
format: int32
89+
type: integer
90+
type: object
91+
type: array
92+
errors:
93+
items:
94+
type: string
95+
type: array
96+
healthy:
97+
type: boolean
98+
phase:
99+
type: string
100+
ready:
101+
description: Ready is set if all resources have been created
102+
type: boolean
103+
required:
104+
- healthy
105+
type: object
106+
type: object
107+
served: true
108+
storage: true
109+
subresources:
110+
status: {}
111+
status:
112+
acceptedNames:
113+
kind: ""
114+
plural: ""
115+
conditions: []
116+
storedVersions: []

config/crd/kustomization.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@
33
# It should be run by config/default
44
resources:
55
- bases/controlplane.cluster.x-k8s.io_nestedcontrolplanes.yaml
6+
- bases/controlplane.cluster.x-k8s.io_nestedetcds.yaml
67
# +kubebuilder:scaffold:crdkustomizeresource
78

89
patchesStrategicMerge:
910
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
1011
# patches here are for enabling the conversion webhook for each CRD
1112
#- patches/webhook_in_nestedcontrolplanes.yaml
13+
#- patches/webhook_in_nestedetcds.yaml
1214
# +kubebuilder:scaffold:crdkustomizewebhookpatch
1315

1416
# [CERTMANAGER] To enable webhook, uncomment all the sections with [CERTMANAGER] prefix.
1517
# patches here are for enabling the CA injection for each CRD
1618
#- patches/cainjection_in_nestedcontrolplanes.yaml
19+
#- patches/cainjection_in_nestedetcds.yaml
1720
# +kubebuilder:scaffold:crdkustomizecainjectionpatch
1821

1922
# the following config is for teaching kustomize how to do kustomization for CRDs.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# The following patch adds a directive for certmanager to inject CA into the CRD
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
annotations:
6+
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
7+
name: nestedetcds.controlplane.cluster.x-k8s.io
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# The following patch enables a conversion webhook for the CRD
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
name: nestedetcds.controlplane.cluster.x-k8s.io
6+
spec:
7+
conversion:
8+
strategy: Webhook
9+
webhook:
10+
clientConfig:
11+
service:
12+
namespace: system
13+
name: webhook-service
14+
path: /convert
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# permissions for end users to edit nestedetcds.
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: ClusterRole
4+
metadata:
5+
name: nestedetcd-editor-role
6+
rules:
7+
- apiGroups:
8+
- controlplane.cluster.x-k8s.io
9+
resources:
10+
- nestedetcds
11+
verbs:
12+
- create
13+
- delete
14+
- get
15+
- list
16+
- patch
17+
- update
18+
- watch
19+
- apiGroups:
20+
- controlplane.cluster.x-k8s.io
21+
resources:
22+
- nestedetcds/status
23+
verbs:
24+
- get

0 commit comments

Comments
 (0)