Skip to content

Commit

Permalink
Remove paused handling from reconcileExternal
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Büringer [email protected]
  • Loading branch information
sbueringer committed Nov 11, 2024
1 parent c54a51b commit 14c1111
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 67 deletions.
3 changes: 0 additions & 3 deletions controllers/external/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,4 @@ type ReconcileOutput struct {
// Details of the referenced external object.
// +optional
Result *unstructured.Unstructured
// Indicates if the external object is paused.
// +optional
Paused bool
}
21 changes: 3 additions & 18 deletions exp/internal/controllers/machinepool_controller_phases.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (r *MachinePoolReconciler) reconcilePhase(mp *expv1.MachinePool) {
}

// reconcileExternal handles generic unstructured objects referenced by a MachinePool.
func (r *MachinePoolReconciler) reconcileExternal(ctx context.Context, cluster *clusterv1.Cluster, m *expv1.MachinePool, ref *corev1.ObjectReference) (external.ReconcileOutput, error) {
func (r *MachinePoolReconciler) reconcileExternal(ctx context.Context, m *expv1.MachinePool, ref *corev1.ObjectReference) (external.ReconcileOutput, error) {
log := ctrl.LoggerFrom(ctx)

if err := utilconversion.UpdateReferenceAPIContract(ctx, r.Client, ref); err != nil {
Expand All @@ -127,12 +127,6 @@ func (r *MachinePoolReconciler) reconcileExternal(ctx context.Context, cluster *
return external.ReconcileOutput{}, err
}

// if external ref is paused, return error.
if annotations.IsPaused(cluster, obj) {
log.V(3).Info("External object referenced is paused")
return external.ReconcileOutput{Paused: true}, nil
}

// Initialize the patch helper.
patchHelper, err := patch.NewHelper(obj, r.Client)
if err != nil {
Expand Down Expand Up @@ -179,19 +173,14 @@ func (r *MachinePoolReconciler) reconcileExternal(ctx context.Context, cluster *
// reconcileBootstrap reconciles the Spec.Bootstrap.ConfigRef object on a MachinePool.
func (r *MachinePoolReconciler) reconcileBootstrap(ctx context.Context, s *scope) (ctrl.Result, error) {
log := ctrl.LoggerFrom(ctx)
cluster := s.cluster
m := s.machinePool
// Call generic external reconciler if we have an external reference.
var bootstrapConfig *unstructured.Unstructured
if m.Spec.Template.Spec.Bootstrap.ConfigRef != nil {
bootstrapReconcileResult, err := r.reconcileExternal(ctx, cluster, m, m.Spec.Template.Spec.Bootstrap.ConfigRef)
bootstrapReconcileResult, err := r.reconcileExternal(ctx, m, m.Spec.Template.Spec.Bootstrap.ConfigRef)
if err != nil {
return ctrl.Result{}, err
}
// if the external object is paused, return without any further processing
if bootstrapReconcileResult.Paused {
return ctrl.Result{}, nil
}
bootstrapConfig = bootstrapReconcileResult.Result

// If the bootstrap config is being deleted, return early.
Expand Down Expand Up @@ -247,7 +236,7 @@ func (r *MachinePoolReconciler) reconcileInfrastructure(ctx context.Context, s *
cluster := s.cluster
mp := s.machinePool
// Call generic external reconciler.
infraReconcileResult, err := r.reconcileExternal(ctx, cluster, mp, &mp.Spec.Template.Spec.InfrastructureRef)
infraReconcileResult, err := r.reconcileExternal(ctx, mp, &mp.Spec.Template.Spec.InfrastructureRef)
if err != nil {
if apierrors.IsNotFound(errors.Cause(err)) {
log.Error(err, "infrastructure reference could not be found")
Expand All @@ -262,10 +251,6 @@ func (r *MachinePoolReconciler) reconcileInfrastructure(ctx context.Context, s *
}
return ctrl.Result{}, err
}
// if the external object is paused, return without any further processing
if infraReconcileResult.Paused {
return ctrl.Result{}, nil
}
infraConfig := infraReconcileResult.Result

if !infraConfig.GetDeletionTimestamp().IsZero() {
Expand Down
37 changes: 0 additions & 37 deletions exp/internal/controllers/machinepool_controller_phases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1215,43 +1215,6 @@ func TestReconcileMachinePoolInfrastructure(t *testing.T) {
g.Expect(m.Status.GetTypedPhase()).To(Equal(expv1.MachinePoolPhaseFailed))
},
},
{
name: "infrastructure ref is paused",
infraConfig: map[string]interface{}{
"kind": builder.TestInfrastructureMachineTemplateKind,
"apiVersion": builder.InfrastructureGroupVersion.String(),
"metadata": map[string]interface{}{
"name": "infra-config1",
"namespace": metav1.NamespaceDefault,
"annotations": map[string]interface{}{
"cluster.x-k8s.io/paused": "true",
},
},
"spec": map[string]interface{}{
"providerIDList": []interface{}{
"test://id-1",
},
},
"status": map[string]interface{}{
"ready": true,
"addresses": []interface{}{
map[string]interface{}{
"type": "InternalIP",
"address": "10.0.0.1",
},
map[string]interface{}{
"type": "InternalIP",
"address": "10.0.0.2",
},
},
},
},
expectError: false,
expectChanged: false,
expected: func(g *WithT, m *expv1.MachinePool) {
g.Expect(m.Status.InfrastructureReady).To(BeFalse())
},
},
{
name: "ready bootstrap, infra, and nodeRef, machinepool is running, replicas 0, providerIDList not set",
machinepool: &expv1.MachinePool{
Expand Down
9 changes: 0 additions & 9 deletions internal/controllers/clusterclass/clusterclass_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import (
"sigs.k8s.io/cluster-api/feature"
runtimeclient "sigs.k8s.io/cluster-api/internal/runtime/client"
"sigs.k8s.io/cluster-api/internal/topology/variables"
"sigs.k8s.io/cluster-api/util/annotations"
"sigs.k8s.io/cluster-api/util/conditions"
"sigs.k8s.io/cluster-api/util/conversion"
"sigs.k8s.io/cluster-api/util/patch"
Expand Down Expand Up @@ -371,8 +370,6 @@ func refString(ref *corev1.ObjectReference) string {
}

func (r *Reconciler) reconcileExternal(ctx context.Context, clusterClass *clusterv1.ClusterClass, ref *corev1.ObjectReference) error {
log := ctrl.LoggerFrom(ctx)

obj, err := external.Get(ctx, r.Client, ref, clusterClass.Namespace)
if err != nil {
if apierrors.IsNotFound(errors.Cause(err)) {
Expand All @@ -381,12 +378,6 @@ func (r *Reconciler) reconcileExternal(ctx context.Context, clusterClass *cluste
return errors.Wrapf(err, "failed to get the external object for the ClusterClass. refGroupVersionKind: %s, refName: %s", ref.GroupVersionKind(), ref.Name)
}

// If referenced object is paused, return early.
if annotations.HasPaused(obj) {
log.V(3).Info("External object referenced is paused", "refGroupVersionKind", ref.GroupVersionKind(), "refName", ref.Name)
return nil
}

// Initialize the patch helper.
patchHelper, err := patch.NewHelper(obj, r.Client)
if err != nil {
Expand Down

0 comments on commit 14c1111

Please sign in to comment.