Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rename interface{} => any #3000

Merged
merged 2 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
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 @@
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) {

Check warning on line 111 in analysis/controller.go

View check run for this annotation

Codecov / codecov/patch

analysis/controller.go#L111

Added line #L111 was not covered by tests
controller.enqueueIfCompleted(newObj)
},
DeleteFunc: func(obj interface{}) {
DeleteFunc: func(obj any) {

Check warning on line 114 in analysis/controller.go

View check run for this annotation

Codecov / codecov/patch

analysis/controller.go#L114

Added line #L114 was not covered by tests
controller.enqueueIfCompleted(obj)
},
})
Expand All @@ -120,10 +120,10 @@
// 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) {

Check warning on line 126 in analysis/controller.go

View check run for this annotation

Codecov / codecov/patch

analysis/controller.go#L126

Added line #L126 was not covered by tests
controller.enqueueAnalysis(obj)
if ar := unstructuredutil.ObjectToAnalysisRun(obj); ar != nil {
logCtx := logutil.WithAnalysisRun(ar)
Expand Down Expand Up @@ -186,7 +186,7 @@
return c.persistAnalysisRunStatus(run, newRun.Status)
}

func (c *Controller) enqueueIfCompleted(obj interface{}) {
func (c *Controller) enqueueIfCompleted(obj any) {

Check warning on line 189 in analysis/controller.go

View check run for this annotation

Codecov / codecov/patch

analysis/controller.go#L189

Added line #L189 was not covered by tests
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 @@
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 @@
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) {

Check warning on line 149 in experiments/controller.go

View check run for this annotation

Codecov / codecov/patch

experiments/controller.go#L149

Added line #L149 was not covered by tests
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 @@
// Two different versions of the same Replica will always have different RVs.
return
}
enqueueRollout := func(obj interface{}) {
enqueueRollout := func(obj any) {

Check warning on line 168 in experiments/controller.go

View check run for this annotation

Codecov / codecov/patch

experiments/controller.go#L168

Added line #L168 was not covered by tests
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 @@
})

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 @@
}
controllerutil.EnqueueParentObject(new, register.ExperimentKind, controller.enqueueExperiment)
},
DeleteFunc: func(obj interface{}) {
DeleteFunc: func(obj any) {

Check warning on line 207 in experiments/controller.go

View check run for this annotation

Codecov / codecov/patch

experiments/controller.go#L207

Added line #L207 was not covered by tests
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) {

Check warning on line 219 in experiments/controller.go

View check run for this annotation

Codecov / codecov/patch

experiments/controller.go#L219

Added line #L219 was not covered by tests
controller.enqueueIfCompleted(obj)
},
})
Expand Down Expand Up @@ -346,7 +346,7 @@
}

// 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
Loading