Skip to content

Commit

Permalink
Add analysis informers and listers to experiment controller
Browse files Browse the repository at this point in the history
  • Loading branch information
jessesuen committed Oct 20, 2019
1 parent 3648c50 commit fa1ce45
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 29 deletions.
2 changes: 2 additions & 0 deletions controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ func NewManager(
replicaSetInformer,
rolloutsInformer,
experimentsInformer,
analysisRunInformer,
analysisTemplateInformer,
resyncPeriod,
rolloutWorkqueue,
experimentWorkqueue,
Expand Down
52 changes: 32 additions & 20 deletions experiments/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@ type ExperimentController struct {
// rsControl is used for adopting/releasing replica sets.
replicaSetControl controller.RSControlInterface

replicaSetLister appslisters.ReplicaSetLister
rolloutsLister listers.RolloutLister
experimentsLister listers.ExperimentLister
replicaSetLister appslisters.ReplicaSetLister
rolloutsLister listers.RolloutLister
experimentsLister listers.ExperimentLister
analysisTemplateLister listers.AnalysisTemplateLister
analysisRunLister listers.AnalysisRunLister

replicaSetSynced cache.InformerSynced
experimentSynced cache.InformerSynced
rolloutSynced cache.InformerSynced
replicaSetSynced cache.InformerSynced
experimentSynced cache.InformerSynced
rolloutSynced cache.InformerSynced
analysisRunSynced cache.InformerSynced
analysisTemplateSynced cache.InformerSynced

metricsServer *metrics.MetricsServer

Expand Down Expand Up @@ -72,6 +76,8 @@ func NewExperimentController(
replicaSetInformer appsinformers.ReplicaSetInformer,
rolloutsInformer informers.RolloutInformer,
experimentsInformer informers.ExperimentInformer,
analysisRunInformer informers.AnalysisRunInformer,
analysisTemplateInformer informers.AnalysisTemplateInformer,
resyncPeriod time.Duration,
rolloutWorkQueue workqueue.RateLimitingInterface,
experimentWorkQueue workqueue.RateLimitingInterface,
Expand All @@ -84,21 +90,25 @@ func NewExperimentController(
}

controller := &ExperimentController{
kubeclientset: kubeclientset,
argoProjClientset: argoProjClientset,
replicaSetControl: replicaSetControl,
replicaSetLister: replicaSetInformer.Lister(),
rolloutsLister: rolloutsInformer.Lister(),
experimentsLister: experimentsInformer.Lister(),
metricsServer: metricsServer,
rolloutWorkqueue: rolloutWorkQueue,
experimentWorkqueue: experimentWorkQueue,
kubeclientset: kubeclientset,
argoProjClientset: argoProjClientset,
replicaSetControl: replicaSetControl,
replicaSetLister: replicaSetInformer.Lister(),
rolloutsLister: rolloutsInformer.Lister(),
experimentsLister: experimentsInformer.Lister(),
analysisTemplateLister: analysisTemplateInformer.Lister(),
analysisRunLister: analysisRunInformer.Lister(),
metricsServer: metricsServer,
rolloutWorkqueue: rolloutWorkQueue,
experimentWorkqueue: experimentWorkQueue,

replicaSetSynced: replicaSetInformer.Informer().HasSynced,
experimentSynced: experimentsInformer.Informer().HasSynced,
rolloutSynced: rolloutsInformer.Informer().HasSynced,
recorder: recorder,
resyncPeriod: resyncPeriod,
replicaSetSynced: replicaSetInformer.Informer().HasSynced,
experimentSynced: experimentsInformer.Informer().HasSynced,
rolloutSynced: rolloutsInformer.Informer().HasSynced,
analysisRunSynced: analysisRunInformer.Informer().HasSynced,
analysisTemplateSynced: analysisTemplateInformer.Informer().HasSynced,
recorder: recorder,
resyncPeriod: resyncPeriod,
}

controller.enqueueExperiment = func(obj interface{}) {
Expand Down Expand Up @@ -237,6 +247,8 @@ func (ec *ExperimentController) syncHandler(key string) error {
ec.kubeclientset,
ec.argoProjClientset,
ec.replicaSetLister,
ec.analysisTemplateLister,
ec.analysisRunLister,
ec.recorder,
ec.enqueueExperimentAfter,
)
Expand Down
12 changes: 9 additions & 3 deletions experiments/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ func (f *fixture) newController(resync resyncFunc) (*ExperimentController, infor
k8sI.Apps().V1().ReplicaSets(),
i.Argoproj().V1alpha1().Rollouts(),
i.Argoproj().V1alpha1().Experiments(),
i.Argoproj().V1alpha1().AnalysisRuns(),
i.Argoproj().V1alpha1().AnalysisTemplates(),
resync(),
rolloutWorkqueue,
experimentWorkqueue,
Expand Down Expand Up @@ -358,7 +360,7 @@ func (f *fixture) runController(experimentName string, startInformers bool, expe
i.Start(stopCh)
k8sI.Start(stopCh)

assert.True(f.t, cache.WaitForCacheSync(stopCh, c.replicaSetSynced, c.rolloutSynced, c.experimentSynced))
assert.True(f.t, cache.WaitForCacheSync(stopCh, c.replicaSetSynced, c.rolloutSynced, c.experimentSynced, c.analysisRunSynced, c.analysisTemplateSynced))
}

err := c.syncHandler(experimentName)
Expand Down Expand Up @@ -425,7 +427,7 @@ func checkAction(expected, actual core.Action, t *testing.T) {

// filterInformerActions filters list, and watch actions for testing resources.
// Since list, and watch don't change resource state we can filter it to lower
// nose level in our tests.
// noise level in our tests.
func filterInformerActions(actions []core.Action) []core.Action {
ret := []core.Action{}
for _, action := range actions {
Expand All @@ -434,7 +436,11 @@ func filterInformerActions(actions []core.Action) []core.Action {
action.Matches("list", "replicaSets") ||
action.Matches("watch", "replicaSets") ||
action.Matches("list", "experiments") ||
action.Matches("watch", "experiments") {
action.Matches("watch", "experiments") ||
action.Matches("list", "analysistemplates") ||
action.Matches("watch", "analysistemplates") ||
action.Matches("list", "analysisruns") ||
action.Matches("watch", "analysisruns") {
continue
}
ret = append(ret, action)
Expand Down
11 changes: 8 additions & 3 deletions experiments/experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ func newExperimentContext(
kubeclientset kubernetes.Interface,
argoProjClientset clientset.Interface,
replicaSetLister appslisters.ReplicaSetLister,
analysisTemplateLister rolloutslisters.AnalysisTemplateLister,
analysisRunLister rolloutslisters.AnalysisRunLister,
recorder record.EventRecorder,
enqueueExperimentAfter func(obj interface{}, duration time.Duration),
) *experimentContext {
Expand All @@ -59,6 +61,8 @@ func newExperimentContext(
kubeclientset: kubeclientset,
argoProjClientset: argoProjClientset,
replicaSetLister: replicaSetLister,
analysisTemplateLister: analysisTemplateLister,
analysisRunLister: analysisRunLister,
recorder: recorder,
enqueueExperimentAfter: enqueueExperimentAfter,

Expand Down Expand Up @@ -293,9 +297,10 @@ func (ec *experimentContext) createAnalysisRun(analysis v1alpha1.ExperimentAnaly
}

func (ec *experimentContext) calculateStatus() *v1alpha1.ExperimentStatus {
newStatus := v1alpha1.ExperimentStatus{
Conditions: ec.ex.Status.Conditions,
}
// newStatus := v1alpha1.ExperimentStatus{
// Conditions: ec.ex.Status.Conditions,
// }
newStatus := *ec.newStatus

newStatus.Running = ec.ex.Status.Running
if !experimentutil.HasStarted(ec.ex) {
Expand Down
10 changes: 7 additions & 3 deletions experiments/experiment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1"
"github.com/argoproj/argo-rollouts/pkg/client/clientset/versioned/fake"

//informers "github.com/argoproj/argo-rollouts/pkg/client/informers/externalversions"
informers "github.com/argoproj/argo-rollouts/pkg/client/informers/externalversions"
"github.com/argoproj/argo-rollouts/utils/conditions"
)

Expand All @@ -40,15 +40,18 @@ func newTestContext(ex *v1alpha1.Experiment, objects ...runtime.Object) *experim

k8sI := kubeinformers.NewSharedInformerFactory(kubeclient, noResyncPeriodFunc())
rsLister := k8sI.Apps().V1().ReplicaSets().Lister()
//rolloutsI := informers.NewSharedInformerFactory(f.client, resync())
//analysisRunLister := rolloutsI.Argoproj().V1alpha1().AnalysisRuns().Lister()
rolloutsI := informers.NewSharedInformerFactory(rolloutclient, noResyncPeriodFunc())
analysisRunLister := rolloutsI.Argoproj().V1alpha1().AnalysisRuns().Lister()
analysisTemplateLister := rolloutsI.Argoproj().V1alpha1().AnalysisTemplates().Lister()

return newExperimentContext(
ex,
make(map[string]*appsv1.ReplicaSet),
kubeclient,
rolloutclient,
rsLister,
analysisTemplateLister,
analysisRunLister,
&record.FakeRecorder{},
func(obj interface{}, duration time.Duration) {},
)
Expand Down Expand Up @@ -226,4 +229,5 @@ func TestFailReplicaSetCreation(t *testing.T) {
return true, nil, errors.New("intentional error")
})
exCtx.reconcile()
// TODO: check that we set condition
}
19 changes: 19 additions & 0 deletions test/e2e/functional/analysis-template-job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

kind: AnalysisTemplate
apiVersion: argoproj.io/v1alpha1
metadata:
name: job
spec:
metrics:
- name: test
provider:
job:
spec:
template:
spec:
containers:
- name: sleep
image: alpine:3.8
command: [sleep, "30"]
restartPolicy: Never
backoffLimit: 0
22 changes: 22 additions & 0 deletions test/e2e/functional/experiment-with-analysis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: argoproj.io/v1alpha1
kind: Experiment
metadata:
generateName: experiment-with-analysis-
spec:
duration: 3600
templates:
- name: baseline
selector:
matchLabels:
app: rollouts-demo
template:
metadata:
labels:
app: rollouts-demo
spec:
containers:
- name: rollouts-demo
image: argoproj/rollouts-demo:blue
analyses:
- name: job
templateName: job

0 comments on commit fa1ce45

Please sign in to comment.