-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🌱 Support for ClusterClass template #1405
Merged
metal3-io-bot
merged 2 commits into
metal3-io:main
from
p-strusiewiczsurmacki-mobica:clusterclass-support
Apr 30, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
Copyright 2024 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 v1beta1 | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// Metal3ClusterTemplateSpec defines the desired state of Metal3ClusterTemplate. | ||
type Metal3ClusterTemplateSpec struct { | ||
Template Metal3ClusterTemplateResource `json:"template"` | ||
} | ||
|
||
// +kubebuilder:object:root=true | ||
// +kubebuilder:resource:path=metal3clustertemplates,scope=Namespaced,categories=cluster-api,shortName=m3ct | ||
// +kubebuilder:storageversion | ||
|
||
// Metal3ClusterTemplate is the Schema for the metal3clustertemplates API. | ||
type Metal3ClusterTemplate struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec Metal3ClusterTemplateSpec `json:"spec,omitempty"` | ||
} | ||
|
||
// +kubebuilder:object:root=true | ||
|
||
// Metal3ClusterTemplateList contains a list of Metal3ClusterTemplate. | ||
type Metal3ClusterTemplateList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []Metal3ClusterTemplate `json:"items"` | ||
} | ||
|
||
func init() { | ||
objectTypes = append(objectTypes, &Metal3ClusterTemplate{}, &Metal3ClusterTemplateList{}) | ||
} | ||
|
||
// Metal3ClusterTemplateResource describes the data for creating a Metal3Cluster from a template. | ||
type Metal3ClusterTemplateResource struct { | ||
Spec Metal3ClusterSpec `json:"spec"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
Copyright 2024 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 v1beta1 | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
"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" | ||
) | ||
|
||
// SetupWebhookWithManager sets up and registers the webhook with the manager. | ||
func (c *Metal3ClusterTemplate) SetupWebhookWithManager(mgr ctrl.Manager) error { | ||
p-strusiewiczsurmacki-mobica marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return ctrl.NewWebhookManagedBy(mgr). | ||
For(c). | ||
Complete() | ||
} | ||
|
||
// +kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta1-metal3clustertemplate,mutating=false,failurePolicy=fail,groups=infrastructure.cluster.x-k8s.io,resources=metal3clustertemplates,versions=v1beta1,name=validation.metal3clustertemplate.infrastructure.cluster.x-k8s.io,matchPolicy=Equivalent,sideEffects=None,admissionReviewVersions=v1;v1beta1 | ||
// +kubebuilder:webhook:verbs=create;update,path=/mutate-infrastructure-cluster-x-k8s-io-v1beta1-metal3clustertemplate,mutating=true,failurePolicy=fail,groups=infrastructure.cluster.x-k8s.io,resources=metal3clustertemplates,versions=v1beta1,name=default.metal3clustertemplate.infrastructure.cluster.x-k8s.io,matchPolicy=Equivalent,sideEffects=None,admissionReviewVersions=v1;v1beta1 | ||
|
||
var _ webhook.Defaulter = &Metal3ClusterTemplate{} | ||
var _ webhook.Validator = &Metal3ClusterTemplate{} | ||
|
||
func (c *Metal3ClusterTemplate) Default() { | ||
} | ||
|
||
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type. | ||
func (c *Metal3ClusterTemplate) ValidateCreate() (admission.Warnings, error) { | ||
return nil, c.validate() | ||
} | ||
|
||
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type. | ||
func (c *Metal3ClusterTemplate) ValidateUpdate(old runtime.Object) (admission.Warnings, error) { | ||
oldM3ct, ok := old.(*Metal3ClusterTemplate) | ||
if !ok || oldM3ct == nil { | ||
return nil, apierrors.NewInternalError(errors.New("unable to convert existing object")) | ||
} | ||
|
||
if err := oldM3ct.Spec.Template.Spec.IsValid(); err != nil { | ||
return nil, err | ||
} | ||
|
||
return nil, c.validate() | ||
} | ||
|
||
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type. | ||
func (c *Metal3ClusterTemplate) ValidateDelete() (admission.Warnings, error) { | ||
return nil, nil | ||
} | ||
|
||
func (c *Metal3ClusterTemplate) validate() error { | ||
return c.Spec.Template.Spec.IsValid() | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line is redundant because it is included already in
clusterclass-templates
Makefile target?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@p-strusiewiczsurmacki-mobica hey, will you have a time to address this comment soon? We can then try to run CI tests on this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@furkatgofurov7 Sorry, I've had to omit the notification email for this comment, and I've only seen it now.
I think that this should stay here.
clusterclass-templates
will not be used if non-clusterclass e2e test is being run, andclusterclass.yaml
file is required by e2e config. If it will not exist, the test will fail.I had no better idea on how to fix that, but to create empty
clusterclass.yaml
file.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah right, now I got the point. Ideally, we could test the feature (simple cluster creation/destroy using CC would have been enough) as part of the current e2e tests setup, instead of having a separate Makefile target which is not part of it right now.
@lentzi90 WDYT of the current approach?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can live with it, but I agree that making it part of the current e2e tests would be preferable. Enabling cluster class support in the controllers should be fine for all tests. They will anyway not use a ClusterClass unless defined in the test 🙂