Skip to content

Commit

Permalink
Address golangci-lint comments
Browse files Browse the repository at this point in the history
Signed-off-by: Per Goncalves da Silva <pegoncal@redhat.com>
Signed-off-by: Todd Short <todd.short@me.com>
  • Loading branch information
Per Goncalves da Silva authored and tmshort committed Jul 14, 2023
1 parent 0239e99 commit 6b377ca
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 63 deletions.
6 changes: 4 additions & 2 deletions pkg/controller/install/rule_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,12 +594,14 @@ func NewFakeCSVRuleChecker(k8sObjs []runtime.Object, csv *operatorsv1alpha1.Clus
for _, informer := range []cache.SharedIndexInformer{roleInformer.Informer(), roleBindingInformer.Informer(), clusterRoleInformer.Informer(), clusterRoleBindingInformer.Informer()} {
go informer.Run(stopCh)

synced := func() (bool, error) {
synced := func(_ context.Context) (done bool, err error) {
return informer.HasSynced(), nil
}

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

ruleChecker := NewCSVRuleChecker(roleInformer.Lister(), roleBindingInformer.Lister(), clusterRoleInformer.Lister(), clusterRoleBindingInformer.Lister(), csv)
Expand Down
8 changes: 4 additions & 4 deletions pkg/controller/operators/olm/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4953,7 +4953,7 @@ func TestSyncOperatorGroups(t *testing.T) {
require.NoError(t, err)

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

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

// This must be done (at least) twice to have annotateCSVs run in syncOperatorGroups and to catch provided API changes
// syncOperatorGroups is eventually consistent and may return errors until the cache has caught up with the cluster (fake client here)
wait.PollImmediateWithContext(ctx, tick, timeout, func(ctx context.Context) (bool, error) { // Throw away timeout errors since any timeout will coincide with err != nil anyway
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
err = op.syncOperatorGroups(operatorGroup)
return err == nil, nil
})
require.NoError(t, err)

// Sync csvs enough to get them back to a succeeded state
err = wait.PollImmediateWithContext(ctx, tick, timeout, func(ctx context.Context) (bool, error) {
err = wait.PollUntilContextTimeout(ctx, tick, timeout, true, func(ctx context.Context) (bool, error) {
csvs, err := op.client.OperatorsV1alpha1().ClusterServiceVersions(operatorNamespace).List(ctx, metav1.ListOptions{})
if err != nil {
return false, err
Expand Down
7 changes: 2 additions & 5 deletions pkg/controller/registry/resolver/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ import (
)

var testGVKKey = opregistry.APIKey{Group: "g", Version: "v", Kind: "k", Plural: "ks"}

func init() {
rand.Seed(time.Now().UnixNano())
}
var rnd = rand.New(rand.NewSource(time.Now().UnixNano()))

// tests can directly specify fixtures as cache entries instead of depending on this translation
func csvSnapshotOrPanic(ns string, subs []*v1alpha1.Subscription, csvs ...*v1alpha1.ClusterServiceVersion) *cache.Snapshot {
Expand Down Expand Up @@ -778,7 +775,7 @@ func (g entryGenerator) gen() *cache.Entry {
func genEntriesRandom(ops ...entryGenerator) []*cache.Entry {
entries := make([]*cache.Entry, len(ops))
// Randomize entry order to fuzz input operators over time.
idxs := rand.Perm(len(ops))
idxs := rnd.Perm(len(ops))
for destIdx, srcIdx := range idxs {
entries[destIdx] = ops[srcIdx].gen()
}
Expand Down
17 changes: 9 additions & 8 deletions pkg/controller/registry/resolver/solver/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,35 @@ var BenchmarkInput = func() []Variable {
nConflict = 3
)

rnd := rand.New(rand.NewSource(seed))

id := func(i int) Identifier {
return Identifier(strconv.Itoa(i))
}

variable := func(i int) TestVariable {
var c []Constraint
if rand.Float64() < pMandatory {
if rnd.Float64() < pMandatory {
c = append(c, Mandatory())
}
if rand.Float64() < pDependency {
n := rand.Intn(nDependency-1) + 1
if rnd.Float64() < pDependency {
n := rnd.Intn(nDependency-1) + 1
var d []Identifier
for x := 0; x < n; x++ {
y := i
for y == i {
y = rand.Intn(length)
y = rnd.Intn(length)
}
d = append(d, id(y))
}
c = append(c, Dependency(d...))
}
if rand.Float64() < pConflict {
n := rand.Intn(nConflict-1) + 1
if rnd.Float64() < pConflict {
n := rnd.Intn(nConflict-1) + 1
for x := 0; x < n; x++ {
y := i
for y == i {
y = rand.Intn(length)
y = rnd.Intn(length)
}
c = append(c, Conflict(id(y)))
}
Expand All @@ -55,7 +57,6 @@ var BenchmarkInput = func() []Variable {
}
}

rand.Seed(seed)
result := make([]Variable, length)
for i := range result {
result[i] = variable(i)
Expand Down
40 changes: 20 additions & 20 deletions pkg/lib/operatorstatus/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestBuilder(t *testing.T) {
},
expected: &configv1.ClusterOperatorStatus{
Conditions: []configv1.ClusterOperatorStatusCondition{
configv1.ClusterOperatorStatusCondition{
{
Type: configv1.OperatorProgressing,
Status: configv1.ConditionTrue,
Message: "message",
Expand All @@ -51,7 +51,7 @@ func TestBuilder(t *testing.T) {
},
existing: &configv1.ClusterOperatorStatus{
Conditions: []configv1.ClusterOperatorStatusCondition{
configv1.ClusterOperatorStatusCondition{
{
Type: configv1.OperatorProgressing,
Status: configv1.ConditionFalse,
},
Expand All @@ -61,7 +61,7 @@ func TestBuilder(t *testing.T) {
},
expected: &configv1.ClusterOperatorStatus{
Conditions: []configv1.ClusterOperatorStatusCondition{
configv1.ClusterOperatorStatusCondition{
{
Type: configv1.OperatorProgressing,
Status: configv1.ConditionTrue,
Message: "message",
Expand All @@ -82,7 +82,7 @@ func TestBuilder(t *testing.T) {
},
existing: &configv1.ClusterOperatorStatus{
Conditions: []configv1.ClusterOperatorStatusCondition{
configv1.ClusterOperatorStatusCondition{
{
Type: configv1.OperatorProgressing,
Status: configv1.ConditionTrue,
LastTransitionTime: minuteAgo,
Expand All @@ -93,7 +93,7 @@ func TestBuilder(t *testing.T) {
},
expected: &configv1.ClusterOperatorStatus{
Conditions: []configv1.ClusterOperatorStatusCondition{
configv1.ClusterOperatorStatusCondition{
{
Type: configv1.OperatorProgressing,
Status: configv1.ConditionTrue,
Message: "message",
Expand Down Expand Up @@ -199,7 +199,7 @@ func TestBuilder(t *testing.T) {
expected: &configv1.ClusterOperatorStatus{
Conditions: []configv1.ClusterOperatorStatusCondition{},
Versions: []configv1.OperandVersion{
configv1.OperandVersion{
{
Name: "foo",
Version: "1.00",
},
Expand All @@ -218,7 +218,7 @@ func TestBuilder(t *testing.T) {
existing: &configv1.ClusterOperatorStatus{
Conditions: []configv1.ClusterOperatorStatusCondition{},
Versions: []configv1.OperandVersion{
configv1.OperandVersion{
{
Name: "foo",
Version: "1.00",
},
Expand All @@ -228,7 +228,7 @@ func TestBuilder(t *testing.T) {
expected: &configv1.ClusterOperatorStatus{
Conditions: []configv1.ClusterOperatorStatusCondition{},
Versions: []configv1.OperandVersion{
configv1.OperandVersion{
{
Name: "foo",
Version: "1.00",
},
Expand All @@ -247,7 +247,7 @@ func TestBuilder(t *testing.T) {
existing: &configv1.ClusterOperatorStatus{
Conditions: []configv1.ClusterOperatorStatusCondition{},
Versions: []configv1.OperandVersion{
configv1.OperandVersion{
{
Name: "foo",
Version: "1.00",
},
Expand All @@ -257,7 +257,7 @@ func TestBuilder(t *testing.T) {
expected: &configv1.ClusterOperatorStatus{
Conditions: []configv1.ClusterOperatorStatusCondition{},
Versions: []configv1.OperandVersion{
configv1.OperandVersion{
{
Name: "foo",
Version: "2.00",
},
Expand All @@ -275,7 +275,7 @@ func TestBuilder(t *testing.T) {
existing: &configv1.ClusterOperatorStatus{
Conditions: []configv1.ClusterOperatorStatusCondition{},
Versions: []configv1.OperandVersion{
configv1.OperandVersion{
{
Name: "foo",
Version: "1.00",
},
Expand All @@ -285,11 +285,11 @@ func TestBuilder(t *testing.T) {
expected: &configv1.ClusterOperatorStatus{
Conditions: []configv1.ClusterOperatorStatusCondition{},
Versions: []configv1.OperandVersion{
configv1.OperandVersion{
{
Name: "foo",
Version: "2.00",
},
configv1.OperandVersion{
{
Name: "bar",
Version: "1.00",
},
Expand All @@ -308,11 +308,11 @@ func TestBuilder(t *testing.T) {
existing: &configv1.ClusterOperatorStatus{
Conditions: []configv1.ClusterOperatorStatusCondition{},
Versions: []configv1.OperandVersion{
configv1.OperandVersion{
{
Name: "foo",
Version: "1.00",
},
configv1.OperandVersion{
{
Name: "bar",
Version: "1.00",
},
Expand All @@ -322,7 +322,7 @@ func TestBuilder(t *testing.T) {
expected: &configv1.ClusterOperatorStatus{
Conditions: []configv1.ClusterOperatorStatusCondition{},
Versions: []configv1.OperandVersion{
configv1.OperandVersion{
{
Name: "bar",
Version: "1.00",
},
Expand All @@ -342,7 +342,7 @@ func TestBuilder(t *testing.T) {
Conditions: []configv1.ClusterOperatorStatusCondition{},
Versions: []configv1.OperandVersion{},
RelatedObjects: []configv1.ObjectReference{
configv1.ObjectReference{
{
Group: "group",
Resource: "resources",
Namespace: "namespace",
Expand All @@ -363,7 +363,7 @@ func TestBuilder(t *testing.T) {
Conditions: []configv1.ClusterOperatorStatusCondition{},
Versions: []configv1.OperandVersion{},
RelatedObjects: []configv1.ObjectReference{
configv1.ObjectReference{
{
Group: "group",
Resource: "resources",
Namespace: "namespace",
Expand All @@ -375,7 +375,7 @@ func TestBuilder(t *testing.T) {
Conditions: []configv1.ClusterOperatorStatusCondition{},
Versions: []configv1.OperandVersion{},
RelatedObjects: []configv1.ObjectReference{
configv1.ObjectReference{
{
Group: "group",
Resource: "resources",
Namespace: "namespace",
Expand All @@ -396,7 +396,7 @@ func TestBuilder(t *testing.T) {
Conditions: []configv1.ClusterOperatorStatusCondition{},
Versions: []configv1.OperandVersion{},
RelatedObjects: []configv1.ObjectReference{
configv1.ObjectReference{
{
Group: "group",
Resource: "resources",
Namespace: "namespace",
Expand Down
6 changes: 3 additions & 3 deletions pkg/lib/operatorstatus/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ func TestMonitorWaiting(t *testing.T) {

statusWant := &configv1.ClusterOperatorStatus{
Conditions: []configv1.ClusterOperatorStatusCondition{
configv1.ClusterOperatorStatusCondition{
{
Type: configv1.OperatorDegraded,
Status: configv1.ConditionFalse,
LastTransitionTime: metav1.NewTime(fakeClock.Now()),
},
configv1.ClusterOperatorStatusCondition{
{
Type: configv1.OperatorAvailable,
Status: configv1.ConditionFalse,
LastTransitionTime: metav1.NewTime(fakeClock.Now()),
},
configv1.ClusterOperatorStatusCondition{
{
Type: configv1.OperatorProgressing,
Status: configv1.ConditionTrue,
Message: fmt.Sprintf("waiting for events - source=%s", name),
Expand Down
6 changes: 3 additions & 3 deletions pkg/lib/proxy/envvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ var (
// As a consumer we should be reading off of proxy.status.
func ToEnvVar(proxy *apiconfigv1.Proxy) []corev1.EnvVar {
return []corev1.EnvVar{
corev1.EnvVar{
{
Name: envHTTPProxyName,
Value: proxy.Status.HTTPProxy,
},
corev1.EnvVar{
{
Name: envHTTPSProxyName,
Value: proxy.Status.HTTPSProxy,
},
corev1.EnvVar{
{
Name: envNoProxyName,
Value: proxy.Status.NoProxy,
},
Expand Down
12 changes: 6 additions & 6 deletions pkg/lib/proxy/envvar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ func TestToEnvVar(t *testing.T) {
},
},
envVarWant: []corev1.EnvVar{
corev1.EnvVar{
{
Name: envHTTPProxyName,
Value: "http://",
},
corev1.EnvVar{
{
Name: envHTTPSProxyName,
Value: "https://",
},
corev1.EnvVar{
{
Name: envNoProxyName,
Value: "foo,bar",
},
Expand All @@ -56,15 +56,15 @@ func TestToEnvVar(t *testing.T) {
},
},
envVarWant: []corev1.EnvVar{
corev1.EnvVar{
{
Name: envHTTPProxyName,
Value: "http://",
},
corev1.EnvVar{
{
Name: envHTTPSProxyName,
Value: "",
},
corev1.EnvVar{
{
Name: envNoProxyName,
Value: "",
},
Expand Down
Loading

0 comments on commit 6b377ca

Please sign in to comment.