Skip to content

Commit 90001cf

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

12 files changed

+544
-19
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+
version: v1alpha4
25+
kind: DockerClusterTemplate
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
apierrors "k8s.io/apimachinery/pkg/api/errors"
21+
"k8s.io/apimachinery/pkg/runtime"
22+
"k8s.io/apimachinery/pkg/util/validation/field"
23+
ctrl "sigs.k8s.io/controller-runtime"
24+
"sigs.k8s.io/controller-runtime/pkg/webhook"
25+
)
26+
27+
func (c *DockerCluster) SetupWebhookWithManager(mgr ctrl.Manager) error {
28+
return ctrl.NewWebhookManagedBy(mgr).
29+
For(c).
30+
Complete()
31+
}
32+
33+
// +kubebuilder:webhook:verbs=create;update,path=/mutate-infrastructure-cluster-x-k8s-io-v1alpha4-dockercluster,mutating=true,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=dockerclusters,versions=v1alpha4,name=default.dockercluster.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1beta1
34+
35+
var _ webhook.Defaulter = &DockerCluster{}
36+
37+
// Default implements webhook.Defaulter so a webhook will be registered for the type.
38+
func (c *DockerCluster) Default() {
39+
defaultDockerClusterSpec(&c.Spec)
40+
}
41+
42+
// +kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1alpha4-dockercluster,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=dockerclusters,versions=v1alpha4,name=validation.dockercluster.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1beta1
43+
44+
var _ webhook.Validator = &DockerCluster{}
45+
46+
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
47+
func (c *DockerCluster) ValidateCreate() error {
48+
allErrs := validateDockerClusterSpec(c.Spec)
49+
if len(allErrs) > 0 {
50+
return apierrors.NewInvalid(GroupVersion.WithKind("DockerCluster").GroupKind(), c.Name, allErrs)
51+
}
52+
return nil
53+
}
54+
55+
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
56+
func (c *DockerCluster) ValidateUpdate(old runtime.Object) error {
57+
return nil
58+
}
59+
60+
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
61+
func (c *DockerCluster) ValidateDelete() error {
62+
return nil
63+
}
64+
65+
func defaultDockerClusterSpec(s *DockerClusterSpec) {}
66+
67+
func validateDockerClusterSpec(s DockerClusterSpec) field.ErrorList {
68+
return nil
69+
}
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
"errors"
21+
"reflect"
22+
23+
apierrors "k8s.io/apimachinery/pkg/api/errors"
24+
"k8s.io/apimachinery/pkg/runtime"
25+
ctrl "sigs.k8s.io/controller-runtime"
26+
"sigs.k8s.io/controller-runtime/pkg/webhook"
27+
)
28+
29+
func (r *DockerClusterTemplate) SetupWebhookWithManager(mgr ctrl.Manager) error {
30+
return ctrl.NewWebhookManagedBy(mgr).
31+
For(r).
32+
Complete()
33+
}
34+
35+
// +kubebuilder:webhook:verbs=create;update,path=/mutate-infrastructure-cluster-x-k8s-io-v1alpha4-dockerclustertemplate,mutating=true,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=dockerclustertemplates,versions=v1alpha4,name=default.dockerclustertemplate.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1beta1
36+
37+
var _ webhook.Defaulter = &DockerClusterTemplate{}
38+
39+
// Default implements webhook.Defaulter so a webhook will be registered for the type.
40+
func (r *DockerClusterTemplate) Default() {
41+
defaultDockerClusterSpec(&r.Spec.Template.Spec)
42+
}
43+
44+
// +kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1alpha4-dockerclustertemplate,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=dockerclustertemplates,versions=v1alpha4,name=validation.dockerclustertemplate.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1beta1
45+
46+
var _ webhook.Validator = &DockerClusterTemplate{}
47+
48+
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
49+
func (r *DockerClusterTemplate) ValidateCreate() error {
50+
allErrs := validateDockerClusterSpec(r.Spec.Template.Spec)
51+
if len(allErrs) > 0 {
52+
return apierrors.NewInvalid(GroupVersion.WithKind("DockerClusterTemplate").GroupKind(), r.Name, allErrs)
53+
}
54+
return nil
55+
}
56+
57+
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
58+
func (r *DockerClusterTemplate) ValidateUpdate(oldRaw runtime.Object) error {
59+
old := oldRaw.(*DockerClusterTemplate)
60+
if !reflect.DeepEqual(r.Spec, old.Spec) {
61+
return errors.New("DockerClusterTemplateSpec is immutable")
62+
}
63+
return nil
64+
}
65+
66+
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
67+
func (r *DockerClusterTemplate) ValidateDelete() error {
68+
return nil
69+
}

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.

0 commit comments

Comments
 (0)