Skip to content

Commit c986934

Browse files
committed
CABPK - v1alpha3 types
1 parent 6b9b7d7 commit c986934

23 files changed

+2351
-718
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ generate-manifests: $(CONTROLLER_GEN) ## Generate manifests e.g. CRD, RBAC etc.
153153
webhook
154154
$(CONTROLLER_GEN) \
155155
paths=./bootstrap/kubeadm/api/... \
156-
crd:trivialVersions=true \
156+
crd \
157157
output:crd:dir=./config/crd/bases
158158
## Copy files in CI folders.
159159
cp -f ./config/rbac/*.yaml ./config/ci/rbac/

api/v1alpha3/kubeadm_control_plane_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package v1alpha3
1919
import (
2020
corev1 "k8s.io/api/core/v1"
2121
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22-
cabpkv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1alpha2"
22+
cabpkv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1alpha3"
2323
"sigs.k8s.io/cluster-api/errors"
2424
)
2525

@@ -90,7 +90,7 @@ type KubeadmControlPlaneStatus struct {
9090
// state, and will be set to a token value suitable for
9191
// programmatic interpretation.
9292
// +optional
93-
Failurereason errors.KubeadmControlPlaneStatusError `json:"failureReason,omitempty"`
93+
FailureReason errors.KubeadmControlPlaneStatusError `json:"failureReason,omitempty"`
9494

9595
// ErrorMessage indicates that there is a terminal problem reconciling the
9696
// state, and will be set to a descriptive error message.

bootstrap/kubeadm/PROJECT

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@ resources:
88
- group: bootstrap
99
version: v1alpha2
1010
kind: KubeadmConfigTemplate
11+
- group: bootstrap
12+
version: v1alpha3
13+
kind: KubeadmConfig
14+
- group: bootstrap
15+
version: v1alpha3
16+
kind: KubeadmConfigTemplate

bootstrap/kubeadm/api/v1alpha2/kubeadmbootstrapconfig_types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ type KubeadmConfigStatus struct {
8282

8383
// +kubebuilder:object:root=true
8484
// +kubebuilder:resource:path=kubeadmconfigs,scope=Namespaced,categories=cluster-api
85-
// +kubebuilder:storageversion
8685
// +kubebuilder:subresource:status
8786

8887
// KubeadmConfig is the Schema for the kubeadmconfigs API

bootstrap/kubeadm/api/v1alpha2/kubeadmconfigtemplate_types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ type KubeadmConfigTemplateSpec struct {
2727

2828
// +kubebuilder:object:root=true
2929
// +kubebuilder:resource:path=kubeadmconfigtemplates,scope=Namespaced,categories=cluster-api
30-
// +kubebuilder:storageversion
3130

3231
// KubeadmConfigTemplate is the Schema for the kubeadmconfigtemplates API
3332
type KubeadmConfigTemplate struct {
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright 2019 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 v1alpha3 contains API Schema definitions for the kubeadm v1alpha3 API group
18+
// +kubebuilder:object:generate=true
19+
// +groupName=bootstrap.cluster.x-k8s.io
20+
package v1alpha3
21+
22+
import (
23+
"k8s.io/apimachinery/pkg/runtime/schema"
24+
"sigs.k8s.io/controller-runtime/pkg/scheme"
25+
)
26+
27+
var (
28+
// GroupVersion is group version used to register these objects
29+
GroupVersion = schema.GroupVersion{Group: "bootstrap.cluster.x-k8s.io", Version: "v1alpha3"}
30+
31+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
32+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
33+
34+
// AddToScheme adds the types in this group-version to the given scheme.
35+
AddToScheme = SchemeBuilder.AddToScheme
36+
)
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
/*
2+
Copyright 2019 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 v1alpha3
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
kubeadmv1beta1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/types/v1beta1"
22+
)
23+
24+
// Format specifies the output format of the bootstrap data
25+
// +kubebuilder:validation:Enum=cloud-config
26+
type Format string
27+
28+
const (
29+
// CloudConfig make the bootstrap data to be of cloud-config format
30+
CloudConfig Format = "cloud-config"
31+
)
32+
33+
// KubeadmConfigSpec defines the desired state of KubeadmConfig.
34+
// Either ClusterConfiguration and InitConfiguration should be defined or the JoinConfiguration should be defined.
35+
type KubeadmConfigSpec struct {
36+
// ClusterConfiguration along with InitConfiguration are the configurations necessary for the init command
37+
// +optional
38+
ClusterConfiguration *kubeadmv1beta1.ClusterConfiguration `json:"clusterConfiguration,omitempty"`
39+
// InitConfiguration along with ClusterConfiguration are the configurations necessary for the init command
40+
// +optional
41+
InitConfiguration *kubeadmv1beta1.InitConfiguration `json:"initConfiguration,omitempty"`
42+
// JoinConfiguration is the kubeadm configuration for the join command
43+
// +optional
44+
JoinConfiguration *kubeadmv1beta1.JoinConfiguration `json:"joinConfiguration,omitempty"`
45+
// Files specifies extra files to be passed to user_data upon creation.
46+
// +optional
47+
Files []File `json:"files,omitempty"`
48+
// PreKubeadmCommands specifies extra commands to run before kubeadm runs
49+
// +optional
50+
PreKubeadmCommands []string `json:"preKubeadmCommands,omitempty"`
51+
// PostKubeadmCommands specifies extra commands to run after kubeadm runs
52+
// +optional
53+
PostKubeadmCommands []string `json:"postKubeadmCommands,omitempty"`
54+
// Users specifies extra users to add
55+
// +optional
56+
Users []User `json:"users,omitempty"`
57+
// NTP specifies NTP configuration
58+
// +optional
59+
NTP *NTP `json:"ntp,omitempty"`
60+
// Format specifies the output format of the bootstrap data
61+
// +optional
62+
Format Format `json:"format,omitempty"`
63+
}
64+
65+
// KubeadmConfigStatus defines the observed state of KubeadmConfig
66+
type KubeadmConfigStatus struct {
67+
// Ready indicates the BootstrapData field is ready to be consumed
68+
Ready bool `json:"ready,omitempty"`
69+
70+
// BootstrapData will be a cloud-init script for now
71+
// +optional
72+
BootstrapData []byte `json:"bootstrapData,omitempty"`
73+
74+
// FailureReason will be set on non-retryable errors
75+
// +optional
76+
FailureReason string `json:"failureReason,omitempty"`
77+
78+
// FailureMessage will be set on non-retryable errors
79+
// +optional
80+
FailureMessage string `json:"failureMessage,omitempty"`
81+
}
82+
83+
// +kubebuilder:object:root=true
84+
// +kubebuilder:resource:path=kubeadmconfigs,scope=Namespaced,categories=cluster-api
85+
// +kubebuilder:storageversion
86+
// +kubebuilder:subresource:status
87+
88+
// KubeadmConfig is the Schema for the kubeadmconfigs API
89+
type KubeadmConfig struct {
90+
metav1.TypeMeta `json:",inline"`
91+
metav1.ObjectMeta `json:"metadata,omitempty"`
92+
93+
Spec KubeadmConfigSpec `json:"spec,omitempty"`
94+
Status KubeadmConfigStatus `json:"status,omitempty"`
95+
}
96+
97+
// +kubebuilder:object:root=true
98+
99+
// KubeadmConfigList contains a list of KubeadmConfig
100+
type KubeadmConfigList struct {
101+
metav1.TypeMeta `json:",inline"`
102+
metav1.ListMeta `json:"metadata,omitempty"`
103+
Items []KubeadmConfig `json:"items"`
104+
}
105+
106+
func init() {
107+
SchemeBuilder.Register(&KubeadmConfig{}, &KubeadmConfigList{})
108+
}
109+
110+
// Encoding specifies the cloud-init file encoding.
111+
// +kubebuilder:validation:Enum=base64;gzip;gzip+base64
112+
type Encoding string
113+
114+
const (
115+
// Base64 implies the contents of the file are encoded as base64.
116+
Base64 Encoding = "base64"
117+
// Gzip implies the contents of the file are encoded with gzip.
118+
Gzip Encoding = "gzip"
119+
// GzipBase64 implies the contents of the file are first base64 encoded and then gzip encoded.
120+
GzipBase64 Encoding = "gzip+base64"
121+
)
122+
123+
// File defines the input for generating write_files in cloud-init.
124+
type File struct {
125+
// Path specifies the full path on disk where to store the file.
126+
Path string `json:"path"`
127+
128+
// Owner specifies the ownership of the file, e.g. "root:root".
129+
// +optional
130+
Owner string `json:"owner,omitempty"`
131+
132+
// Permissions specifies the permissions to assign to the file, e.g. "0640".
133+
// +optional
134+
Permissions string `json:"permissions,omitempty"`
135+
136+
// Encoding specifies the encoding of the file contents.
137+
// +optional
138+
Encoding Encoding `json:"encoding,omitempty"`
139+
140+
// Content is the actual content of the file.
141+
Content string `json:"content"`
142+
}
143+
144+
// User defines the input for a generated user in cloud-init.
145+
type User struct {
146+
// Name specifies the user name
147+
Name string `json:"name"`
148+
149+
// Gecos specifies the gecos to use for the user
150+
// +optional
151+
Gecos *string `json:"gecos,omitempty"`
152+
153+
// Groups specifies the additional groups for the user
154+
// +optional
155+
Groups *string `json:"groups,omitempty"`
156+
157+
// HomeDir specifies the home directory to use for the user
158+
// +optional
159+
HomeDir *string `json:"homeDir,omitempty"`
160+
161+
// Inactive specifies whether to mark the user as inactive
162+
// +optional
163+
Inactive *bool `json:"inactive,omitempty"`
164+
165+
// Shell specifies the user's shell
166+
// +optional
167+
Shell *string `json:"shell,omitempty"`
168+
169+
// Passwd specifies a hashed password for the user
170+
// +optional
171+
Passwd *string `json:"passwd"`
172+
173+
// PrimaryGroup specifies the primary group for the user
174+
// +optional
175+
PrimaryGroup *string `json:"primaryGroup,omitempty"`
176+
177+
// LockPassword specifies if password login should be disabled
178+
// +optional
179+
LockPassword *bool `json:"lockPassword,omitempty"`
180+
181+
// Sudo specifies a sudo role for the user
182+
// +optional
183+
Sudo *string `json:"sudo,omitempty"`
184+
185+
// SSHAuthorizedKeys specifies a list of ssh authorized keys for the user
186+
// +optional
187+
SSHAuthorizedKeys []string `json:"sshAuthorizedKeys,omitempty"`
188+
}
189+
190+
// NTP defines input for generated ntp in cloud-init
191+
type NTP struct {
192+
// Servers specifies which NTP servers to use
193+
// +optional
194+
Servers []string `json:"servers,omitempty"`
195+
196+
// Enabled specifies whether NTP should be enabled
197+
// +optional
198+
Enabled *bool `json:"enabled,omitempty"`
199+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
Copyright 2019 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 v1alpha3
18+
19+
import (
20+
. "github.com/onsi/ginkgo"
21+
. "github.com/onsi/gomega"
22+
"golang.org/x/net/context"
23+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24+
"k8s.io/apimachinery/pkg/types"
25+
)
26+
27+
// These tests are written in BDD-style using Ginkgo framework. Refer to
28+
// http://onsi.github.io/ginkgo to learn more.
29+
30+
var _ = Describe("KubeadmConfig", func() {
31+
var (
32+
key types.NamespacedName
33+
created, fetched *KubeadmConfig
34+
)
35+
36+
BeforeEach(func() {
37+
// Add any setup steps that needs to be executed before each test
38+
})
39+
40+
AfterEach(func() {
41+
// Add any teardown steps that needs to be executed after each test
42+
})
43+
44+
// Add Tests for OpenAPI validation (or additional CRD features) specified in
45+
// your API definition.
46+
// Avoid adding tests for vanilla CRUD operations because they would
47+
// test Kubernetes API server, which isn't the goal here.
48+
Context("Create API", func() {
49+
50+
It("should create an object successfully", func() {
51+
52+
key = types.NamespacedName{
53+
Name: "foo",
54+
Namespace: "default",
55+
}
56+
created = &KubeadmConfig{
57+
ObjectMeta: metav1.ObjectMeta{
58+
Name: "foo",
59+
Namespace: "default",
60+
},
61+
}
62+
63+
By("creating an API obj")
64+
Expect(k8sClient.Create(context.TODO(), created)).To(Succeed())
65+
66+
fetched = &KubeadmConfig{}
67+
Expect(k8sClient.Get(context.TODO(), key, fetched)).To(Succeed())
68+
Expect(fetched).To(Equal(created))
69+
70+
By("deleting the created object")
71+
Expect(k8sClient.Delete(context.TODO(), created)).To(Succeed())
72+
Expect(k8sClient.Get(context.TODO(), key, created)).ToNot(Succeed())
73+
})
74+
75+
})
76+
77+
})

0 commit comments

Comments
 (0)