Skip to content

Commit

Permalink
feat(experiments): Fire k8s Event bound to the Rollout when it owns t…
Browse files Browse the repository at this point in the history
…he Experiment

Addresses argoproj#4009. This change will fire Analysis Run events bound to the parent Rollout object when the Experiment is a Step in the Rollout.

Signed-off-by: mitchell amihod <[email protected]>
  • Loading branch information
meeech committed Feb 11, 2025
1 parent e653c91 commit 3dd8af0
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions experiments/experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ func newExperimentContext(
resyncPeriod time.Duration,
enqueueExperimentAfter func(obj any, duration time.Duration),
) *experimentContext {

exCtx := experimentContext{
ex: experiment,
templateRSs: templateRSs,
Expand Down Expand Up @@ -416,6 +415,19 @@ func (ec *experimentContext) reconcileAnalysisRun(analysis v1alpha1.ExperimentAn
eventType = corev1.EventTypeWarning
}
ec.recorder.Eventf(ec.ex, record.EventOptions{EventType: eventType, EventReason: "AnalysisRun" + string(newStatus.Phase)}, msg)

// Handle the case where the Analysis Run belongs to an Experiment, and the Experiment is a Step in the Rollout
// This makes sure the rollout gets the Analysis Run events, which will then trigger any subscribed notifications
// #4009
if experimentutil.BelongsToRollout(ec.ex) {
roRef := ec.ex.OwnerReferences[0]
rollout, err := ec.argoProjClientset.ArgoprojV1alpha1().Rollouts(ec.ex.Namespace).Get(context.TODO(), roRef.Name, metav1.GetOptions{})
if err != nil {
ec.log.Warnf("Failed to get parent Rollout of the Experiment '%s': %v", roRef.Name, err)
} else {
ec.recorder.Eventf(rollout, record.EventOptions{EventType: corev1.EventTypeWarning, EventReason: "AnalysisRun" + string(newStatus.Phase)}, msg)
}
}
}
experimentutil.SetAnalysisRunStatus(ec.newStatus, *newStatus)
}()
Expand Down Expand Up @@ -627,7 +639,6 @@ func (ec *experimentContext) assessAnalysisRuns() (v1alpha1.AnalysisPhase, strin

// newAnalysisRun generates an AnalysisRun from the experiment and template
func (ec *experimentContext) newAnalysisRun(analysis v1alpha1.ExperimentAnalysisTemplateRef, args []v1alpha1.Argument, dryRunMetrics []v1alpha1.DryRun, measurementRetentionMetrics []v1alpha1.MeasurementRetention, analysisRunMetadata *v1alpha1.AnalysisRunMetadata) (*v1alpha1.AnalysisRun, error) {

if analysis.ClusterScope {
analysisTemplates, clusterAnalysisTemplates, err := ec.getAnalysisTemplatesFromClusterAnalysis(analysis)
if err != nil {
Expand Down Expand Up @@ -772,7 +783,6 @@ func (ec *experimentContext) getAnalysisTemplatesFromRefs(templateRefs *[]v1alph
templates = append(templates, innerTemplates...)
}
}

}
uniqueTemplates, uniqueClusterTemplates := analysisutil.FilterUniqueTemplates(templates, clusterTemplates)
return uniqueTemplates, uniqueClusterTemplates, nil
Expand Down

0 comments on commit 3dd8af0

Please sign in to comment.