-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: use a MachineImageTemplate object (#39)
- Loading branch information
Showing
19 changed files
with
8,959 additions
and
8,377 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Copyright 2023 Dimitri Koshkin. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
/* | ||
Copyright 2023. | ||
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 ( | ||
"fmt" | ||
|
||
"k8s.io/apimachinery/pkg/runtime" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
logf "sigs.k8s.io/controller-runtime/pkg/log" | ||
"sigs.k8s.io/controller-runtime/pkg/webhook" | ||
"sigs.k8s.io/controller-runtime/pkg/webhook/admission" | ||
) | ||
|
||
// log is for logging in this package. | ||
// | ||
//nolint:gochecknoglobals // This came from the Kubebuilder project. | ||
var machineimagesyncerlog = logf.Log.WithName("machineimagesyncer-resource") | ||
|
||
func (r *MachineImageSyncer) SetupWebhookWithManager(mgr ctrl.Manager) error { | ||
//nolint:wrapcheck // This came from the Kubebuilder project. | ||
return ctrl.NewWebhookManagedBy(mgr). | ||
For(r). | ||
Complete() | ||
} | ||
|
||
// TODO(user): EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! | ||
//nolint:lll // This is generated code. | ||
//+kubebuilder:webhook:path=/mutate-kubernetesupgraded-dimitrikoshkin-com-v1alpha1-machineimagesyncer,mutating=true,failurePolicy=fail,sideEffects=None,groups=kubernetesupgraded.dimitrikoshkin.com,resources=machineimagesyncers,verbs=create;update,versions=v1alpha1,name=mmachineimagesyncer.kb.io,admissionReviewVersions=v1 | ||
|
||
var _ webhook.Defaulter = &MachineImageSyncer{} | ||
|
||
// Default implements webhook.Defaulter so a webhook will be registered for the type. | ||
func (r *MachineImageSyncer) Default() { | ||
machineimagesyncerlog.Info("default", "name", r.Name) | ||
|
||
if r.Spec.MachineImageTemplateRef.Namespace == "" { | ||
r.Spec.MachineImageTemplateRef.Namespace = r.Namespace | ||
} | ||
} | ||
|
||
// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation. | ||
//nolint:lll // This is generated code. | ||
//+kubebuilder:webhook:path=/validate-kubernetesupgraded-dimitrikoshkin-com-v1alpha1-machineimagesyncer,mutating=false,failurePolicy=fail,sideEffects=None,groups=kubernetesupgraded.dimitrikoshkin.com,resources=machineimagesyncers,verbs=create;update,versions=v1alpha1,name=vmachineimagesyncer.kb.io,admissionReviewVersions=v1 | ||
|
||
var _ webhook.Validator = &MachineImageSyncer{} | ||
|
||
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type. | ||
func (r *MachineImageSyncer) ValidateCreate() (admission.Warnings, error) { | ||
machineimagesyncerlog.Info("validate create", "name", r.Name) | ||
|
||
if r.Spec.MachineImageTemplateRef.Name == "" { | ||
//nolint:goerr113 // This is a user facing error. | ||
return nil, | ||
fmt.Errorf("spec.machineImageTemplateRef.name must be set") | ||
} | ||
|
||
if r.Namespace != r.Spec.MachineImageTemplateRef.Namespace { | ||
//nolint:goerr113 // This is a user facing error. | ||
return nil, | ||
fmt.Errorf("spec.machineImageTemplateRef.namespace must be in the same namespace") | ||
} | ||
return nil, nil | ||
} | ||
|
||
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type. | ||
func (r *MachineImageSyncer) ValidateUpdate(old runtime.Object) (admission.Warnings, error) { | ||
machineimagesyncerlog.Info("validate update", "name", r.Name) | ||
|
||
// TODO(user): fill in your validation logic upon object update. | ||
return nil, nil | ||
} | ||
|
||
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type. | ||
func (r *MachineImageSyncer) ValidateDelete() (admission.Warnings, error) { | ||
machineimagesyncerlog.Info("validate delete", "name", r.Name) | ||
|
||
// TODO(user): fill in your validation logic upon object deletion. | ||
return nil, nil | ||
} |
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,83 @@ | ||
// Copyright 2023 Dimitri Koshkin. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
/* | ||
Copyright 2023. | ||
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" | ||
) | ||
|
||
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! | ||
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. | ||
|
||
// MachineImageTemplateSpec defines the desired state of MachineImageTemplate. | ||
type MachineImageTemplateSpec struct { | ||
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster | ||
// Important: Run "make" to regenerate code after modifying this file | ||
|
||
// Template is the MachineImage template to use when building the image. | ||
// +required | ||
Template MachineImageSyncerResource `json:"template"` | ||
} | ||
|
||
// MachineImageSyncerResource defines the Template structure. | ||
type MachineImageSyncerResource 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 is the MachineImage spec to use when building the image. | ||
// +required | ||
Spec MachineImageSpec `json:"spec"` | ||
} | ||
|
||
// MachineImageTemplateStatus defines the observed state of MachineImageTemplate. | ||
type MachineImageTemplateStatus struct { | ||
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster | ||
// Important: Run "make" to regenerate code after modifying this file | ||
} | ||
|
||
//+kubebuilder:object:root=true | ||
//+kubebuilder:subresource:status | ||
//+kubebuilder:resource:categories=cluster-api | ||
|
||
// MachineImageTemplate is the Schema for the machineimagetemplates API. | ||
type MachineImageTemplate struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec MachineImageTemplateSpec `json:"spec,omitempty"` | ||
Status MachineImageTemplateStatus `json:"status,omitempty"` | ||
} | ||
|
||
//+kubebuilder:object:root=true | ||
|
||
// MachineImageTemplateList contains a list of MachineImageTemplate. | ||
type MachineImageTemplateList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []MachineImageTemplate `json:"items"` | ||
} | ||
|
||
//nolint:gochecknoinits // This is required for the Kubebuilder tooling. | ||
func init() { | ||
SchemeBuilder.Register(&MachineImageTemplate{}, &MachineImageTemplateList{}) | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.