Skip to content

Commit

Permalink
Merge pull request #8807 from ykakarap/pr-inmemory-provider-clusterclass
Browse files Browse the repository at this point in the history
🌱 add ClusterClass support for in-memory provider
  • Loading branch information
k8s-ci-robot authored Jun 13, 2023
2 parents b47b77b + 87c4ee6 commit 238ca15
Show file tree
Hide file tree
Showing 11 changed files with 507 additions and 126 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
Copyright 2023 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

// InMemoryClusterTemplateSpec defines the desired state of InMemoryClusterTemplate.
type InMemoryClusterTemplateSpec struct {
Template InMemoryClusterTemplateResource `json:"template"`
}

// +kubebuilder:resource:path=inmemoryclustertemplates,scope=Namespaced,categories=cluster-api
// +kubebuilder:object:root=true
// +kubebuilder:storageversion
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time duration since creation of InMemoryClusterTemplate"

// InMemoryClusterTemplate is the Schema for the inmemoryclustertemplates API.
type InMemoryClusterTemplate struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec InMemoryClusterTemplateSpec `json:"spec,omitempty"`
}

// +kubebuilder:object:root=true

// InMemoryClusterTemplateList contains a list of InMemoryClusterTemplate.
type InMemoryClusterTemplateList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []InMemoryClusterTemplate `json:"items"`
}

func init() {
SchemeBuilder.Register(&InMemoryClusterTemplate{}, &InMemoryClusterTemplateList{})
}

// InMemoryClusterTemplateResource describes the data needed to create a InMemoryCluster from a template.
type InMemoryClusterTemplateResource struct {
// Standard object's metadata.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
// +optional
ObjectMeta clusterv1.ObjectMeta `json:"metadata,omitempty"`
Spec InMemoryClusterSpec `json:"spec"`
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
Copyright 2023 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

func (c *InMemoryClusterTemplate) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
For(c).
Complete()
}

// +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

var _ webhook.Defaulter = &InMemoryClusterTemplate{}

// Default implements webhook.Defaulter so a webhook will be registered for the type.
func (c *InMemoryClusterTemplate) Default() {

}

// +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

var _ webhook.Validator = &InMemoryClusterTemplate{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (c *InMemoryClusterTemplate) ValidateCreate() (admission.Warnings, error) {
return nil, nil
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (c *InMemoryClusterTemplate) ValidateUpdate(_ runtime.Object) (admission.Warnings, error) {
return nil, nil
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (c *InMemoryClusterTemplate) ValidateDelete() (admission.Warnings, error) {
return nil, nil
}
91 changes: 91 additions & 0 deletions test/infrastructure/inmemory/api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test/infrastructure/inmemory/config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- bases/infrastructure.cluster.x-k8s.io_inmemoryclusters.yaml
- bases/infrastructure.cluster.x-k8s.io_inmemoryclustertemplates.yaml
- bases/infrastructure.cluster.x-k8s.io_inmemorymachines.yaml
- bases/infrastructure.cluster.x-k8s.io_inmemorymachinetemplates.yaml
# +kubebuilder:scaffold:crdkustomizeresource
Expand All @@ -16,12 +17,14 @@ patchesStrategicMerge:
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
# patches here are for enabling the conversion webhook for each CRD
- patches/webhook_in_inmemoryclusters.yaml
- patches/webhook_in_inmemoryclustertemplates.yaml
- patches/webhook_in_inmemorymachines.yaml
- patches/webhook_in_inmemorymachinetemplates.yaml
# +kubebuilder:scaffold:crdkustomizewebhookpatch
# [CERTMANAGER] To enable webhook, uncomment all the sections with [CERTMANAGER] prefix.
# patches here are for enabling the CA injection for each CRD
- patches/cainjection_in_inmemoryclusters.yaml
- patches/cainjection_in_inmemoryclustertemplates.yaml
- patches/cainjection_in_inmemorymachines.yaml
- patches/cainjection_in_inmemorymachinetemplates.yaml
# +kubebuilder:scaffold:crdkustomizecainjectionpatch
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# The following patch adds a directive for certmanager to inject CA into the CRD
# CRD conversion requires k8s 1.13 or later.
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
name: inmemoryclustertemplates.infrastructure.cluster.x-k8s.io
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# The following patch enables conversion webhook for CRD
# CRD conversion requires k8s 1.13 or later.
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: inmemoryclustertemplates.infrastructure.cluster.x-k8s.io
spec:
conversion:
strategy: Webhook
webhook:
conversionReviewVersions: ["v1", "v1beta1"]
clientConfig:
# this is "\n" used as a placeholder, otherwise it will be rejected by the apiserver for being blank,
# but we're going to set it later using the cert-manager (or potentially a patch if not using cert-manager)
caBundle: Cg==
service:
namespace: system
name: webhook-service
path: /convert
Loading

0 comments on commit 238ca15

Please sign in to comment.