Skip to content

Commit

Permalink
feat(experiment): Add a check before deletion
Browse files Browse the repository at this point in the history
Signed-off-by: Ce Gao <[email protected]>
  • Loading branch information
gaocegege committed Jun 19, 2020
1 parent 20d5708 commit 528a735
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pkg/controller.v1alpha3/experiment/experiment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package experiment

import (
"context"
"fmt"
"sort"

"github.com/spf13/viper"
Expand Down Expand Up @@ -357,7 +358,7 @@ func (r *ReconcileExperiment) createTrials(instance *experimentsv1alpha3.Experim

func (r *ReconcileExperiment) deleteTrials(instance *experimentsv1alpha3.Experiment,
trials []trialsv1alpha3.Trial,
deleteCount int32) error {
expectedDeletions int32) error {
logger := log.WithValues("Experiment", types.NamespacedName{Name: instance.GetName(), Namespace: instance.GetNamespace()})

trialSlice := trials
Expand All @@ -366,7 +367,12 @@ func (r *ReconcileExperiment) deleteTrials(instance *experimentsv1alpha3.Experim
After(trialSlice[j].CreationTimestamp.Time)
})

for i := 0; i < int(deleteCount); i++ {
expected := int(expectedDeletions)
if len(trialSlice) < expected {
return fmt.Errorf("Expected to delete %d trials, but got %d trials",
expected, len(trialSlice))
}
for i := 0; i < expected; i++ {
if err := r.Delete(context.TODO(), &trialSlice[i]); err != nil {
logger.Error(err, "Trial Delete error")
return err
Expand Down

0 comments on commit 528a735

Please sign in to comment.