Skip to content

Commit 8cfce79

Browse files
authored
Fix golangci-lint v2 linting errors (#248)
* Update .golangci.yaml for v2 * Use convenience methods on GinkgoWriter for priting test logs * Resolve duplicate imports * Remove embedded fields from selectors * Ignore dot-imports in tests package * Check error when closing logstream * Update CHANGELOG.md
1 parent 202056d commit 8cfce79

12 files changed

+52
-41
lines changed

.golangci.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
version: 2
2+
linters:
3+
exclusions:
4+
rules:
5+
- path: _test\.go
6+
linters:
7+
- gosec
8+
- goconst
9+
- path: tests/
10+
# ST1001: should not use dot imports # gomega is designed to be dot-imported.
11+
text: ST1001
12+
# v1 config, remove when golangci-lint v2 is active
113
issues:
214
exclude-rules:
315
- path: _test\.go

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Dynamically calculate CAPI and CAPA versions from go cache, so that we use the right path when installing the CRDs during tests.
1313

14+
### Fixed
15+
16+
- Resolve several linting errors.
17+
1418
## [0.17.0] - 2024-09-30
1519

1620
### Changed

controllers/management_cluster_network_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
. "github.com/onsi/gomega/gstruct"
1313
corev1 "k8s.io/api/core/v1"
1414
k8serrors "k8s.io/apimachinery/pkg/api/errors"
15-
"k8s.io/apimachinery/pkg/types"
1615
k8stypes "k8s.io/apimachinery/pkg/types"
1716
capa "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
1817
capi "sigs.k8s.io/cluster-api/api/v1beta1"
@@ -268,7 +267,7 @@ var _ = Describe("ManagementClusterTransitGatewayReconciler", func() {
268267
})
269268

270269
It("removes the finalizer", func() {
271-
err := k8sClient.Get(context.Background(), types.NamespacedName{Name: cluster.Name, Namespace: namespace}, cluster)
270+
err := k8sClient.Get(context.Background(), k8stypes.NamespacedName{Name: cluster.Name, Namespace: namespace}, cluster)
272271
Expect(k8serrors.IsNotFound(err)).To(BeTrue())
273272
})
274273

controllers/package.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ func predicateToFilterAWSClusterResourceVersionChanges(e event.UpdateEvent) bool
116116
oldCluster.Status = capa.AWSClusterStatus{}
117117
newCluster.Status = capa.AWSClusterStatus{}
118118

119-
oldCluster.ObjectMeta.ResourceVersion = ""
120-
newCluster.ObjectMeta.ResourceVersion = ""
119+
oldCluster.ResourceVersion = ""
120+
newCluster.ResourceVersion = ""
121121

122122
return !cmp.Equal(oldCluster, newCluster)
123123
}
@@ -135,8 +135,8 @@ func predicateToFilterAWSManagedControlPlaneResourceVersionChanges(e event.Updat
135135
oldCluster.Status = eks.AWSManagedControlPlaneStatus{}
136136
newCluster.Status = eks.AWSManagedControlPlaneStatus{}
137137

138-
oldCluster.ObjectMeta.ResourceVersion = ""
139-
newCluster.ObjectMeta.ResourceVersion = ""
138+
oldCluster.ResourceVersion = ""
139+
newCluster.ResourceVersion = ""
140140

141141
return !cmp.Equal(oldCluster, newCluster)
142142
}

