Skip to content

Commit c29fe33

Browse files
aamoyelAlan Amoyel
authored andcommitted
feat: add ClusterClass support
1 parent b3c2554 commit c29fe33

File tree

8 files changed

+476
-2
lines changed

8 files changed

+476
-2
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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 v1alpha1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
22+
)
23+
24+
// KubevirtClusterTemplateResource describes the data needed to create a KubevirtCluster from a template.
25+
type KubevirtClusterTemplateResource struct {
26+
ObjectMeta clusterv1.ObjectMeta `json:"metadata,omitempty"`
27+
Spec KubevirtClusterSpec `json:"spec"`
28+
}
29+
30+
// KubevirtClusterTemplateSpec defines the desired state of KubevirtClusterTemplate.
31+
type KubevirtClusterTemplateSpec struct {
32+
Template KubevirtClusterTemplateResource `json:"template"`
33+
}
34+
35+
// +kubebuilder:object:root=true
36+
// +kubebuilder:resource:path=kubevirtclustertemplates,scope=Namespaced,categories=cluster-api,shortName=kct
37+
38+
// KubevirtClusterTemplate is the Schema for the kubevirtclustertemplates API.
39+
type KubevirtClusterTemplate struct {
40+
metav1.TypeMeta `json:",inline"`
41+
metav1.ObjectMeta `json:"metadata,omitempty"`
42+
43+
Spec KubevirtClusterTemplateSpec `json:"spec,omitempty"`
44+
}
45+
46+
// +kubebuilder:object:root=true
47+
48+
// KubevirtClusterTemplateList contains a list of KubevirtClusterTemplates.
49+
type KubevirtClusterTemplateList struct {
50+
metav1.TypeMeta `json:",inline"`
51+
metav1.ListMeta `json:"metadata,omitempty"`
52+
Items []KubevirtClusterTemplate `json:"items"`
53+
}
54+
55+
func init() {
56+
SchemeBuilder.Register(&KubevirtClusterTemplate{}, &KubevirtClusterTemplateList{})
57+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
Copyright 2023 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 v1alpha1
18+
19+
import (
20+
"errors"
21+
"reflect"
22+
23+
"k8s.io/apimachinery/pkg/runtime"
24+
ctrl "sigs.k8s.io/controller-runtime"
25+
"sigs.k8s.io/controller-runtime/pkg/webhook"
26+
)
27+
28+
const kubevirtClusterTemplateImmutableMsg = "KubevirtClusterTemplate spec.template.spec field is immutable. Please create new resource instead."
29+
30+
func (m *KubevirtClusterTemplate) SetupWebhookWithManager(mgr ctrl.Manager) error {
31+
return ctrl.NewWebhookManagedBy(mgr).
32+
For(m).
33+
Complete()
34+
}
35+
36+
// +kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1alpha1-kubevirtclustertemplate,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=kubevirtclustertemplates,versions=v1alpha1,name=validation.kubevirtclustertemplate.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1beta1
37+
38+
var _ webhook.Validator = &KubevirtClusterTemplate{}
39+
40+
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
41+
func (m *KubevirtClusterTemplate) ValidateCreate() error {
42+
return nil
43+
}
44+
45+
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
46+
func (m *KubevirtClusterTemplate) ValidateUpdate(old runtime.Object) error {
47+
oldCRS := old.(*KubevirtClusterTemplate)
48+
if !reflect.DeepEqual(m.Spec, oldCRS.Spec) {
49+
return errors.New(kubevirtClusterTemplateImmutableMsg)
50+
}
51+
return nil
52+
}
53+
54+
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
55+
func (m *KubevirtClusterTemplate) ValidateDelete() error {
56+
return nil
57+
}

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 91 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)