Skip to content

Commit 67aa33a

Browse files
Mikalai Radchukm1kola
authored andcommitted
Fixes linting issues
Signed-off-by: Mikalai Radchuk <[email protected]>
1 parent 8c7a35d commit 67aa33a

File tree

19 files changed

+109
-123
lines changed

19 files changed

+109
-123
lines changed

api/v1alpha1/operator_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type OperatorSpec struct {
4040

4141
//+kubebuilder:validation:MaxLength:=48
4242
//+kubebuilder:validation:Pattern:=^[a-z0-9]+([\.-][a-z0-9]+)*$
43-
// Channel constraint defintion
43+
// Channel constraint definition
4444
Channel string `json:"channel,omitempty"`
4545
}
4646

cmd/manager/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ import (
2020
"flag"
2121
"os"
2222

23-
"github.com/operator-framework/deppy/pkg/deppy/solver"
24-
rukpakv1alpha1 "github.com/operator-framework/rukpak/api/v1alpha1"
2523
"github.com/spf13/pflag"
2624
"go.uber.org/zap/zapcore"
2725
"k8s.io/apimachinery/pkg/runtime"
@@ -33,6 +31,9 @@ import (
3331
"sigs.k8s.io/controller-runtime/pkg/log/zap"
3432

3533
catalogd "github.com/operator-framework/catalogd/api/core/v1alpha1"
34+
"github.com/operator-framework/deppy/pkg/deppy/solver"
35+
rukpakv1alpha1 "github.com/operator-framework/rukpak/api/v1alpha1"
36+
3637
operatorsv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
3738
"github.com/operator-framework/operator-controller/internal/controllers"
3839
"github.com/operator-framework/operator-controller/internal/resolution/entitysources"

config/crd/bases/operators.operatorframework.io_operators.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ spec:
3636
description: OperatorSpec defines the desired state of Operator
3737
properties:
3838
channel:
39-
description: Channel constraint defintion
39+
description: Channel constraint definition
4040
maxLength: 48
4141
pattern: ^[a-z0-9]+([\.-][a-z0-9]+)*$
4242
type: string

internal/controllers/operator_controller.go

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ func checkForUnexpectedFieldChange(a, b operatorsv1alpha1.Operator) bool {
107107
}
108108

109109
// Helper function to do the actual reconcile
110+
//
111+
// Today we always return ctrl.Result{} and an error.
112+
// But in the future we might update this function
113+
// to return different results (e.g. requeue).
114+
//
115+
//nolint:unparam
110116
func (r *OperatorReconciler) reconcile(ctx context.Context, op *operatorsv1alpha1.Operator) (ctrl.Result, error) {
111117
// validate spec
112118
if err := validators.ValidateOperatorSpec(op); err != nil {
@@ -348,31 +354,6 @@ func (r *OperatorReconciler) existingBundleDeploymentUnstructured(ctx context.Co
348354
return &unstructured.Unstructured{Object: unstrExistingBundleDeploymentObj}, nil
349355
}
350356

351-
// verifyBDStatus reads the various possibilities of status in bundle deployment and translates
352-
// into corresponding operator condition status and message.
353-
func verifyBDStatus(dep *rukpakv1alpha1.BundleDeployment) (metav1.ConditionStatus, string) {
354-
isValidBundleCond := apimeta.FindStatusCondition(dep.Status.Conditions, rukpakv1alpha1.TypeHasValidBundle)
355-
isInstalledCond := apimeta.FindStatusCondition(dep.Status.Conditions, rukpakv1alpha1.TypeInstalled)
356-
357-
if isValidBundleCond != nil && isValidBundleCond.Status == metav1.ConditionFalse {
358-
return metav1.ConditionFalse, isValidBundleCond.Message
359-
}
360-
361-
if isInstalledCond != nil && isInstalledCond.Status == metav1.ConditionFalse {
362-
return metav1.ConditionFalse, isInstalledCond.Message
363-
}
364-
365-
if isInstalledCond != nil && isInstalledCond.Status == metav1.ConditionTrue {
366-
return metav1.ConditionTrue, "install was successful"
367-
}
368-
return metav1.ConditionUnknown, fmt.Sprintf("could not determine the state of BundleDeployment %s", dep.Name)
369-
}
370-
371-
// isBundleDepStale returns true if conditions are out of date.
372-
func isBundleDepStale(bd *rukpakv1alpha1.BundleDeployment) bool {
373-
return bd != nil && bd.Status.ObservedGeneration != bd.GetGeneration()
374-
}
375-
376357
// mapBundleMediaTypeToBundleProvisioner maps an olm.bundle.mediatype property to a
377358
// rukpak bundle provisioner class name that is capable of unpacking the bundle type
378359
func mapBundleMediaTypeToBundleProvisioner(mediaType string) (string, error) {

internal/controllers/operator_controller_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,8 +1061,7 @@ var _ = Describe("Operator Controller Test", func() {
10611061

10621062
func verifyInvariants(ctx context.Context, c client.Client, op *operatorsv1alpha1.Operator) {
10631063
key := client.ObjectKeyFromObject(op)
1064-
err := c.Get(ctx, key, op)
1065-
Expect(err).To(BeNil())
1064+
Expect(c.Get(ctx, key, op)).To(Succeed())
10661065

10671066
verifyConditionsInvariants(op)
10681067
}

internal/controllers/suite_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ var _ = AfterSuite(func() {
9494
})
9595

9696
func namesFromList(list client.ObjectList) []string {
97-
var names []string
98-
9997
items, err := meta.ExtractList(list)
10098
Expect(err).NotTo(HaveOccurred())
99+
100+
names := make([]string, 0, len(items))
101101
for _, item := range items {
102102
names = append(names, item.(client.Object).GetName())
103103
}

internal/resolution/entitysources/catalogdsource.go

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,67 +5,66 @@ import (
55
"encoding/json"
66
"fmt"
77

8+
catalogd "github.com/operator-framework/catalogd/api/core/v1alpha1"
89
"github.com/operator-framework/deppy/pkg/deppy"
910
"github.com/operator-framework/deppy/pkg/deppy/input"
10-
"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/entity"
1111
"github.com/operator-framework/operator-registry/alpha/property"
1212
"sigs.k8s.io/controller-runtime/pkg/client"
1313

14-
catalogd "github.com/operator-framework/catalogd/api/core/v1alpha1"
14+
"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/entity"
1515
)
1616

17-
// catalogdEntitySource is a source for(/collection of) deppy defined input.Entity, built from content
17+
// CatalogdEntitySource is a source for(/collection of) deppy defined input.Entity, built from content
1818
// made accessible on-cluster by https://github.com/operator-framework/catalogd.
1919
// It is an implementation of deppy defined input.EntitySource
20-
type catalogdEntitySource struct {
20+
type CatalogdEntitySource struct {
2121
client client.Client
2222
}
2323

24-
func NewCatalogdEntitySource(client client.Client) *catalogdEntitySource {
25-
26-
return &catalogdEntitySource{client: client}
24+
func NewCatalogdEntitySource(client client.Client) *CatalogdEntitySource {
25+
return &CatalogdEntitySource{client: client}
2726
}
2827

29-
func (es *catalogdEntitySource) Get(ctx context.Context, id deppy.Identifier) (*input.Entity, error) {
28+
func (es *CatalogdEntitySource) Get(_ context.Context, _ deppy.Identifier) (*input.Entity, error) {
3029
panic("not implemented")
3130
}
3231

33-
func (es *catalogdEntitySource) Filter(ctx context.Context, filter input.Predicate) (input.EntityList, error) {
32+
func (es *CatalogdEntitySource) Filter(ctx context.Context, filter input.Predicate) (input.EntityList, error) {
3433
resultSet := input.EntityList{}
3534
entities, err := getEntities(ctx, es.client)
3635
if err != nil {
3736
return nil, err
3837
}
39-
for _, entity := range entities {
40-
if filter(&entity) {
41-
resultSet = append(resultSet, entity)
38+
for i := range entities {
39+
if filter(&entities[i]) {
40+
resultSet = append(resultSet, entities[i])
4241
}
4342
}
4443
return resultSet, nil
4544
}
4645

47-
func (es *catalogdEntitySource) GroupBy(ctx context.Context, fn input.GroupByFunction) (input.EntityListMap, error) {
46+
func (es *CatalogdEntitySource) GroupBy(ctx context.Context, fn input.GroupByFunction) (input.EntityListMap, error) {
4847
entities, err := getEntities(ctx, es.client)
4948
if err != nil {
5049
return nil, err
5150
}
5251
resultSet := input.EntityListMap{}
53-
for _, entity := range entities {
54-
keys := fn(&entity)
52+
for i := range entities {
53+
keys := fn(&entities[i])
5554
for _, key := range keys {
56-
resultSet[key] = append(resultSet[key], entity)
55+
resultSet[key] = append(resultSet[key], entities[i])
5756
}
5857
}
5958
return resultSet, nil
6059
}
6160

62-
func (es *catalogdEntitySource) Iterate(ctx context.Context, fn input.IteratorFunction) error {
61+
func (es *CatalogdEntitySource) Iterate(ctx context.Context, fn input.IteratorFunction) error {
6362
entities, err := getEntities(ctx, es.client)
6463
if err != nil {
6564
return err
6665
}
67-
for _, entity := range entities {
68-
if err := fn(&entity); err != nil {
66+
for i := range entities {
67+
if err := fn(&entities[i]); err != nil {
6968
return err
7069
}
7170
}

internal/resolution/resolver_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ var _ = Describe("OperatorResolver", func() {
9999
resolver := solver.NewDeppySolver(entitySource, variableSource)
100100
solution, err := resolver.Solve(context.Background())
101101
Expect(err).ToNot(HaveOccurred())
102-
Expect(solution.SelectedVariables()).To(HaveLen(0))
102+
Expect(solution.SelectedVariables()).To(BeEmpty())
103103
})
104104

105105
It("should return an error if the entity source throws an error", func() {
@@ -135,19 +135,19 @@ var _ input.EntitySource = &FailEntitySource{}
135135

136136
type FailEntitySource struct{}
137137

138-
func (f FailEntitySource) Get(ctx context.Context, id deppy.Identifier) (*input.Entity, error) {
138+
func (f FailEntitySource) Get(_ context.Context, _ deppy.Identifier) (*input.Entity, error) {
139139
return nil, fmt.Errorf("error calling get in entity source")
140140
}
141141

142-
func (f FailEntitySource) Filter(ctx context.Context, filter input.Predicate) (input.EntityList, error) {
142+
func (f FailEntitySource) Filter(_ context.Context, _ input.Predicate) (input.EntityList, error) {
143143
return nil, fmt.Errorf("error calling filter in entity source")
144144
}
145145

146-
func (f FailEntitySource) GroupBy(ctx context.Context, fn input.GroupByFunction) (input.EntityListMap, error) {
146+
func (f FailEntitySource) GroupBy(_ context.Context, _ input.GroupByFunction) (input.EntityListMap, error) {
147147
return nil, fmt.Errorf("error calling group by in entity source")
148148
}
149149

150-
func (f FailEntitySource) Iterate(ctx context.Context, fn input.IteratorFunction) error {
150+
func (f FailEntitySource) Iterate(_ context.Context, _ input.IteratorFunction) error {
151151
return fmt.Errorf("error calling iterate in entity source")
152152
}
153153

@@ -165,30 +165,30 @@ func NewFailClientWithError(err error) client.Client {
165165
}
166166
}
167167

168-
func (f FailClient) Get(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error {
168+
func (f FailClient) Get(_ context.Context, _ client.ObjectKey, _ client.Object, _ ...client.GetOption) error {
169169
return f.err
170170
}
171171

172-
func (f FailClient) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error {
172+
func (f FailClient) List(_ context.Context, _ client.ObjectList, _ ...client.ListOption) error {
173173
return f.err
174174
}
175175

176-
func (f FailClient) Create(ctx context.Context, obj client.Object, opts ...client.CreateOption) error {
176+
func (f FailClient) Create(_ context.Context, _ client.Object, _ ...client.CreateOption) error {
177177
return f.err
178178
}
179179

180-
func (f FailClient) Delete(ctx context.Context, obj client.Object, opts ...client.DeleteOption) error {
180+
func (f FailClient) Delete(_ context.Context, _ client.Object, _ ...client.DeleteOption) error {
181181
return f.err
182182
}
183183

184-
func (f FailClient) Update(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error {
184+
func (f FailClient) Update(_ context.Context, _ client.Object, _ ...client.UpdateOption) error {
185185
return f.err
186186
}
187187

188-
func (f FailClient) Patch(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.PatchOption) error {
188+
func (f FailClient) Patch(_ context.Context, _ client.Object, _ client.Patch, _ ...client.PatchOption) error {
189189
return f.err
190190
}
191191

192-
func (f FailClient) DeleteAllOf(ctx context.Context, obj client.Object, opts ...client.DeleteAllOfOption) error {
192+
func (f FailClient) DeleteAllOf(_ context.Context, _ client.Object, _ ...client.DeleteAllOfOption) error {
193193
return f.err
194194
}

internal/resolution/variable_sources/bundles_and_dependencies/bundles_and_dependencies.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func (b *BundleVariable) Dependencies() []*olmentity.BundleEntity {
3131
}
3232

3333
func NewBundleVariable(bundleEntity *olmentity.BundleEntity, dependencyBundleEntities []*olmentity.BundleEntity) *BundleVariable {
34-
var dependencyIDs []deppy.Identifier
34+
dependencyIDs := make([]deppy.Identifier, 0, len(dependencyBundleEntities))
3535
for _, bundle := range dependencyBundleEntities {
3636
dependencyIDs = append(dependencyIDs, bundle.ID)
3737
}

internal/resolution/variable_sources/bundles_and_dependencies/bundles_and_dependencies_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ var _ = Describe("BundlesAndDepsVariableSource", func() {
199199
bundleVariables = append(bundleVariables, v)
200200
}
201201
}
202-
Expect(len(bundleVariables)).To(Equal(12))
202+
Expect(bundleVariables).To(HaveLen(12))
203203
Expect(bundleVariables).To(WithTransform(CollectBundleVariableIDs, Equal([]string{"bundle-2", "bundle-1", "bundle-15", "bundle-16", "bundle-17", "bundle-9", "bundle-8", "bundle-7", "bundle-5", "bundle-4", "bundle-11", "bundle-10"})))
204204

205205
// check dependencies for one of the bundles
@@ -244,7 +244,7 @@ type MockRequiredPackageSource struct {
244244
ResultSet []deppy.Variable
245245
}
246246

247-
func (m *MockRequiredPackageSource) GetVariables(ctx context.Context, entitySource input.EntitySource) ([]deppy.Variable, error) {
247+
func (m *MockRequiredPackageSource) GetVariables(_ context.Context, _ input.EntitySource) ([]deppy.Variable, error) {
248248
return m.ResultSet, nil
249249
}
250250

@@ -260,15 +260,15 @@ func VariableWithID(id deppy.Identifier) func(vars []*bundles_and_dependencies.B
260260
}
261261

262262
func CollectBundleVariableIDs(vars []*bundles_and_dependencies.BundleVariable) []string {
263-
var ids []string
263+
ids := make([]string, 0, len(vars))
264264
for _, v := range vars {
265265
ids = append(ids, v.Identifier().String())
266266
}
267267
return ids
268268
}
269269

270270
func CollectDeppyEntities(vars []*olmentity.BundleEntity) []*input.Entity {
271-
var entities []*input.Entity
271+
entities := make([]*input.Entity, 0, len(vars))
272272
for _, v := range vars {
273273
entities = append(entities, v.Entity)
274274
}

0 commit comments

Comments
 (0)