operator: reliability and simplification (#968)

* operator: make tests more reliable

* operator: simplify RetryOnConflict statements
This commit is contained in:
3u13r 2023-01-13 16:49:41 +01:00 committed by GitHub
parent c36a009188
commit 67f8336b9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 23 deletions

View File

@ -216,9 +216,6 @@ func (r *AutoscalingStrategyReconciler) tryUpdateStatus(ctx context.Context, nam
return err return err
} }
autoscalingStrategy.Status = *status.DeepCopy() autoscalingStrategy.Status = *status.DeepCopy()
if err := r.Status().Update(ctx, &autoscalingStrategy); err != nil { return r.Status().Update(ctx, &autoscalingStrategy)
return err
}
return nil
}) })
} }

View File

@ -743,10 +743,7 @@ func (r *NodeVersionReconciler) tryUpdateStatus(ctx context.Context, name types.
return err return err
} }
nodeVersion.Status = *status.DeepCopy() nodeVersion.Status = *status.DeepCopy()
if err := r.Status().Update(ctx, &nodeVersion); err != nil { return r.Status().Update(ctx, &nodeVersion)
return err
}
return nil
}) })
} }

View File

@ -246,7 +246,7 @@ var _ = Describe("NodeVersion controller", func() {
Eventually(func() int { Eventually(func() int {
err := k8sClient.Get(ctx, nodeVersionLookupKey, nodeVersion) err := k8sClient.Get(ctx, nodeVersionLookupKey, nodeVersion)
if err != nil { if err != nil {
return 0 return 1
} }
return len(nodeVersion.Status.AwaitingAnnotation) return len(nodeVersion.Status.AwaitingAnnotation)
}, timeout, interval).Should(Equal(0)) }, timeout, interval).Should(Equal(0))
@ -300,13 +300,18 @@ var _ = Describe("NodeVersion controller", func() {
}, timeout, interval).Should(HaveKeyWithValue("custom-node-label", "custom-node-label-value")) }, timeout, interval).Should(HaveKeyWithValue("custom-node-label", "custom-node-label-value"))
By("marking the new node as ready") By("marking the new node as ready")
secondNode.Status.Conditions = []corev1.NodeCondition{ Eventually(func() error {
{ if err := k8sClient.Get(ctx, secondNodeLookupKey, secondNode); err != nil {
Type: corev1.NodeReady, return err
Status: corev1.ConditionTrue, }
}, secondNode.Status.Conditions = []corev1.NodeCondition{
} {
Expect(k8sClient.Status().Update(ctx, secondNode)).Should(Succeed()) Type: corev1.NodeReady,
Status: corev1.ConditionTrue,
},
}
return k8sClient.Status().Update(ctx, secondNode)
}, timeout, interval).Should(Succeed())
By("waiting for a NodeMaintenance resource to be created") By("waiting for a NodeMaintenance resource to be created")
nodeMaintenance := &nodemaintenancev1beta1.NodeMaintenance{} nodeMaintenance := &nodemaintenancev1beta1.NodeMaintenance{}
@ -316,10 +321,12 @@ var _ = Describe("NodeVersion controller", func() {
By("marking the NodeMaintenance as successful") By("marking the NodeMaintenance as successful")
fakes.nodeStateGetter.setNodeState(updatev1alpha1.NodeStateTerminated) fakes.nodeStateGetter.setNodeState(updatev1alpha1.NodeStateTerminated)
nodeMaintenance.Status.Phase = nodemaintenancev1beta1.MaintenanceSucceeded
Expect(k8sClient.Status().Update(ctx, nodeMaintenance)).Should(Succeed())
Eventually(func() error { Eventually(func() error {
return k8sClient.Get(ctx, nodeMaintenanceLookupKey, nodeMaintenance) if err := k8sClient.Get(ctx, nodeMaintenanceLookupKey, nodeMaintenance); err != nil {
return err
}
nodeMaintenance.Status.Phase = nodemaintenancev1beta1.MaintenanceSucceeded
return k8sClient.Status().Update(ctx, nodeMaintenance)
}, timeout, interval).Should(Succeed()) }, timeout, interval).Should(Succeed())
By("checking that the outdated node is removed") By("checking that the outdated node is removed")

View File

@ -240,10 +240,7 @@ func (r *PendingNodeReconciler) tryUpdateStatus(ctx context.Context, name types.
return err return err
} }
pendingNode.Status = *status.DeepCopy() pendingNode.Status = *status.DeepCopy()
if err := r.Status().Update(ctx, pendingNode); err != nil { return r.Status().Update(ctx, pendingNode)
return err
}
return nil
}) })
} }