controllers/prefix_list_entry_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
. "github.com/onsi/gomega/gstruct"
1414
corev1 "k8s.io/api/core/v1"
1515
k8serrors "k8s.io/apimachinery/pkg/api/errors"
16-
"k8s.io/apimachinery/pkg/types"
1716
k8stypes "k8s.io/apimachinery/pkg/types"
1817
capa "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
1918
capi "sigs.k8s.io/cluster-api/api/v1beta1"
@@ -83,7 +82,7 @@ var _ = Describe("PrefixListEntryReconciler", func() {
8382

8483
JustBeforeEach(func() {
8584
request = ctrl.Request{
86-
NamespacedName: types.NamespacedName{
85+
NamespacedName: k8stypes.NamespacedName{
8786
Name: requestResourceName,
8887
Namespace: namespace,
8988
},
@@ -218,7 +217,7 @@ var _ = Describe("PrefixListEntryReconciler", func() {
218217
})
219218

220219
It("removes the finalizer", func() {
221-
err := k8sClient.Get(context.Background(), types.NamespacedName{Name: cluster.Name, Namespace: namespace}, cluster)
220+
err := k8sClient.Get(context.Background(), k8stypes.NamespacedName{Name: cluster.Name, Namespace: namespace}, cluster)
222221
Expect(k8serrors.IsNotFound(err)).To(BeTrue())
223222
})
224223

controllers/route_controller_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
. "github.com/onsi/ginkgo/v2"
1010
. "github.com/onsi/gomega"
1111
k8serrors "k8s.io/apimachinery/pkg/api/errors"
12-
"k8s.io/apimachinery/pkg/types"
1312
k8stypes "k8s.io/apimachinery/pkg/types"
1413
capa "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
1514
ctrl "sigs.k8s.io/controller-runtime"
@@ -65,7 +64,7 @@ var _ = Describe("RouteReconciler", func() {
6564
annotation.NetworkTopologyModeGiantSwarmManaged,
6665
)
6766

68-
reconciler = controllers.NewRouteReconciler(types.NamespacedName{Namespace: managementCluster.Namespace, Name: managementCluster.Name}, clusterClient, clientsFactory)
67+
reconciler = controllers.NewRouteReconciler(k8stypes.NamespacedName{Namespace: managementCluster.Namespace, Name: managementCluster.Name}, clusterClient, clientsFactory)
6968

7069
awsClusterRoleIdentity, awsCluster = createRandomClusterWithIdentity(
7170
annotation.NetworkTopologyModeAnnotation,
@@ -183,7 +182,7 @@ var _ = Describe("RouteReconciler", func() {
183182
routeTableClient.RemoveRoutesReturns(nil)
184183
})
185184
It("It removes the finalizer", func() {
186-
err := k8sClient.Get(context.Background(), types.NamespacedName{Name: awsCluster.Name, Namespace: namespace}, awsCluster)
185+
err := k8sClient.Get(context.Background(), k8stypes.NamespacedName{Name: awsCluster.Name, Namespace: namespace}, awsCluster)
187186
Expect(k8serrors.IsNotFound(err)).To(BeTrue())
188187
})
189188
})

controllers/share.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/aws/aws-sdk-go/aws/arn"
99
"github.com/giantswarm/k8smetadata/pkg/annotation"
1010
"github.com/pkg/errors"
11-
"k8s.io/apimachinery/pkg/types"
1211
k8stypes "k8s.io/apimachinery/pkg/types"
1312
capa "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
1413
ctrl "sigs.k8s.io/controller-runtime"
@@ -32,7 +31,7 @@ type ShareReconciler struct {
3231
}
3332

3433
func NewShareReconciler(
35-
managementCluster types.NamespacedName,
34+
managementCluster k8stypes.NamespacedName,
3635
clusterClient AWSClusterClient,
3736
awsClients resolver.AWSClients,
3837
) *ShareReconciler {

controllers/share_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"errors"
66
"fmt"
77

8-
"github.com/giantswarm/k8smetadata/pkg/annotation"
98
gsannotation "github.com/giantswarm/k8smetadata/pkg/annotation"
109
"github.com/google/uuid"
1110
. "github.com/onsi/ginkgo/v2"
@@ -56,11 +55,11 @@ var _ = Describe("Share", func() {
5655
Expect(err).NotTo(HaveOccurred())
5756

5857
_, managementCluster = createRandomClusterWithIdentity(
59-
annotation.NetworkTopologyModeAnnotation,
60-
annotation.NetworkTopologyModeGiantSwarmManaged,
61-
annotation.NetworkTopologyTransitGatewayIDAnnotation,
58+
gsannotation.NetworkTopologyModeAnnotation,
59+
gsannotation.NetworkTopologyModeGiantSwarmManaged,
60+
gsannotation.NetworkTopologyTransitGatewayIDAnnotation,
6261
transitGatewayARN,
63-
annotation.NetworkTopologyPrefixListIDAnnotation,
62+
gsannotation.NetworkTopologyPrefixListIDAnnotation,
6463
prefixListARN,
6564
)
6665

@@ -247,8 +246,8 @@ var _ = Describe("Share", func() {
247246
wcTransitGatewayARN = fmt.Sprintf("arn:aws:iam::123456789012:transit-gateways/%s", uuid.NewString())
248247
wcPrefixListARN = fmt.Sprintf("arn:aws:iam::123456789012:prefix-lists/%s", uuid.NewString())
249248
patchedCluster := cluster.DeepCopy()
250-
patchedCluster.Annotations[annotation.NetworkTopologyTransitGatewayIDAnnotation] = wcTransitGatewayARN
251-
patchedCluster.Annotations[annotation.NetworkTopologyPrefixListIDAnnotation] = wcPrefixListARN
249+
patchedCluster.Annotations[gsannotation.NetworkTopologyTransitGatewayIDAnnotation] = wcTransitGatewayARN
250+
patchedCluster.Annotations[gsannotation.NetworkTopologyPrefixListIDAnnotation] = wcPrefixListARN
252251
err := k8sClient.Patch(context.Background(), patchedCluster, client.MergeFrom(cluster))
253252
Expect(err).NotTo(HaveOccurred())
254253
})

controllers/transit_gateway_attachment_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
. "github.com/onsi/gomega/gstruct"
1414
corev1 "k8s.io/api/core/v1"
1515
k8serrors "k8s.io/apimachinery/pkg/api/errors"
16-
"k8s.io/apimachinery/pkg/types"
1716
k8stypes "k8s.io/apimachinery/pkg/types"
1817
capa "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
1918
capi "sigs.k8s.io/cluster-api/api/v1beta1"
@@ -350,7 +349,7 @@ var _ = Describe("TransitGatewayAttachment", func() {
350349
})
351350

352351
It("removes the finalizer", func() {
353-
err := k8sClient.Get(context.Background(), types.NamespacedName{Name: cluster.Name, Namespace: namespace}, cluster)
352+
err := k8sClient.Get(context.Background(), k8stypes.NamespacedName{Name: cluster.Name, Namespace: namespace}, cluster)
354353
Expect(k8serrors.IsNotFound(err)).To(BeTrue())
355354
})
356355

pkg/aws/prefixlist.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66
"net"
77

8-
"github.com/aws/aws-sdk-go/aws"
98
awssdk "github.com/aws/aws-sdk-go/aws"
109
"github.com/aws/aws-sdk-go/service/ec2"
1110
"github.com/pkg/errors"
@@ -106,8 +105,8 @@ func (t *PrefixLists) getByName(ctx context.Context, name string) (*ec2.ManagedP
106105
input := &ec2.DescribeManagedPrefixListsInput{
107106
Filters: []*ec2.Filter{
108107
{
109-
Name: aws.String(prefixListNameFilter),
110-
Values: aws.StringSlice([]string{GetPrefixListName(name)}),
108+
Name: awssdk.String(prefixListNameFilter),
109+
Values: awssdk.StringSlice([]string{GetPrefixListName(name)}),
111110
},
112111
},
113112
}
@@ -151,7 +150,7 @@ func (t *PrefixLists) create(ctx context.Context, name string, tags map[string]s
151150
if len(ec2Tags) != 0 {
152151
input.TagSpecifications = []*ec2.TagSpecification{
153152
{
154-
ResourceType: aws.String(ec2.ResourceTypePrefixList),
153+
ResourceType: awssdk.String(ec2.ResourceTypePrefixList),
155154
Tags: ec2Tags,
156155
},
157156
}

0 commit comments

Comments
 (0)