Skip to content

Commit

Permalink
test wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Mendoza committed May 3, 2024
1 parent 126435a commit f3bd8bf
Show file tree
Hide file tree
Showing 7 changed files with 278 additions and 350 deletions.
10 changes: 5 additions & 5 deletions controller/linodemachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func (r *LinodeMachineReconciler) reconcileCreate(

if reconciler.RecordDecayingCondition(machineScope.LinodeMachine,
ConditionPreflightCreated, string(cerrs.CreateMachineError), err.Error(),
reconciler.DefaultMachineControllerPreflightTimeout(r.ReconcileTimeout)) {
reconciler.DefaultTimeout(r.ReconcileTimeout, reconciler.DefaultMachineControllerWaitForPreflightTimeout)) {
return ctrl.Result{}, err
}

Expand Down Expand Up @@ -325,7 +325,7 @@ func (r *LinodeMachineReconciler) reconcileInstanceCreate(
if err := r.configureDisks(ctx, logger, machineScope, linodeInstance.ID); err != nil {
if reconciler.RecordDecayingCondition(machineScope.LinodeMachine,
ConditionPreflightConfigured, string(cerrs.CreateMachineError), err.Error(),
reconciler.DefaultMachineControllerPreflightTimeout(r.ReconcileTimeout)) {
reconciler.DefaultTimeout(r.ReconcileTimeout, reconciler.DefaultMachineControllerWaitForPreflightTimeout)) {
return ctrl.Result{}, err
}

Expand All @@ -341,7 +341,7 @@ func (r *LinodeMachineReconciler) reconcileInstanceCreate(

if reconciler.RecordDecayingCondition(machineScope.LinodeMachine,
ConditionPreflightBootTriggered, string(cerrs.CreateMachineError), err.Error(),
reconciler.DefaultMachineControllerPreflightTimeout(r.ReconcileTimeout)) {
reconciler.DefaultTimeout(r.ReconcileTimeout, reconciler.DefaultMachineControllerWaitForPreflightTimeout)) {
return ctrl.Result{}, err
}

Expand All @@ -357,7 +357,7 @@ func (r *LinodeMachineReconciler) reconcileInstanceCreate(

if reconciler.RecordDecayingCondition(machineScope.LinodeMachine,
ConditionPreflightNetworking, string(cerrs.CreateMachineError), err.Error(),
reconciler.DefaultMachineControllerPreflightTimeout(r.ReconcileTimeout)) {
reconciler.DefaultTimeout(r.ReconcileTimeout, reconciler.DefaultMachineControllerWaitForPreflightTimeout)) {
return ctrl.Result{}, err
}

Expand All @@ -374,7 +374,7 @@ func (r *LinodeMachineReconciler) reconcileInstanceCreate(

if reconciler.RecordDecayingCondition(machineScope.LinodeMachine,
ConditionPreflightReady, string(cerrs.CreateMachineError), err.Error(),
reconciler.DefaultMachineControllerPreflightTimeout(r.ReconcileTimeout)) {
reconciler.DefaultTimeout(r.ReconcileTimeout, reconciler.DefaultMachineControllerWaitForPreflightTimeout)) {
return ctrl.Result{}, err
}

Expand Down
10 changes: 4 additions & 6 deletions controller/linodeobjectstoragebucket_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ var _ = Describe("lifecycle", Ordered, Label("bucket", "lifecycle"), func() {
Expect(logOutput).To(ContainSubstring("Reconciling apply"))
Expect(logOutput).To(ContainSubstring("Secret lifecycle-bucket-details was applied with new access keys"))
}),
Once("resource keyGeneration is modified", func(ctx context.Context, _ Mock) {
obj.Spec.KeyGeneration = ptr.To(1)
Expect(k8sClient.Update(ctx, &obj)).To(Succeed())
}),
OneOf(
Path(Call("bucket is retrieved on update", func(ctx context.Context, mck Mock) {
mck.ObjectStorageClient.EXPECT().GetObjectStorageBucket(gomock.Any(), obj.Spec.Cluster, gomock.Any()).
Expand All @@ -214,12 +218,6 @@ var _ = Describe("lifecycle", Ordered, Label("bucket", "lifecycle"), func() {
}),
),
),
Once("resource keyGeneration is modified", func(ctx context.Context, _ Mock) {
objectKey := client.ObjectKeyFromObject(&obj)
Expect(k8sClient.Get(ctx, objectKey, &obj)).To(Succeed())
obj.Spec.KeyGeneration = ptr.To(1)
Expect(k8sClient.Update(ctx, &obj)).To(Succeed())
}),
OneOf(
// nb: Order matters for paths of the same length. The leftmost path is evaluated first.
// If we evaluate the happy path first, the bucket resource is mutated so the error path won't occur.
Expand Down
34 changes: 22 additions & 12 deletions controller/linodevpc_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/source"
Expand Down Expand Up @@ -134,7 +135,7 @@ func (r *LinodeVPCReconciler) reconcile(
// Always close the scope when exiting this function so we can persist
// any LinodeVPC changes. This ignores any resource not found errors
// when reconciling deletions.
if patchErr := vpcScope.Close(ctx); patchErr != nil && utilerrors.FilterOut(patchErr, apierrors.IsNotFound) != nil {
if patchErr := vpcScope.Close(ctx); patchErr != nil && utilerrors.FilterOut(util.UnwrapError(patchErr), apierrors.IsNotFound) != nil {
logger.Error(patchErr, "failed to patch LinodeVPC")

err = errors.Join(err, patchErr)
Expand All @@ -158,7 +159,7 @@ func (r *LinodeVPCReconciler) reconcile(
err = nil

default:
if vpcScope.LinodeVPC.ObjectMeta.DeletionTimestamp.Add(reconciler.DefaultVPCControllerReconcileTimeout).After(time.Now()) {
if vpcScope.LinodeVPC.ObjectMeta.DeletionTimestamp.Add(reconciler.DefaultTimeout(r.ReconcileTimeout, reconciler.DefaultVPCControllerReconcileTimeout)).After(time.Now()) {
logger.Info("re-queuing VPC deletion")

res = ctrl.Result{RequeueAfter: reconciler.DefaultVPCControllerReconcileDelay}
Expand All @@ -180,11 +181,17 @@ func (r *LinodeVPCReconciler) reconcile(

// Update
if vpcScope.LinodeVPC.Spec.VPCID != nil {
// Update is not currently supported, so do nothing for now
vpcScope.LinodeVPC.Status.Ready = true
failureReason = infrav1alpha1.UpdateVPCError

// failureReason = infrav1alpha1.UpdateVPCError
// logger = logger.WithValues("vpcID", *vpcScope.LinodeVPC.Spec.VPCID)
logger = logger.WithValues("vpcID", *vpcScope.LinodeVPC.Spec.VPCID)

err = r.reconcileUpdate(ctx, logger, vpcScope)
if err != nil && !reconciler.HasConditionSeverity(vpcScope.LinodeVPC, clusterv1.ReadyCondition, clusterv1.ConditionSeverityError) {
logger.Info("re-queuing VPC update")

res = ctrl.Result{RequeueAfter: reconciler.DefaultVPCControllerReconcileDelay}
err = nil
}

return
}
Expand All @@ -193,7 +200,7 @@ func (r *LinodeVPCReconciler) reconcile(
failureReason = infrav1alpha1.CreateVPCError

err = r.reconcileCreate(ctx, logger, vpcScope)
if err != nil && vpcScope.LinodeVPC.ObjectMeta.CreationTimestamp.Add(reconciler.DefaultVPCControllerReconcileTimeout).After(time.Now()) {
if err != nil && !reconciler.HasConditionSeverity(vpcScope.LinodeVPC, clusterv1.ReadyCondition, clusterv1.ConditionSeverityError) {
logger.Info("re-queuing VPC creation")

res = ctrl.Result{RequeueAfter: reconciler.DefaultVPCControllerReconcileDelay}
Expand All @@ -209,7 +216,7 @@ func (r *LinodeVPCReconciler) reconcileCreate(ctx context.Context, logger logr.L
if err := r.reconcileVPC(ctx, vpcScope, logger); err != nil {
logger.Error(err, "Failed to create VPC")

conditions.MarkFalse(vpcScope.LinodeVPC, clusterv1.ReadyCondition, string(infrav1alpha1.CreateVPCError), clusterv1.ConditionSeverityWarning, err.Error())
reconciler.RecordDecayingCondition(vpcScope.LinodeVPC, clusterv1.ReadyCondition, string(infrav1alpha1.CreateVPCError), err.Error(), reconciler.DefaultTimeout(r.ReconcileTimeout, reconciler.DefaultVPCControllerReconcileTimeout))

r.Recorder.Event(vpcScope.LinodeVPC, corev1.EventTypeWarning, string(infrav1alpha1.CreateVPCError), err.Error())

Expand All @@ -231,7 +238,7 @@ func (r *LinodeVPCReconciler) reconcileUpdate(ctx context.Context, logger logr.L
if err := r.reconcileVPC(ctx, vpcScope, logger); err != nil {
logger.Error(err, "Failed to update VPC")

conditions.MarkFalse(vpcScope.LinodeVPC, clusterv1.ReadyCondition, string(infrav1alpha1.UpdateVPCError), clusterv1.ConditionSeverityWarning, err.Error())
reconciler.RecordDecayingCondition(vpcScope.LinodeVPC, clusterv1.ReadyCondition, string(infrav1alpha1.UpdateVPCError), err.Error(), reconciler.DefaultTimeout(r.ReconcileTimeout, reconciler.DefaultVPCControllerReconcileTimeout))

r.Recorder.Event(vpcScope.LinodeVPC, corev1.EventTypeWarning, string(infrav1alpha1.UpdateVPCError), err.Error())

Expand Down Expand Up @@ -260,7 +267,7 @@ func (r *LinodeVPCReconciler) reconcileDelete(ctx context.Context, logger logr.L
continue
}

if vpc.Updated.Add(reconciler.DefaultVPCControllerWaitForHasNodesTimeout).After(time.Now()) {
if vpc.Updated.Add(reconciler.DefaultTimeout(r.ReconcileTimeout, reconciler.DefaultVPCControllerWaitForHasNodesTimeout)).After(time.Now()) {
return errVPCHasNodesAttached
}

Expand Down Expand Up @@ -298,8 +305,11 @@ func (r *LinodeVPCReconciler) SetupWithManager(mgr ctrl.Manager) error {
predicate.And(
// Filter for objects with a specific WatchLabel.
predicates.ResourceNotPausedAndHasFilterLabel(mgr.GetLogger(), r.WatchFilterValue),
// Do not reconcile events generated by the controller itself.
predicate.GenerationChangedPredicate{},
// Do not reconcile the Delete events generated by the
// controller itself.
predicate.Funcs{
DeleteFunc: func(e event.DeleteEvent) bool { return false },
},
)).Build(r)
if err != nil {
return fmt.Errorf("failed to build controller: %w", err)
Expand Down
Loading

0 comments on commit f3bd8bf

Please sign in to comment.