Double check the experiment status before creating trials
@@ -18,6 +18,7 @@ package experiment
import (
"context"
+
"github.com/redskyops/k8s-experiment/internal/meta"
"github.com/redskyops/k8s-experiment/internal/trial"
redskyv1alpha1 "github.com/redskyops/k8s-experiment/pkg/apis/redsky/v1alpha1"
@@ -32,17 +33,17 @@ import (
func NextTrialNamespace(c client.Client, ctx context.Context, exp *redskyv1alpha1.Experiment, trialList *redskyv1alpha1.TrialList) (string, error) {
// Determine which namespaces have an active trial
activeNamespaces := make(map[string]bool, len(trialList.Items))
- desiredReplicas := exp.Replicas()
+ activeTrials := int32(0)
for i := range trialList.Items {
t := &trialList.Items[i]
if trial.IsActive(t) {
activeNamespaces[t.Namespace] = true
- desiredReplicas--
+ activeTrials++
}
}
// Check the number of desired replicas
- if desiredReplicas <= 0 {
+ if activeTrials >= exp.Replicas() || exp.Status.ActiveTrials != activeTrials {
return "", nil
}
