Skip to content
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

Bump CAPI to v1.5.2 #176

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions bootstrap/api/v1alpha1/rke2config_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
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"
)

var (
Expand Down Expand Up @@ -62,38 +63,38 @@ func DefaultRKE2ConfigSpec(spec *RKE2ConfigSpec) {
var _ webhook.Validator = &RKE2Config{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (r *RKE2Config) ValidateCreate() error {
func (r *RKE2Config) ValidateCreate() (admission.Warnings, error) {
rke2configlog.Info("RKE2Config validate create", "rke2config", klog.KObj(r))

var allErrs field.ErrorList

allErrs = append(allErrs, ValidateRKE2ConfigSpec(r.Name, &r.Spec)...)

if len(allErrs) == 0 {
return nil
return nil, nil
}

return apierrors.NewInvalid(GroupVersion.WithKind("RKE2Config").GroupKind(), r.Name, allErrs)
return nil, apierrors.NewInvalid(GroupVersion.WithKind("RKE2Config").GroupKind(), r.Name, allErrs)
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (r *RKE2Config) ValidateUpdate(_ runtime.Object) error {
func (r *RKE2Config) ValidateUpdate(_ runtime.Object) (admission.Warnings, error) {
rke2configlog.Info("RKE2Config validate update", "rke2config", klog.KObj(r))

var allErrs field.ErrorList

allErrs = append(allErrs, ValidateRKE2ConfigSpec(r.Name, &r.Spec)...)

if len(allErrs) == 0 {
return nil
return nil, nil
}

return apierrors.NewInvalid(GroupVersion.WithKind("RKE2Config").GroupKind(), r.Name, allErrs)
return nil, apierrors.NewInvalid(GroupVersion.WithKind("RKE2Config").GroupKind(), r.Name, allErrs)
}

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

// ValidateRKE2ConfigSpec validates the RKE2ConfigSpec.
Expand Down
13 changes: 7 additions & 6 deletions bootstrap/api/v1alpha1/rke2configtemplate_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
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"
)

// RKE2configtemplatelog is for logging in this package.
Expand All @@ -47,22 +48,22 @@ func (r *RKE2ConfigTemplate) Default() {
var _ webhook.Validator = &RKE2ConfigTemplate{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (r *RKE2ConfigTemplate) ValidateCreate() error {
func (r *RKE2ConfigTemplate) ValidateCreate() (admission.Warnings, error) {
RKE2configtemplatelog.Info("validate create", "name", r.Name)

return nil
return nil, nil
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (r *RKE2ConfigTemplate) ValidateUpdate(old runtime.Object) error {
func (r *RKE2ConfigTemplate) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
RKE2configtemplatelog.Info("validate update", "name", r.Name)

return nil
return nil, nil
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (r *RKE2ConfigTemplate) ValidateDelete() error {
func (r *RKE2ConfigTemplate) ValidateDelete() (admission.Warnings, error) {
RKE2configtemplatelog.Info("validate delete", "name", r.Name)

return nil
return nil, nil
}
19 changes: 10 additions & 9 deletions controlplane/api/v1alpha1/rke2controlplane_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
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"

bootstrapv1 "github.com/rancher-sandbox/cluster-api-provider-rke2/bootstrap/api/v1alpha1"
)
Expand Down Expand Up @@ -54,7 +55,7 @@ func (r *RKE2ControlPlane) Default() {
var _ webhook.Validator = &RKE2ControlPlane{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (r *RKE2ControlPlane) ValidateCreate() error {
func (r *RKE2ControlPlane) ValidateCreate() (admission.Warnings, error) {
rke2controlplanelog.Info("RKE2ControlPlane validate create", "control-plane", klog.KObj(r))

var allErrs field.ErrorList
Expand All @@ -64,17 +65,17 @@ func (r *RKE2ControlPlane) ValidateCreate() error {
allErrs = append(allErrs, r.validateRegistrationMethod()...)

if len(allErrs) == 0 {
return nil
return nil, nil
}

return apierrors.NewInvalid(GroupVersion.WithKind("RKE2ControlPlane").GroupKind(), r.Name, allErrs)
return nil, apierrors.NewInvalid(GroupVersion.WithKind("RKE2ControlPlane").GroupKind(), r.Name, allErrs)
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (r *RKE2ControlPlane) ValidateUpdate(old runtime.Object) error {
func (r *RKE2ControlPlane) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
oldControlplane, ok := old.(*RKE2ControlPlane)
if !ok {
return apierrors.NewInvalid(GroupVersion.WithKind("RKE2ControlPlane").GroupKind(), r.Name, field.ErrorList{
return nil, apierrors.NewInvalid(GroupVersion.WithKind("RKE2ControlPlane").GroupKind(), r.Name, field.ErrorList{
field.InternalError(nil, errors.New("failed to convert old RKE2ControlPlane to object")),
})
}
Expand All @@ -91,17 +92,17 @@ func (r *RKE2ControlPlane) ValidateUpdate(old runtime.Object) error {
}

if len(allErrs) == 0 {
return nil
return nil, nil
}

return apierrors.NewInvalid(GroupVersion.WithKind("RKE2ControlPlane").GroupKind(), r.Name, allErrs)
return nil, apierrors.NewInvalid(GroupVersion.WithKind("RKE2ControlPlane").GroupKind(), r.Name, allErrs)
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (r *RKE2ControlPlane) ValidateDelete() error {
func (r *RKE2ControlPlane) ValidateDelete() (admission.Warnings, error) {
rke2controlplanelog.Info("validate delete", "name", r.Name)

return nil
return nil, nil
}

func (r *RKE2ControlPlane) validateCNI() field.ErrorList {
Expand Down
13 changes: 7 additions & 6 deletions controlplane/api/v1alpha1/rke2controlplanetemplate_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
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.
Expand All @@ -47,22 +48,22 @@ func (r *RKE2ControlPlaneTemplate) Default() {
var _ webhook.Validator = &RKE2ControlPlaneTemplate{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (r *RKE2ControlPlaneTemplate) ValidateCreate() error {
func (r *RKE2ControlPlaneTemplate) ValidateCreate() (admission.Warnings, error) {
rke2controlplanetemplatelog.Info("validate create", "name", r.Name)

return nil
return nil, nil
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (r *RKE2ControlPlaneTemplate) ValidateUpdate(old runtime.Object) error {
func (r *RKE2ControlPlaneTemplate) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
rke2controlplanetemplatelog.Info("validate update", "name", r.Name)

return nil
return nil, nil
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (r *RKE2ControlPlaneTemplate) ValidateDelete() error {
func (r *RKE2ControlPlaneTemplate) ValidateDelete() (admission.Warnings, error) {
rke2controlplanetemplatelog.Info("validate delete", "name", r.Name)

return nil
return nil, nil
}
32 changes: 18 additions & 14 deletions controlplane/internal/controllers/rke2controlplane_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func patchRKE2ControlPlane(ctx context.Context, patchHelper *patch.Helper, rcp *
}

// SetupWithManager sets up the controller with the Manager.
func (r *RKE2ControlPlaneReconciler) SetupWithManager(mgr ctrl.Manager) error {
func (r *RKE2ControlPlaneReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager) error {
c, err := ctrl.NewControllerManagedBy(mgr).
For(&controlplanev1.RKE2ControlPlane{}).
Build(r)
Expand All @@ -223,8 +223,8 @@ func (r *RKE2ControlPlaneReconciler) SetupWithManager(mgr ctrl.Manager) error {
}

err = c.Watch(
&source.Kind{Type: &clusterv1.Cluster{}},
handler.EnqueueRequestsFromMapFunc(r.ClusterToRKE2ControlPlane),
source.Kind(mgr.GetCache(), &clusterv1.Cluster{}),
handler.EnqueueRequestsFromMapFunc(r.ClusterToRKE2ControlPlane(ctx)),
)
if err != nil {
return errors.Wrap(err, "failed adding Watch for Clusters to controller manager")
Expand Down Expand Up @@ -736,18 +736,22 @@ func (r *RKE2ControlPlaneReconciler) upgradeControlPlane(

// ClusterToRKE2ControlPlane is a handler.ToRequestsFunc to be used to enqueue requests for reconciliation
// for RKE2ControlPlane based on updates to a Cluster.
func (r *RKE2ControlPlaneReconciler) ClusterToRKE2ControlPlane(o client.Object) []ctrl.Request {
c, ok := o.(*clusterv1.Cluster)
if !ok {
r.Log.Error(nil, fmt.Sprintf("Expected a Cluster but got a %T", o))
func (r *RKE2ControlPlaneReconciler) ClusterToRKE2ControlPlane(ctx context.Context) handler.MapFunc {
log := log.FromContext(ctx)

return nil
}
return func(_ context.Context, o client.Object) []ctrl.Request {
c, ok := o.(*clusterv1.Cluster)
if !ok {
log.Error(nil, fmt.Sprintf("Expected a Cluster but got a %T", o))

controlPlaneRef := c.Spec.ControlPlaneRef
if controlPlaneRef != nil && controlPlaneRef.Kind == "RKE2ControlPlane" {
return []ctrl.Request{{NamespacedName: client.ObjectKey{Namespace: controlPlaneRef.Namespace, Name: controlPlaneRef.Name}}}
}
return nil
}

return nil
controlPlaneRef := c.Spec.ControlPlaneRef
if controlPlaneRef != nil && controlPlaneRef.Kind == "RKE2ControlPlane" {
return []ctrl.Request{{NamespacedName: client.ObjectKey{Namespace: controlPlaneRef.Namespace, Name: controlPlaneRef.Name}}}
}

return nil
}
}
11 changes: 7 additions & 4 deletions controlplane/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package main

import (
"context"
"flag"
"fmt"
"net/http"
Expand Down Expand Up @@ -149,14 +150,16 @@ func main() {
os.Exit(1)
}

ctx := ctrl.SetupSignalHandler()

setupChecks(mgr)
setupReconcilers(mgr)
setupReconcilers(ctx, mgr)
setupWebhooks(mgr)
//+kubebuilder:scaffold:builder

setupLog.Info("starting manager")

if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
if err := mgr.Start(ctx); err != nil {
setupLog.Error(err, "problem running manager")
os.Exit(1)
}
Expand All @@ -182,11 +185,11 @@ func setupChecks(mgr ctrl.Manager) {
}
}

func setupReconcilers(mgr ctrl.Manager) {
func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {
if err := (&controllers.RKE2ControlPlaneReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
}).SetupWithManager(ctx, mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "RKE2ControlPlane")
os.Exit(1)
}
Expand Down
Loading
Loading