Skip to content

Commit 6b377ca

Browse files
Per Goncalves da Silvatmshort
Per Goncalves da Silva
authored andcommitted
Address golangci-lint comments
Signed-off-by: Per Goncalves da Silva <[email protected]> Signed-off-by: Todd Short <[email protected]>
1 parent 0239e99 commit 6b377ca

File tree

11 files changed

+65
-63
lines changed

11 files changed

+65
-63
lines changed

pkg/controller/install/rule_checker_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -594,12 +594,14 @@ func NewFakeCSVRuleChecker(k8sObjs []runtime.Object, csv *operatorsv1alpha1.Clus
594594
for _, informer := range []cache.SharedIndexInformer{roleInformer.Informer(), roleBindingInformer.Informer(), clusterRoleInformer.Informer(), clusterRoleBindingInformer.Informer()} {
595595
go informer.Run(stopCh)
596596

597-
synced := func() (bool, error) {
597+
synced := func(_ context.Context) (done bool, err error) {
598598
return informer.HasSynced(), nil
599599
}
600600

601601
// wait until the informer has synced to continue
602-
wait.PollUntil(500*time.Millisecond, synced, stopCh)
602+
if err := wait.PollUntilContextTimeout(context.Background(), 500*time.Millisecond, 5*time.Second, true, synced); err != nil {
603+
return nil, err
604+
}
603605
}
604606

605607
ruleChecker := NewCSVRuleChecker(roleInformer.Lister(), roleBindingInformer.Lister(), clusterRoleInformer.Lister(), clusterRoleBindingInformer.Lister(), csv)

pkg/controller/operators/olm/operator_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -4953,7 +4953,7 @@ func TestSyncOperatorGroups(t *testing.T) {
49534953
require.NoError(t, err)
49544954

49554955
// Wait for the lister cache to catch up
4956-
err = wait.PollImmediateWithContext(ctx, tick, timeout, func(ctx context.Context) (bool, error) {
4956+
err = wait.PollUntilContextTimeout(ctx, tick, timeout, true, func(ctx context.Context) (bool, error) {
49574957
deployment, err := op.lister.AppsV1().DeploymentLister().Deployments(namespace).Get(dep.GetName())
49584958
if err != nil || deployment == nil {
49594959
return false, err
@@ -4974,7 +4974,7 @@ func TestSyncOperatorGroups(t *testing.T) {
49744974
require.NoError(t, err)
49754975

49764976
// Wait on operator group updated status to be in the cache as it is required for later CSV operations
4977-
err = wait.PollImmediateWithContext(ctx, tick, timeout, func(ctx context.Context) (bool, error) {
4977+
err = wait.PollUntilContextTimeout(ctx, tick, timeout, true, func(ctx context.Context) (bool, error) {
49784978
og, err := op.lister.OperatorsV1().OperatorGroupLister().OperatorGroups(operatorGroup.GetNamespace()).Get(operatorGroup.GetName())
49794979
if err != nil {
49804980
return false, err
@@ -4993,14 +4993,14 @@ func TestSyncOperatorGroups(t *testing.T) {
49934993

49944994
// This must be done (at least) twice to have annotateCSVs run in syncOperatorGroups and to catch provided API changes
49954995
// syncOperatorGroups is eventually consistent and may return errors until the cache has caught up with the cluster (fake client here)
4996-
wait.PollImmediateWithContext(ctx, tick, timeout, func(ctx context.Context) (bool, error) { // Throw away timeout errors since any timeout will coincide with err != nil anyway
4996+
err = wait.PollUntilContextTimeout(ctx, tick, timeout, true, func(ctx context.Context) (bool, error) { // Throw away timeout errors since any timeout will coincide with err != nil anyway
49974997
err = op.syncOperatorGroups(operatorGroup)
49984998
return err == nil, nil
49994999
})
50005000
require.NoError(t, err)
50015001

50025002
// Sync csvs enough to get them back to a succeeded state
5003-
err = wait.PollImmediateWithContext(ctx, tick, timeout, func(ctx context.Context) (bool, error) {
5003+
err = wait.PollUntilContextTimeout(ctx, tick, timeout, true, func(ctx context.Context) (bool, error) {
50045004
csvs, err := op.client.OperatorsV1alpha1().ClusterServiceVersions(operatorNamespace).List(ctx, metav1.ListOptions{})
50055005
if err != nil {
50065006
return false, err

pkg/controller/registry/resolver/resolver_test.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ import (
2424
)
2525

2626
var testGVKKey = opregistry.APIKey{Group: "g", Version: "v", Kind: "k", Plural: "ks"}
27-
28-
func init() {
29-
rand.Seed(time.Now().UnixNano())
30-
}
27+
var rnd = rand.New(rand.NewSource(time.Now().UnixNano()))
3128

3229
// tests can directly specify fixtures as cache entries instead of depending on this translation
3330
func csvSnapshotOrPanic(ns string, subs []*v1alpha1.Subscription, csvs ...*v1alpha1.ClusterServiceVersion) *cache.Snapshot {
@@ -778,7 +775,7 @@ func (g entryGenerator) gen() *cache.Entry {
778775
func genEntriesRandom(ops ...entryGenerator) []*cache.Entry {
779776
entries := make([]*cache.Entry, len(ops))
780777
// Randomize entry order to fuzz input operators over time.
781-
idxs := rand.Perm(len(ops))
778+
idxs := rnd.Perm(len(ops))
782779
for destIdx, srcIdx := range idxs {
783780
entries[destIdx] = ops[srcIdx].gen()
784781
}

pkg/controller/registry/resolver/solver/bench_test.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,35 @@ var BenchmarkInput = func() []Variable {
1818
nConflict = 3
1919
)
2020

21+
rnd := rand.New(rand.NewSource(seed))
22+
2123
id := func(i int) Identifier {
2224
return Identifier(strconv.Itoa(i))
2325
}
2426

2527
variable := func(i int) TestVariable {
2628
var c []Constraint
27-
if rand.Float64() < pMandatory {
29+
if rnd.Float64() < pMandatory {
2830
c = append(c, Mandatory())
2931
}
30-
if rand.Float64() < pDependency {
31-
n := rand.Intn(nDependency-1) + 1
32+
if rnd.Float64() < pDependency {
33+
n := rnd.Intn(nDependency-1) + 1
3234
var d []Identifier
3335
for x := 0; x < n; x++ {
3436
y := i
3537
for y == i {
36-
y = rand.Intn(length)
38+
y = rnd.Intn(length)
3739
}
3840
d = append(d, id(y))
3941
}
4042
c = append(c, Dependency(d...))
4143
}
42-
if rand.Float64() < pConflict {
43-
n := rand.Intn(nConflict-1) + 1
44+
if rnd.Float64() < pConflict {
45+
n := rnd.Intn(nConflict-1) + 1
4446
for x := 0; x < n; x++ {
4547
y := i
4648
for y == i {
47-
y = rand.Intn(length)
49+
y = rnd.Intn(length)
4850
}
4951
c = append(c, Conflict(id(y)))
5052
}
@@ -55,7 +57,6 @@ var BenchmarkInput = func() []Variable {
5557
}
5658
}
5759

58-
rand.Seed(seed)
5960
result := make([]Variable, length)
6061
for i := range result {
6162
result[i] = variable(i)

pkg/lib/operatorstatus/builder_test.go

+20-20
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestBuilder(t *testing.T) {
3030
},
3131
expected: &configv1.ClusterOperatorStatus{
3232
Conditions: []configv1.ClusterOperatorStatusCondition{
33-
configv1.ClusterOperatorStatusCondition{
33+
{
3434
Type: configv1.OperatorProgressing,
3535
Status: configv1.ConditionTrue,
3636
Message: "message",
@@ -51,7 +51,7 @@ func TestBuilder(t *testing.T) {
5151
},
5252
existing: &configv1.ClusterOperatorStatus{
5353
Conditions: []configv1.ClusterOperatorStatusCondition{
54-
configv1.ClusterOperatorStatusCondition{
54+
{
5555
Type: configv1.OperatorProgressing,
5656
Status: configv1.ConditionFalse,
5757
},
@@ -61,7 +61,7 @@ func TestBuilder(t *testing.T) {
6161
},
6262
expected: &configv1.ClusterOperatorStatus{
6363
Conditions: []configv1.ClusterOperatorStatusCondition{
64-
configv1.ClusterOperatorStatusCondition{
64+
{
6565
Type: configv1.OperatorProgressing,
6666
Status: configv1.ConditionTrue,
6767
Message: "message",
@@ -82,7 +82,7 @@ func TestBuilder(t *testing.T) {
8282
},
8383
existing: &configv1.ClusterOperatorStatus{
8484
Conditions: []configv1.ClusterOperatorStatusCondition{
85-
configv1.ClusterOperatorStatusCondition{
85+
{
8686
Type: configv1.OperatorProgressing,
8787
Status: configv1.ConditionTrue,
8888
LastTransitionTime: minuteAgo,
@@ -93,7 +93,7 @@ func TestBuilder(t *testing.T) {
9393
},
9494
expected: &configv1.ClusterOperatorStatus{
9595
Conditions: []configv1.ClusterOperatorStatusCondition{
96-
configv1.ClusterOperatorStatusCondition{
96+
{
9797
Type: configv1.OperatorProgressing,
9898
Status: configv1.ConditionTrue,
9999
Message: "message",
@@ -199,7 +199,7 @@ func TestBuilder(t *testing.T) {
199199
expected: &configv1.ClusterOperatorStatus{
200200
Conditions: []configv1.ClusterOperatorStatusCondition{},
201201
Versions: []configv1.OperandVersion{
202-
configv1.OperandVersion{
202+
{
203203
Name: "foo",
204204
Version: "1.00",
205205
},
@@ -218,7 +218,7 @@ func TestBuilder(t *testing.T) {
218218
existing: &configv1.ClusterOperatorStatus{
219219
Conditions: []configv1.ClusterOperatorStatusCondition{},
220220
Versions: []configv1.OperandVersion{
221-
configv1.OperandVersion{
221+
{
222222
Name: "foo",
223223
Version: "1.00",
224224
},
@@ -228,7 +228,7 @@ func TestBuilder(t *testing.T) {
228228
expected: &configv1.ClusterOperatorStatus{
229229
Conditions: []configv1.ClusterOperatorStatusCondition{},
230230
Versions: []configv1.OperandVersion{
231-
configv1.OperandVersion{
231+
{
232232
Name: "foo",
233233
Version: "1.00",
234234
},
@@ -247,7 +247,7 @@ func TestBuilder(t *testing.T) {
247247
existing: &configv1.ClusterOperatorStatus{
248248
Conditions: []configv1.ClusterOperatorStatusCondition{},
249249
Versions: []configv1.OperandVersion{
250-
configv1.OperandVersion{
250+
{
251251
Name: "foo",
252252
Version: "1.00",
253253
},
@@ -257,7 +257,7 @@ func TestBuilder(t *testing.T) {
257257
expected: &configv1.ClusterOperatorStatus{
258258
Conditions: []configv1.ClusterOperatorStatusCondition{},
259259
Versions: []configv1.OperandVersion{
260-
configv1.OperandVersion{
260+
{
261261
Name: "foo",
262262
Version: "2.00",
263263
},
@@ -275,7 +275,7 @@ func TestBuilder(t *testing.T) {
275275
existing: &configv1.ClusterOperatorStatus{
276276
Conditions: []configv1.ClusterOperatorStatusCondition{},
277277
Versions: []configv1.OperandVersion{
278-
configv1.OperandVersion{
278+
{
279279
Name: "foo",
280280
Version: "1.00",
281281
},
@@ -285,11 +285,11 @@ func TestBuilder(t *testing.T) {
285285
expected: &configv1.ClusterOperatorStatus{
286286
Conditions: []configv1.ClusterOperatorStatusCondition{},
287287
Versions: []configv1.OperandVersion{
288-
configv1.OperandVersion{
288+
{
289289
Name: "foo",
290290
Version: "2.00",
291291
},
292-
configv1.OperandVersion{
292+
{
293293
Name: "bar",
294294
Version: "1.00",
295295
},
@@ -308,11 +308,11 @@ func TestBuilder(t *testing.T) {
308308
existing: &configv1.ClusterOperatorStatus{
309309
Conditions: []configv1.ClusterOperatorStatusCondition{},
310310
Versions: []configv1.OperandVersion{
311-
configv1.OperandVersion{
311+
{
312312
Name: "foo",
313313
Version: "1.00",
314314
},
315-
configv1.OperandVersion{
315+
{
316316
Name: "bar",
317317
Version: "1.00",
318318
},
@@ -322,7 +322,7 @@ func TestBuilder(t *testing.T) {
322322
expected: &configv1.ClusterOperatorStatus{
323323
Conditions: []configv1.ClusterOperatorStatusCondition{},
324324
Versions: []configv1.OperandVersion{
325-
configv1.OperandVersion{
325+
{
326326
Name: "bar",
327327
Version: "1.00",
328328
},
@@ -342,7 +342,7 @@ func TestBuilder(t *testing.T) {
342342
Conditions: []configv1.ClusterOperatorStatusCondition{},
343343
Versions: []configv1.OperandVersion{},
344344
RelatedObjects: []configv1.ObjectReference{
345-
configv1.ObjectReference{
345+
{
346346
Group: "group",
347347
Resource: "resources",
348348
Namespace: "namespace",
@@ -363,7 +363,7 @@ func TestBuilder(t *testing.T) {
363363
Conditions: []configv1.ClusterOperatorStatusCondition{},
364364
Versions: []configv1.OperandVersion{},
365365
RelatedObjects: []configv1.ObjectReference{
366-
configv1.ObjectReference{
366+
{
367367
Group: "group",
368368
Resource: "resources",
369369
Namespace: "namespace",
@@ -375,7 +375,7 @@ func TestBuilder(t *testing.T) {
375375
Conditions: []configv1.ClusterOperatorStatusCondition{},
376376
Versions: []configv1.OperandVersion{},
377377
RelatedObjects: []configv1.ObjectReference{
378-
configv1.ObjectReference{
378+
{
379379
Group: "group",
380380
Resource: "resources",
381381
Namespace: "namespace",
@@ -396,7 +396,7 @@ func TestBuilder(t *testing.T) {
396396
Conditions: []configv1.ClusterOperatorStatusCondition{},
397397
Versions: []configv1.OperandVersion{},
398398
RelatedObjects: []configv1.ObjectReference{
399-
configv1.ObjectReference{
399+
{
400400
Group: "group",
401401
Resource: "resources",
402402
Namespace: "namespace",

pkg/lib/operatorstatus/monitor_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ func TestMonitorWaiting(t *testing.T) {
1717

1818
statusWant := &configv1.ClusterOperatorStatus{
1919
Conditions: []configv1.ClusterOperatorStatusCondition{
20-
configv1.ClusterOperatorStatusCondition{
20+
{
2121
Type: configv1.OperatorDegraded,
2222
Status: configv1.ConditionFalse,
2323
LastTransitionTime: metav1.NewTime(fakeClock.Now()),
2424
},
25-
configv1.ClusterOperatorStatusCondition{
25+
{
2626
Type: configv1.OperatorAvailable,
2727
Status: configv1.ConditionFalse,
2828
LastTransitionTime: metav1.NewTime(fakeClock.Now()),
2929
},
30-
configv1.ClusterOperatorStatusCondition{
30+
{
3131
Type: configv1.OperatorProgressing,
3232
Status: configv1.ConditionTrue,
3333
Message: fmt.Sprintf("waiting for events - source=%s", name),

pkg/lib/proxy/envvar.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ var (
3636
// As a consumer we should be reading off of proxy.status.
3737
func ToEnvVar(proxy *apiconfigv1.Proxy) []corev1.EnvVar {
3838
return []corev1.EnvVar{
39-
corev1.EnvVar{
39+
{
4040
Name: envHTTPProxyName,
4141
Value: proxy.Status.HTTPProxy,
4242
},
43-
corev1.EnvVar{
43+
{
4444
Name: envHTTPSProxyName,
4545
Value: proxy.Status.HTTPSProxy,
4646
},
47-
corev1.EnvVar{
47+
{
4848
Name: envNoProxyName,
4949
Value: proxy.Status.NoProxy,
5050
},

pkg/lib/proxy/envvar_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ func TestToEnvVar(t *testing.T) {
3131
},
3232
},
3333
envVarWant: []corev1.EnvVar{
34-
corev1.EnvVar{
34+
{
3535
Name: envHTTPProxyName,
3636
Value: "http://",
3737
},
38-
corev1.EnvVar{
38+
{
3939
Name: envHTTPSProxyName,
4040
Value: "https://",
4141
},
42-
corev1.EnvVar{
42+
{
4343
Name: envNoProxyName,
4444
Value: "foo,bar",
4545
},
@@ -56,15 +56,15 @@ func TestToEnvVar(t *testing.T) {
5656
},
5757
},
5858
envVarWant: []corev1.EnvVar{
59-
corev1.EnvVar{
59+
{
6060
Name: envHTTPProxyName,
6161
Value: "http://",
6262
},
63-
corev1.EnvVar{
63+
{
6464
Name: envHTTPSProxyName,
6565
Value: "",
6666
},
67-
corev1.EnvVar{
67+
{
6868
Name: envNoProxyName,
6969
Value: "",
7070
},

0 commit comments

Comments
 (0)