diff --git a/api/v1beta1/machine_webhook.go b/api/v1beta1/machine_webhook.go index a07bf449267e..febaad1ee8ee 100644 --- a/api/v1beta1/machine_webhook.go +++ b/api/v1beta1/machine_webhook.go @@ -44,7 +44,7 @@ func (m *Machine) SetupWebhookWithManager(mgr ctrl.Manager) error { } // +kubebuilder:webhook:verbs=create;update;delete,path=/validate-cluster-x-k8s-io-v1beta1-machine,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=cluster.x-k8s.io,resources=machines,versions=v1beta1,name=validation.machine.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1 -// +kubebuilder:webhook:verbs=create;update;delete,path=/mutate-cluster-x-k8s-io-v1beta1-machine,mutating=true,failurePolicy=fail,matchPolicy=Equivalent,groups=cluster.x-k8s.io,resources=machines,versions=v1beta1,name=default.machine.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1 +// +kubebuilder:webhook:verbs=create;update,path=/mutate-cluster-x-k8s-io-v1beta1-machine,mutating=true,failurePolicy=fail,matchPolicy=Equivalent,groups=cluster.x-k8s.io,resources=machines,versions=v1beta1,name=default.machine.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1 var _ webhook.CustomValidator = &machineValidator{} var _ webhook.Defaulter = &Machine{} @@ -79,27 +79,14 @@ func (m *Machine) Default() { // MachineValidator creates a new CustomValidator for Machines. func MachineValidator(scheme *runtime.Scheme) webhook.CustomValidator { - // Note: The error return parameter is always nil and will be dropped with the next CR release. - decoder, _ := admission.NewDecoder(scheme) - return &machineValidator{ - decoder: decoder, - } + return &machineValidator{} } // machineValidator implements a defaulting webhook for Machine. -type machineValidator struct { - decoder *admission.Decoder -} +type machineValidator struct{} // ValidateCreate implements webhook.Validator so a webhook will be registered for the type. func (*machineValidator) ValidateCreate(ctx context.Context, obj runtime.Object) error { - log := ctrl.LoggerFrom(ctx) - - log.Info("Service account env is", "env", os.Getenv("POD_SERVICE_ACCOUNT")) - log.Info("Pod name env is", "env", os.Getenv("POD_NAME")) - log.Info("Pod namespace env is", "env", os.Getenv("POD_NAMESPACE")) - fmt.Printf("Service account env is %s\n", os.Getenv("POD_SERVICE_ACCOUNT")) - m, ok := obj.(*Machine) if !ok { return apierrors.NewBadRequest(fmt.Sprintf("expected a Machine but got a %T", obj)) diff --git a/exp/api/v1beta1/machinepool_types.go b/exp/api/v1beta1/machinepool_types.go index ac2508f6093f..2634affe1db3 100644 --- a/exp/api/v1beta1/machinepool_types.go +++ b/exp/api/v1beta1/machinepool_types.go @@ -27,10 +27,6 @@ import ( const ( // MachinePoolFinalizer is used to ensure deletion of dependencies (nodes, infra). MachinePoolFinalizer = "machinepool.cluster.x-k8s.io" - - // MachinePoolNameLabel is the label indicating the name of the MachinePool a Machine is controlled by. - // Note: The value of this label may be a hash if the MachinePool name is longer than 63 characters. - MachinePoolNameLabel = "cluster.x-k8s.io/pool-name" ) // ANCHOR: MachinePoolSpec diff --git a/exp/internal/controllers/machinepool_controller.go b/exp/internal/controllers/machinepool_controller.go index b90d18d62a1f..732e48b95968 100644 --- a/exp/internal/controllers/machinepool_controller.go +++ b/exp/internal/controllers/machinepool_controller.go @@ -102,19 +102,6 @@ func (r *MachinePoolReconciler) SetupWithManager(ctx context.Context, mgr ctrl.M return errors.Wrap(err, "failed setting up with a controller manager") } - err = c.Watch( - &source.Kind{Type: &clusterv1.Cluster{}}, - handler.EnqueueRequestsFromMapFunc(clusterToMachinePools), - // TODO: should this wait for Cluster.Status.InfrastructureReady similar to Infra Machine resources? - predicates.All(ctrl.LoggerFrom(ctx), - predicates.ClusterUnpaused(ctrl.LoggerFrom(ctx)), - predicates.ResourceHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue), - ), - ) - if err != nil { - return errors.Wrap(err, "failed adding Watch for Cluster to controller manager") - } - r.controller = c r.recorder = mgr.GetEventRecorderFor("machinepool-controller") return nil diff --git a/exp/internal/controllers/machinepool_controller_phases.go b/exp/internal/controllers/machinepool_controller_phases.go index 91f5411f4b27..c4885f6896d4 100644 --- a/exp/internal/controllers/machinepool_controller_phases.go +++ b/exp/internal/controllers/machinepool_controller_phases.go @@ -354,7 +354,6 @@ func (r *MachinePoolReconciler) reconcileMachinePoolMachines(ctx context.Context // If one missing but not both, return error if noKind != noSelector { - log.Info("Only one of infraMachineKind or infraMachineSelector found, this is unexpected") return errors.Errorf("only one of infraMachineKind or infraMachineSelector found, both must be present") } @@ -433,8 +432,11 @@ func (r *MachinePoolReconciler) deleteDanglingMachines(ctx context.Context, mp * // Until the InfraMachinePool populates its selector kind and selector labels, the MachinePool controller can't tell that it supports MachinePool Machines // and will create fallback machines to begin with. When the selector fields gets populated, we want to clean up those fallback machines. log.V(2).Info("Machine has an empty infraRef, this a fallback machine, will delete", "machine", machine.Name, "namespace", machine.Namespace) + if err := r.Client.Delete(ctx, machine); err != nil { + return err + } - return r.Client.Delete(ctx, machine) + continue } _, err := external.Get(ctx, r.Client, &infraRef, mp.Namespace)