Skip to content

Commit b202ff0

Browse files
author
Yuvaraj Kakaraparthi
committed
CAPD: add DockerClusterTemplate type
1 parent 37c862b commit b202ff0

9 files changed

+323
-0
lines changed

test/infrastructure/docker/PROJECT

+3
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ resources:
2020
- group: infrastructure
2121
version: v1alpha4
2222
kind: DockerMachinePool
23+
- group: infrastructure
24+
kind: DockerClusterTemplate
25+
version: v1alpha4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
)
22+
23+
// DockerClusterTemplateSpec defines the desired state of DockerClusterTemplate.
24+
type DockerClusterTemplateSpec struct {
25+
Template DockerClusterTemplateResource `json:"template"`
26+
}
27+
28+
//+kubebuilder:object:root=true
29+
30+
// DockerClusterTemplate is the Schema for the dockerclustertemplates API.
31+
type DockerClusterTemplate struct {
32+
metav1.TypeMeta `json:",inline"`
33+
metav1.ObjectMeta `json:"metadata,omitempty"`
34+
35+
Spec DockerClusterTemplateSpec `json:"spec,omitempty"`
36+
}
37+
38+
//+kubebuilder:object:root=true
39+
// +kubebuilder:resource:path=dockerclustertemplates,scope=Namespaced,categories=cluster-api
40+
41+
// DockerClusterTemplateList contains a list of DockerClusterTemplate.
42+
type DockerClusterTemplateList struct {
43+
metav1.TypeMeta `json:",inline"`
44+
metav1.ListMeta `json:"metadata,omitempty"`
45+
Items []DockerClusterTemplate `json:"items"`
46+
}
47+
48+
func init() {
49+
SchemeBuilder.Register(&DockerClusterTemplate{}, &DockerClusterTemplateList{})
50+
}
51+
52+
// DockerClusterTemplateResource describes the data needed to create a DockerCluster from a template.
53+
type DockerClusterTemplateResource struct {
54+
Spec DockerClusterSpec `json:"spec"`
55+
}

test/infrastructure/docker/api/v1alpha4/zz_generated.deepcopy.go

+90
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,103 @@
1+
2+
---
3+
apiVersion: apiextensions.k8s.io/v1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
annotations:
7+
controller-gen.kubebuilder.io/version: v0.6.1
8+
creationTimestamp: null
9+
name: dockerclustertemplates.infrastructure.cluster.x-k8s.io
10+
spec:
11+
group: infrastructure.cluster.x-k8s.io
12+
names:
13+
kind: DockerClusterTemplate
14+
listKind: DockerClusterTemplateList
15+
plural: dockerclustertemplates
16+
singular: dockerclustertemplate
17+
scope: Namespaced
18+
versions:
19+
- name: v1alpha4
20+
schema:
21+
openAPIV3Schema:
22+
description: DockerClusterTemplate is the Schema for the dockerclustertemplates
23+
API.
24+
properties:
25+
apiVersion:
26+
description: 'APIVersion defines the versioned schema of this representation
27+
of an object. Servers should convert recognized schemas to the latest
28+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
29+
type: string
30+
kind:
31+
description: 'Kind is a string value representing the REST resource this
32+
object represents. Servers may infer this from the endpoint the client
33+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
34+
type: string
35+
metadata:
36+
type: object
37+
spec:
38+
description: DockerClusterTemplateSpec defines the desired state of DockerClusterTemplate.
39+
properties:
40+
template:
41+
description: DockerClusterTemplateResource describes the data needed
42+
to create a DockerCluster from a template.
43+
properties:
44+
spec:
45+
description: DockerClusterSpec defines the desired state of DockerCluster.
46+
properties:
47+
controlPlaneEndpoint:
48+
description: ControlPlaneEndpoint represents the endpoint
49+
used to communicate with the control plane.
50+
properties:
51+
host:
52+
description: Host is the hostname on which the API server
53+
is serving.
54+
type: string
55+
port:
56+
description: Port is the port on which the API server
57+
is serving.
58+
type: integer
59+
required:
60+
- host
61+
- port
62+
type: object
63+
failureDomains:
64+
additionalProperties:
65+
description: FailureDomainSpec is the Schema for Cluster
66+
API failure domains. It allows controllers to understand
67+
how many failure domains a cluster can optionally span
68+
across.
69+
properties:
70+
attributes:
71+
additionalProperties:
72+
type: string
73+
description: Attributes is a free form map of attributes
74+
an infrastructure provider might use or require.
75+
type: object
76+
controlPlane:
77+
description: ControlPlane determines if this failure
78+
domain is suitable for use by control plane machines.
79+
type: boolean
80+
type: object
81+
description: FailureDomains are not usulaly defined on the
82+
spec. The docker provider is special since failure domains
83+
don't mean anything in a local docker environment. Instead,
84+
the docker cluster controller will simply copy these into
85+
the Status and allow the Cluster API controllers to do what
86+
they will with the defined failure domains.
87+
type: object
88+
type: object
89+
required:
90+
- spec
91+
type: object
92+
required:
93+
- template
94+
type: object
95+
type: object
96+
served: true
97+
storage: true
98+
status:
99+
acceptedNames:
100+
kind: ""
101+
plural: ""
102+
conditions: []
103+
storedVersions: []

