Skip to content

Commit

Permalink
refactor: rename interface{} => any (argoproj#3000)
Browse files Browse the repository at this point in the history
* rename interface{} => any

Signed-off-by: gang.liu <[email protected]>

* revert change to generated code

Signed-off-by: gang.liu <[email protected]>

---------

Signed-off-by: gang.liu <[email protected]>
Signed-off-by: Philip Clark <[email protected]>
  • Loading branch information
izturn authored and phclark committed Oct 15, 2023
1 parent 3b88d02 commit 11ed178
Show file tree
Hide file tree
Showing 81 changed files with 529 additions and 528 deletions.
20 changes: 10 additions & 10 deletions analysis/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ type Controller struct {
newProvider func(logCtx log.Entry, metric v1alpha1.Metric) (metric.Provider, error)

// used for unit testing
enqueueAnalysis func(obj interface{})
enqueueAnalysisAfter func(obj interface{}, duration time.Duration)
enqueueAnalysis func(obj any)
enqueueAnalysisAfter func(obj any, duration time.Duration)

// workqueue is a rate limited work queue. This is used to queue work to be
// processed instead of performing it as soon as a change happens. This
Expand Down Expand Up @@ -91,10 +91,10 @@ func NewController(cfg ControllerConfig) *Controller {
resyncPeriod: cfg.ResyncPeriod,
}

controller.enqueueAnalysis = func(obj interface{}) {
controller.enqueueAnalysis = func(obj any) {
controllerutil.Enqueue(obj, cfg.AnalysisRunWorkQueue)
}
controller.enqueueAnalysisAfter = func(obj interface{}, duration time.Duration) {
controller.enqueueAnalysisAfter = func(obj any, duration time.Duration) {
controllerutil.EnqueueAfter(obj, duration, cfg.AnalysisRunWorkQueue)
}

Expand All @@ -105,13 +105,13 @@ func NewController(cfg ControllerConfig) *Controller {
controller.newProvider = providerFactory.NewProvider

cfg.JobInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
AddFunc: func(obj any) {
controller.enqueueIfCompleted(obj)
},
UpdateFunc: func(oldObj, newObj interface{}) {
UpdateFunc: func(oldObj, newObj any) {
controller.enqueueIfCompleted(newObj)
},
DeleteFunc: func(obj interface{}) {
DeleteFunc: func(obj any) {
controller.enqueueIfCompleted(obj)
},
})
Expand All @@ -120,10 +120,10 @@ func NewController(cfg ControllerConfig) *Controller {
// Set up an event handler for when analysis resources change
cfg.AnalysisRunInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: controller.enqueueAnalysis,
UpdateFunc: func(old, new interface{}) {
UpdateFunc: func(old, new any) {
controller.enqueueAnalysis(new)
},
DeleteFunc: func(obj interface{}) {
DeleteFunc: func(obj any) {
controller.enqueueAnalysis(obj)
if ar := unstructuredutil.ObjectToAnalysisRun(obj); ar != nil {
logCtx := logutil.WithAnalysisRun(ar)
Expand Down Expand Up @@ -186,7 +186,7 @@ func (c *Controller) syncHandler(ctx context.Context, key string) error {
return c.persistAnalysisRunStatus(run, newRun.Status)
}

func (c *Controller) enqueueIfCompleted(obj interface{}) {
func (c *Controller) enqueueIfCompleted(obj any) {
job, ok := obj.(*batchv1.Job)
if !ok {
return
Expand Down
4 changes: 2 additions & 2 deletions analysis/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (f *fixture) newController(resync resyncFunc) (*Controller, informers.Share
Recorder: record.NewFakeEventRecorder(),
})

c.enqueueAnalysis = func(obj interface{}) {
c.enqueueAnalysis = func(obj any) {
var key string
var err error
if key, err = cache.MetaNamespaceKeyFunc(obj); err != nil {
Expand All @@ -127,7 +127,7 @@ func (f *fixture) newController(resync resyncFunc) (*Controller, informers.Share
f.enqueuedObjects[key] = count
c.analysisRunWorkQueue.Add(obj)
}
c.enqueueAnalysisAfter = func(obj interface{}, duration time.Duration) {
c.enqueueAnalysisAfter = func(obj any, duration time.Duration) {
c.enqueueAnalysis(obj)
}
f.provider = &mocks.Provider{}
Expand Down
2 changes: 1 addition & 1 deletion controller/metrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func newFakeServerConfig(objs ...runtime.Object) ServerConfig {
}
}

func testHttpResponse(t *testing.T, handler http.Handler, expectedResponse string, testFunc func(t assert.TestingT, s interface{}, contains interface{}, msgAndArgs ...interface{}) bool) {
func testHttpResponse(t *testing.T, handler http.Handler, expectedResponse string, testFunc func(t assert.TestingT, s any, contains any, msgAndArgs ...any) bool) {
t.Helper()
req, err := http.NewRequest("GET", "/metrics", nil)
assert.NoError(t, err)
Expand Down
36 changes: 18 additions & 18 deletions experiments/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ type Controller struct {
metricsServer *metrics.MetricsServer

// used for unit testing
enqueueExperiment func(obj interface{})
enqueueExperimentAfter func(obj interface{}, duration time.Duration)
enqueueExperiment func(obj any)
enqueueExperimentAfter func(obj any, duration time.Duration)

// workqueue is a rate limited work queue. This is used to queue work to be
// processed instead of performing it as soon as a change happens. This
Expand Down Expand Up @@ -127,31 +127,31 @@ func NewController(cfg ControllerConfig) *Controller {
resyncPeriod: cfg.ResyncPeriod,
}

controller.enqueueExperiment = func(obj interface{}) {
controller.enqueueExperiment = func(obj any) {
controllerutil.Enqueue(obj, cfg.ExperimentWorkQueue)
}
controller.enqueueExperimentAfter = func(obj interface{}, duration time.Duration) {
controller.enqueueExperimentAfter = func(obj any, duration time.Duration) {
controllerutil.EnqueueAfter(obj, duration, cfg.ExperimentWorkQueue)
}

log.Info("Setting up experiments event handlers")
// Set up an event handler for when experiment resources change
cfg.ExperimentsInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: controller.enqueueExperiment,
UpdateFunc: func(old, new interface{}) {
UpdateFunc: func(old, new any) {
controller.enqueueExperiment(new)
},
DeleteFunc: controller.enqueueExperiment,
})

cfg.ExperimentsInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
enqueueRollout := func(obj interface{}) {
AddFunc: func(obj any) {
enqueueRollout := func(obj any) {
controllerutil.Enqueue(obj, cfg.RolloutWorkQueue)
}
controllerutil.EnqueueParentObject(obj, register.RolloutKind, enqueueRollout)
},
UpdateFunc: func(old, new interface{}) {
UpdateFunc: func(old, new any) {
oldAcc, err := meta.Accessor(old)
if err != nil {
return
Expand All @@ -165,13 +165,13 @@ func NewController(cfg ControllerConfig) *Controller {
// Two different versions of the same Replica will always have different RVs.
return
}
enqueueRollout := func(obj interface{}) {
enqueueRollout := func(obj any) {
controllerutil.Enqueue(obj, cfg.RolloutWorkQueue)
}
controllerutil.EnqueueParentObject(new, register.RolloutKind, enqueueRollout)
},
DeleteFunc: func(obj interface{}) {
enqueueRollout := func(obj interface{}) {
DeleteFunc: func(obj any) {
enqueueRollout := func(obj any) {
controllerutil.Enqueue(obj, cfg.RolloutWorkQueue)
}
controllerutil.EnqueueParentObject(obj, register.RolloutKind, enqueueRollout)
Expand All @@ -184,10 +184,10 @@ func NewController(cfg ControllerConfig) *Controller {
})

cfg.ReplicaSetInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
AddFunc: func(obj any) {
controllerutil.EnqueueParentObject(obj, register.ExperimentKind, controller.enqueueExperiment)
},
UpdateFunc: func(old, new interface{}) {
UpdateFunc: func(old, new any) {
newRS := new.(*appsv1.ReplicaSet)
oldRS := old.(*appsv1.ReplicaSet)
if newRS.ResourceVersion == oldRS.ResourceVersion {
Expand All @@ -204,19 +204,19 @@ func NewController(cfg ControllerConfig) *Controller {
}
controllerutil.EnqueueParentObject(new, register.ExperimentKind, controller.enqueueExperiment)
},
DeleteFunc: func(obj interface{}) {
DeleteFunc: func(obj any) {
controllerutil.EnqueueParentObject(obj, register.ExperimentKind, controller.enqueueExperiment)
},
})

cfg.AnalysisRunInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
AddFunc: func(obj any) {
controller.enqueueIfCompleted(obj)
},
UpdateFunc: func(oldObj, newObj interface{}) {
UpdateFunc: func(oldObj, newObj any) {
controller.enqueueIfCompleted(newObj)
},
DeleteFunc: func(obj interface{}) {
DeleteFunc: func(obj any) {
controller.enqueueIfCompleted(obj)
},
})
Expand Down Expand Up @@ -346,7 +346,7 @@ func (ec *Controller) persistExperimentStatus(orig *v1alpha1.Experiment, newStat
}

// enqueueIfCompleted conditionally enqueues the AnalysisRun's Experiment if the run is complete
func (ec *Controller) enqueueIfCompleted(obj interface{}) {
func (ec *Controller) enqueueIfCompleted(obj any) {
run := unstructuredutil.ObjectToAnalysisRun(obj)
if run == nil {
return
Expand Down
10 changes: 5 additions & 5 deletions experiments/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,12 @@ func generateRSName(ex *v1alpha1.Experiment, template v1alpha1.TemplateSpec) str
}

func calculatePatch(ex *v1alpha1.Experiment, patch string, templates []v1alpha1.TemplateStatus, condition *v1alpha1.ExperimentCondition) string {
patchMap := make(map[string]interface{})
patchMap := make(map[string]any)
err := json.Unmarshal([]byte(patch), &patchMap)
if err != nil {
panic(err)
}
newStatus := patchMap["status"].(map[string]interface{})
newStatus := patchMap["status"].(map[string]any)
if templates != nil {
newStatus["templateStatuses"] = templates
patchMap["status"] = newStatus
Expand All @@ -334,7 +334,7 @@ func calculatePatch(ex *v1alpha1.Experiment, patch string, templates []v1alpha1.
newEx := &v1alpha1.Experiment{}
json.Unmarshal(newBytes, newEx)

newPatch := make(map[string]interface{})
newPatch := make(map[string]any)
json.Unmarshal(patchBytes, &newPatch)
newPatchBytes, _ := json.Marshal(newPatch)
return string(newPatchBytes)
Expand Down Expand Up @@ -380,7 +380,7 @@ func (f *fixture) newController(resync resyncFunc) (*Controller, informers.Share
})

var enqueuedObjectsLock sync.Mutex
c.enqueueExperiment = func(obj interface{}) {
c.enqueueExperiment = func(obj any) {
var key string
var err error
if key, err = cache.MetaNamespaceKeyFunc(obj); err != nil {
Expand All @@ -396,7 +396,7 @@ func (f *fixture) newController(resync resyncFunc) (*Controller, informers.Share
f.enqueuedObjects[key] = count
c.experimentWorkqueue.Add(obj)
}
c.enqueueExperimentAfter = func(obj interface{}, duration time.Duration) {
c.enqueueExperimentAfter = func(obj any, duration time.Duration) {
c.enqueueExperiment(obj)
}

Expand Down
4 changes: 2 additions & 2 deletions experiments/experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type experimentContext struct {
replicaSetLister appslisters.ReplicaSetLister
serviceLister v1.ServiceLister
recorder record.EventRecorder
enqueueExperimentAfter func(obj interface{}, duration time.Duration)
enqueueExperimentAfter func(obj any, duration time.Duration)
resyncPeriod time.Duration

// calculated values during reconciliation
Expand All @@ -70,7 +70,7 @@ func newExperimentContext(
serviceLister v1.ServiceLister,
recorder record.EventRecorder,
resyncPeriod time.Duration,
enqueueExperimentAfter func(obj interface{}, duration time.Duration),
enqueueExperimentAfter func(obj any, duration time.Duration),
) *experimentContext {

exCtx := experimentContext{
Expand Down
8 changes: 4 additions & 4 deletions experiments/experiment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func newTestContext(ex *v1alpha1.Experiment, objects ...runtime.Object) *experim
serviceLister,
record.NewFakeEventRecorder(),
noResyncPeriodFunc(),
func(obj interface{}, duration time.Duration) {},
func(obj any, duration time.Duration) {},
)
}

Expand Down Expand Up @@ -302,7 +302,7 @@ func TestDontRequeueWithoutDuration(t *testing.T) {
fakeClient := exCtx.kubeclientset.(*k8sfake.Clientset)
fakeClient.Tracker().Add(rs1)
enqueueCalled := false
exCtx.enqueueExperimentAfter = func(obj interface{}, duration time.Duration) {
exCtx.enqueueExperimentAfter = func(obj any, duration time.Duration) {
enqueueCalled = true
}
newStatus := exCtx.reconcile()
Expand All @@ -325,7 +325,7 @@ func TestRequeueAfterDuration(t *testing.T) {
"bar": rs1,
}
enqueueCalled := false
exCtx.enqueueExperimentAfter = func(obj interface{}, duration time.Duration) {
exCtx.enqueueExperimentAfter = func(obj any, duration time.Duration) {
enqueueCalled = true
// ensures we are enqueued around ~20 seconds
twentySeconds := time.Second * time.Duration(20)
Expand All @@ -352,7 +352,7 @@ func TestRequeueAfterProgressDeadlineSeconds(t *testing.T) {
"bar": rs1,
}
enqueueCalled := false
exCtx.enqueueExperimentAfter = func(obj interface{}, duration time.Duration) {
exCtx.enqueueExperimentAfter = func(obj any, duration time.Duration) {
enqueueCalled = true
// ensures we are enqueued around 10 minutes
tenMinutes := time.Second * time.Duration(600)
Expand Down
Loading

0 comments on commit 11ed178

Please sign in to comment.