Skip to content

Commit 238ca15

Browse files
authored
Merge pull request #8807 from ykakarap/pr-inmemory-provider-clusterclass
🌱 add ClusterClass support for in-memory provider
2 parents b47b77b + 87c4ee6 commit 238ca15

11 files changed

+507
-126
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
22+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
23+
)
24+
25+
// InMemoryClusterTemplateSpec defines the desired state of InMemoryClusterTemplate.
26+
type InMemoryClusterTemplateSpec struct {
27+
Template InMemoryClusterTemplateResource `json:"template"`
28+
}
29+
30+
// +kubebuilder:resource:path=inmemoryclustertemplates,scope=Namespaced,categories=cluster-api
31+
// +kubebuilder:object:root=true
32+
// +kubebuilder:storageversion
33+
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time duration since creation of InMemoryClusterTemplate"
34+
35+
// InMemoryClusterTemplate is the Schema for the inmemoryclustertemplates API.
36+
type InMemoryClusterTemplate struct {
37+
metav1.TypeMeta `json:",inline"`
38+
metav1.ObjectMeta `json:"metadata,omitempty"`
39+
40+
Spec InMemoryClusterTemplateSpec `json:"spec,omitempty"`
41+
}
42+
43+
// +kubebuilder:object:root=true
44+
45+
// InMemoryClusterTemplateList contains a list of InMemoryClusterTemplate.
46+
type InMemoryClusterTemplateList struct {
47+
metav1.TypeMeta `json:",inline"`
48+
metav1.ListMeta `json:"metadata,omitempty"`
49+
Items []InMemoryClusterTemplate `json:"items"`
50+
}
51+
52+
func init() {
53+
SchemeBuilder.Register(&InMemoryClusterTemplate{}, &InMemoryClusterTemplateList{})
54+
}
55+
56+
// InMemoryClusterTemplateResource describes the data needed to create a InMemoryCluster from a template.
57+
type InMemoryClusterTemplateResource struct {
58+
// Standard object's metadata.
59+
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
60+
// +optional
61+
ObjectMeta clusterv1.ObjectMeta `json:"metadata,omitempty"`
62+
Spec InMemoryClusterSpec `json:"spec"`
63+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
"k8s.io/apimachinery/pkg/runtime"
21+
ctrl "sigs.k8s.io/controller-runtime"
22+
"sigs.k8s.io/controller-runtime/pkg/webhook"
23+
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
24+
)
25+
26+
func (c *InMemoryClusterTemplate) SetupWebhookWithManager(mgr ctrl.Manager) error {
27+
return ctrl.NewWebhookManagedBy(mgr).
28+
For(c).
29+
Complete()
30+
}
31+
32+
// +kubebuilder:webhook:verbs=create;update,path=/mutate-infrastructure-cluster-x-k8s-io-v1alpha1-inmemoryclustertemplate,mutating=true,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=inmemoryclustertemplates,versions=v1alpha1,name=default.inmemoryclustertemplate.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
33+
34+
var _ webhook.Defaulter = &InMemoryClusterTemplate{}
35+
36+
// Default implements webhook.Defaulter so a webhook will be registered for the type.
37+
func (c *InMemoryClusterTemplate) Default() {
38+
39+
}
40+
41+
// +kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1alpha1-inmemoryclustertemplate,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=inmemoryclustertemplates,versions=v1alpha1,name=validation.inmemoryclustertemplate.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
42+
43+
var _ webhook.Validator = &InMemoryClusterTemplate{}
44+
45+
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
46+
func (c *InMemoryClusterTemplate) ValidateCreate() (admission.Warnings, error) {
47+
return nil, nil
48+
}
49+
50+
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
51+
func (c *InMemoryClusterTemplate) ValidateUpdate(_ runtime.Object) (admission.Warnings, error) {
52+
return nil, nil
53+
}
54+
55+
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
56+
func (c *InMemoryClusterTemplate) ValidateDelete() (admission.Warnings, error) {
57+
return nil, nil
58+
}

test/infrastructure/inmemory/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.

test/infrastructure/inmemory/config/crd/bases/infrastructure.cluster.x-k8s.io_inmemoryclustertemplates.yaml

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

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ apiVersion: kustomize.config.k8s.io/v1beta1
88
kind: Kustomization
99
resources:
1010
- bases/infrastructure.cluster.x-k8s.io_inmemoryclusters.yaml
11+
- bases/infrastructure.cluster.x-k8s.io_inmemoryclustertemplates.yaml
1112
- bases/infrastructure.cluster.x-k8s.io_inmemorymachines.yaml
1213
- bases/infrastructure.cluster.x-k8s.io_inmemorymachinetemplates.yaml
1314
# +kubebuilder:scaffold:crdkustomizeresource
@@ -16,12 +17,14 @@ patchesStrategicMerge:
1617
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
1718
# patches here are for enabling the conversion webhook for each CRD
1819
- patches/webhook_in_inmemoryclusters.yaml
20+
- patches/webhook_in_inmemoryclustertemplates.yaml
1921
- patches/webhook_in_inmemorymachines.yaml
2022
- patches/webhook_in_inmemorymachinetemplates.yaml
2123
# +kubebuilder:scaffold:crdkustomizewebhookpatch
2224
# [CERTMANAGER] To enable webhook, uncomment all the sections with [CERTMANAGER] prefix.
2325
# patches here are for enabling the CA injection for each CRD
2426
- patches/cainjection_in_inmemoryclusters.yaml
27+
- patches/cainjection_in_inmemoryclustertemplates.yaml
2528
- patches/cainjection_in_inmemorymachines.yaml
2629
- patches/cainjection_in_inmemorymachinetemplates.yaml
2730
# +kubebuilder:scaffold:crdkustomizecainjectionpatch
Lines changed: 8 additions & 0 deletions
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/v1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
annotations:
7+
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
8+
name: inmemoryclustertemplates.infrastructure.cluster.x-k8s.io
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# The following patch enables conversion webhook for CRD
2+
# CRD conversion requires k8s 1.13 or later.
3+
apiVersion: apiextensions.k8s.io/v1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
name: inmemoryclustertemplates.infrastructure.cluster.x-k8s.io
7+
spec:
8+
conversion:
9+
strategy: Webhook
10+
webhook:
11+
conversionReviewVersions: ["v1", "v1beta1"]
12+
clientConfig:
13+
# this is "\n" used as a placeholder, otherwise it will be rejected by the apiserver for being blank,
14+
# but we're going to set it later using the cert-manager (or potentially a patch if not using cert-manager)
15+
caBundle: Cg==
16+
service:
17+
namespace: system
18+
name: webhook-service
19+
path: /convert

0 commit comments

Comments
 (0)