test/infrastructure/docker/config/crd/kustomization.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,22 @@ resources:
1212
- bases/infrastructure.cluster.x-k8s.io_dockerclusters.yaml
1313
- bases/infrastructure.cluster.x-k8s.io_dockermachinetemplates.yaml
1414
- bases/infrastructure.cluster.x-k8s.io_dockermachinepools.yaml
15+
- bases/infrastructure.cluster.x-k8s.io_dockerclustertemplates.yaml
1516
# +kubebuilder:scaffold:crdkustomizeresource
1617

1718
patchesStrategicMerge: []
1819
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
1920
# patches here are for enabling the conversion webhook for each CRD
2021
#- patches/webhook_in_dockermachines.yaml
2122
#- patches/webhook_in_dockerclusters.yaml
23+
#- patches/webhook_in_dockerclustertemplates.yaml
2224
# +kubebuilder:scaffold:crdkustomizewebhookpatch
2325

2426
# [CERTMANAGER] To enable webhook, uncomment all the sections with [CERTMANAGER] prefix.
2527
# patches here are for enabling the CA injection for each CRD
2628
#- patches/cainjection_in_dockermachines.yaml
2729
#- patches/cainjection_in_dockerclusters.yaml
30+
#- patches/cainjection_in_dockerclustertemplates.yaml
2831
# +kubebuilder:scaffold:crdkustomizecainjectionpatch
2932

3033
# the following config is for teaching kustomize how to do kustomization for CRDs.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# The following patch adds a directive for certmanager to inject CA into the CRD
2+
# CRD conversion requires k8s 1.13 or later.
3+
apiVersion: apiextensions.k8s.io/v1beta1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
annotations:
7+
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
8+
name: dockerclustertemplates.infrastructure.cluster.x-k8s.io
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# The following patch enables conversion webhook for CRD
2+
# CRD conversion requires k8s 1.13 or later.
3+
apiVersion: apiextensions.k8s.io/v1beta1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
name: dockerclustertemplates.infrastructure.cluster.x-k8s.io
7+
spec:
8+
conversion:
9+
strategy: Webhook
10+
webhookClientConfig:
11+
# this is "\n" used as a placeholder, otherwise it will be rejected by the apiserver for being blank,
12+
# but we're going to set it later using the cert-manager (or potentially a patch if not using cert-manager)
13+
caBundle: Cg==
14+
service:
15+
namespace: system
16+
name: webhook-service
17+
path: /convert
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# permissions for end users to edit dockerclustertemplates.
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: ClusterRole
4+
metadata:
5+
name: dockerclustertemplate-editor-role
6+
rules:
7+
- apiGroups:
8+
- infrastructure.cluster.x-k8s.io
9+
resources:
10+
- dockerclustertemplates
11+
verbs:
12+
- create
13+
- delete
14+
- get
15+
- list
16+
- patch
17+
- update
18+
- watch
19+
- apiGroups:
20+
- infrastructure.cluster.x-k8s.io
21+
resources:
22+
- dockerclustertemplates/status
23+
verbs:
24+
- get
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# permissions for end users to view dockerclustertemplates.
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: ClusterRole
4+
metadata:
5+
name: dockerclustertemplate-viewer-role
6+
rules:
7+
- apiGroups:
8+
- infrastructure.cluster.x-k8s.io
9+
resources:
10+
- dockerclustertemplates
11+
verbs:
12+
- get
13+
- list
14+
- watch
15+
- apiGroups:
16+
- infrastructure.cluster.x-k8s.io
17+
resources:
18+
- dockerclustertemplates/status
19+
verbs:
20+
- get

0 commit comments

Comments
 (0)