Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Arvindthiru committed Nov 13, 2024
1 parent e7acdc2 commit 0b76225
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req runtime.Request) (runtim
return runtime.Result{}, r.updateEvictionStatus(ctx, &eviction)
}

// updateEvictionStatus updates eviction status.
func (r *Reconciler) updateEvictionStatus(ctx context.Context, eviction *placementv1alpha1.ClusterResourcePlacementEviction) error {
evictionRef := klog.KObj(eviction)
if err := r.Client.Status().Update(ctx, eviction); err != nil {
Expand All @@ -163,6 +164,7 @@ func (r *Reconciler) updateEvictionStatus(ctx context.Context, eviction *placeme
return nil
}

// deleteClusterResourceBinding deletes the specified cluster resource binding.
func (r *Reconciler) deleteClusterResourceBinding(ctx context.Context, binding *placementv1beta1.ClusterResourceBinding) error {
bindingRef := klog.KObj(binding)
if err := r.Client.Delete(ctx, binding); err != nil {
Expand All @@ -173,6 +175,7 @@ func (r *Reconciler) deleteClusterResourceBinding(ctx context.Context, binding *
return nil
}

// isEvictionAllowed calculates if eviction allowed based on available bindings and spec specified in placement disruption budget.
func isEvictionAllowed(desiredBindings int, bindings []placementv1beta1.ClusterResourceBinding, db placementv1alpha1.ClusterResourcePlacementDisruptionBudget) (bool, int, int) {
availableBindings := 0
for i := range bindings {
Expand All @@ -197,6 +200,7 @@ func isEvictionAllowed(desiredBindings int, bindings []placementv1beta1.ClusterR
return disruptionsAllowed > 0, disruptionsAllowed, availableBindings
}

// markEvictionValid sets the valid condition as true in eviction status.
func markEvictionValid(eviction *placementv1alpha1.ClusterResourcePlacementEviction) {
cond := metav1.Condition{
Type: string(placementv1alpha1.PlacementEvictionConditionTypeValid),
Expand All @@ -208,6 +212,7 @@ func markEvictionValid(eviction *placementv1alpha1.ClusterResourcePlacementEvict
eviction.SetConditions(cond)
}

// markEvictionInvalid sets the valid condition as false in eviction status.
func markEvictionInvalid(eviction *placementv1alpha1.ClusterResourcePlacementEviction, message string) {
cond := metav1.Condition{
Type: string(placementv1alpha1.PlacementEvictionConditionTypeValid),
Expand All @@ -219,6 +224,7 @@ func markEvictionInvalid(eviction *placementv1alpha1.ClusterResourcePlacementEvi
eviction.SetConditions(cond)
}

// markEvictionExecuted sets the executed condition as true in eviction status.
func markEvictionExecuted(eviction *placementv1alpha1.ClusterResourcePlacementEviction, message string) {
cond := metav1.Condition{
Type: string(placementv1alpha1.PlacementEvictionConditionTypeExecuted),
Expand All @@ -230,6 +236,7 @@ func markEvictionExecuted(eviction *placementv1alpha1.ClusterResourcePlacementEv
eviction.SetConditions(cond)
}

// markEvictionNotExecuted sets the executed condition as false in eviction status.
func markEvictionNotExecuted(eviction *placementv1alpha1.ClusterResourcePlacementEviction, message string) {
cond := metav1.Condition{
Type: string(placementv1alpha1.PlacementEvictionConditionTypeExecuted),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ import (
)

const (
crbNameTemplate = "crb-%d"
crpNameTemplate = "crp-%d"
evictionNameTemplate = "eviction-%d"
crbNameTemplate = "crb-%d"
anotherCRBNameTemplate = "another-crb-%d"
crpNameTemplate = "crp-%d"
evictionNameTemplate = "eviction-%d"
)

var (
Expand Down Expand Up @@ -62,7 +63,6 @@ var _ = Describe("Test ClusterResourcePlacementEviction Controller", Ordered, fu
})

It("Clean up resources", func() {
// Delete eviction.
ensureEvictionRemoved(evictionName)
})
})
Expand Down Expand Up @@ -99,7 +99,7 @@ var _ = Describe("Test ClusterResourcePlacementEviction Controller", Ordered, fu
crpName := fmt.Sprintf(crpNameTemplate, GinkgoParallelProcess())
evictionName := fmt.Sprintf(evictionNameTemplate, GinkgoParallelProcess())
crbName := fmt.Sprintf(crbNameTemplate, GinkgoParallelProcess())
anotherCRBName := fmt.Sprintf("another-crb-%d", GinkgoParallelProcess())
anotherCRBName := fmt.Sprintf(anotherCRBNameTemplate, GinkgoParallelProcess())

It("Create ClusterResourcePlacement", func() {
crp := buildTestCRP(crpName)
Expand Down Expand Up @@ -505,7 +505,7 @@ var _ = Describe("Test ClusterResourcePlacementEviction Controller", Ordered, fu
evictionName := fmt.Sprintf(evictionNameTemplate, GinkgoParallelProcess())
crpName := fmt.Sprintf(crpNameTemplate, GinkgoParallelProcess())
crbName := fmt.Sprintf(crbNameTemplate, GinkgoParallelProcess())
anotherCRBName := fmt.Sprintf("another-crb-%d", GinkgoParallelProcess())
anotherCRBName := fmt.Sprintf(anotherCRBNameTemplate, GinkgoParallelProcess())

It("Create ClusterResourcePlacement", func() {
// Create CRP.
Expand Down Expand Up @@ -556,7 +556,7 @@ var _ = Describe("Test ClusterResourcePlacementEviction Controller", Ordered, fu
return k8sClient.Get(ctx, types.NamespacedName{Name: crb.Name}, &crb)
}, eventuallyDuration, eventuallyInterval).Should(Succeed())

// Update CRB status to have available condition.
// Update CRB, anotherCRB status to have available condition.
// Ideally binding would contain more condition before available, but for the sake testing we only specify available condition.
availableCondition := metav1.Condition{
Type: string(placementv1beta1.ResourceBindingAvailable),
Expand Down

0 comments on commit 0b76225

Please sign in to comment.