Skip to content
This repository was archived by the owner on Oct 28, 2024. It is now read-only.

Commit d2f95df

Browse files
authored
Merge pull request #90 from christopherhein/chore/golangci-cleanup-excludes
🌱 Upgrade Golang CI & Fix Lint
2 parents f535029 + 5deaa15 commit d2f95df

39 files changed

+1283
-674
lines changed

.golangci.yml

Lines changed: 112 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,122 @@
11
linters:
2-
enable-all: true
3-
disable:
4-
- dupl
5-
- funlen
6-
- gochecknoglobals
7-
- gochecknoinits
8-
- lll
9-
- godox
10-
- wsl
11-
- whitespace
12-
- gocognit
13-
- gomnd
14-
- interfacer
15-
- godot
16-
- goerr113
17-
- nestif
18-
# Run with --fast=false for more extensive checks
19-
fast: true
2+
disable-all: true
3+
enable:
4+
- asciicheck
5+
- bodyclose
6+
- deadcode
7+
- depguard
8+
- dogsled
9+
- exportloopref
10+
- errcheck
11+
- goconst
12+
- gocritic
13+
- gocyclo
14+
- godot
15+
- gofmt
16+
- goimports
17+
- goprintffuncname
18+
- gosec
19+
- gosimple
20+
- govet
21+
- importas
22+
- ineffassign
23+
- misspell
24+
- nakedret
25+
- nolintlint
26+
- prealloc
27+
- revive
28+
- rowserrcheck
29+
- staticcheck
30+
- structcheck
31+
- stylecheck
32+
- typecheck
33+
- unconvert
34+
- unparam
35+
- varcheck
36+
- whitespace
37+
38+
linters-settings:
39+
staticcheck:
40+
go: "1.16"
41+
stylecheck:
42+
go: "1.16"
43+
importas:
44+
no-unaliased: true
45+
alias:
46+
# Kubernetes
47+
- pkg: k8s.io/api/core/v1
48+
alias: corev1
49+
- pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
50+
alias: apiextensionsv1
51+
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
52+
alias: metav1
53+
- pkg: k8s.io/apimachinery/pkg/api/errors
54+
alias: apierrors
55+
- pkg: k8s.io/apimachinery/pkg/util/errors
56+
alias: kerrors
57+
# Controller Runtime
58+
- pkg: sigs.k8s.io/controller-runtime
59+
alias: ctrl
60+
2061
issues:
2162
max-same-issues: 0
2263
max-issues-per-linter: 0
64+
# We are disabling default golangci exclusions because we want to help reviewers to focus on reviewing the most relevant
65+
# changes in PRs and avoid nitpicking.
66+
exclude-use-default: false
2367
# List of regexps of issue texts to exclude, empty list by default.
2468
exclude:
25-
- Using the variable on range scope `(tc)|(rt)|(tt)|(test)|(testcase)|(testCase)` in function literal
26-
- "G108: Profiling endpoint is automatically exposed on /debug/pprof"
69+
- "G108: Profiling endpoint is automatically exposed on /debug/pprof"
70+
- Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
71+
- "exported: exported method .*\\.(Reconcile|SetupWithManager|SetupWebhookWithManager) should have comment or be unexported"
72+
# The following are being worked on to remove their exclusion. This list should be reduced or go away all together over time.
73+
# If it is decided they will not be addressed they should be moved above this comment.
74+
- Subprocess launch(ed with variable|ing should be audited)
75+
- (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)
76+
- (G104|G307)
77+
exclude-rules:
78+
# With Go 1.16, the new embed directive can be used with an un-named import,
79+
# revive (previously, golint) only allows these to be imported in a main.go, which wouldn't work for us.
80+
# This directive allows the embed package to be imported with an underscore everywhere.
81+
- linters:
82+
- revive
83+
source: _ "embed"
84+
# Exclude some packages or code to require comments, for example test code, or fake clients.
85+
- linters:
86+
- revive
87+
text: exported (method|function|type|const) (.+) should have comment or be unexported
88+
source: (func|type).*Fake.*
89+
- linters:
90+
- revive
91+
text: exported (method|function|type|const) (.+) should have comment or be unexported
92+
path: fake_\.go
93+
- linters:
94+
- revive
95+
text: exported (method|function|type|const) (.+) should have comment or be unexported
96+
path: .*test/(providers|framework|e2e).*.go
97+
# Disable unparam "always receives" which might not be really
98+
# useful when building libraries.
99+
- linters:
100+
- unparam
101+
text: always receives
102+
# Dot imports for gomega or ginkgo are allowed
103+
# within test files.
104+
- path: _test\.go
105+
text: should not use dot imports
106+
- path: _test\.go
107+
text: cyclomatic complexity
108+
- path: test/(framework|e2e).*.go
109+
text: should not use dot imports
110+
# Append should be able to assign to a different var/slice.
111+
- linters:
112+
- gocritic
113+
text: "appendAssign: append result not assigned to the same slice"
114+
27115
run:
28116
timeout: 10m
29117
skip-files:
30-
- "zz_generated.*\\.go$"
31-
- ".*conversion.*\\.go$"
118+
- "zz_generated.*\\.go$"
119+
- ".*conversion.*\\.go$"
32120
skip-dirs:
33-
- third_party
121+
- third_party
122+
allow-parallel-runners: true

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,10 @@ manager-nested-controlplane: ## Build manager binary
112112
$(CONTROLLER_GEN): $(TOOLS_DIR)/go.mod # Build controller-gen from tools folder.
113113
cd $(TOOLS_DIR); go build -tags=tools -o $(BIN_DIR)/controller-gen sigs.k8s.io/controller-tools/cmd/controller-gen
114114

115-
$(GOLANGCI_LINT): $(TOOLS_DIR)/go.mod # Build golangci-lint from tools folder.
116-
cd $(TOOLS_DIR); go build -tags=tools -o $(BIN_DIR)/golangci-lint github.com/golangci/golangci-lint/cmd/golangci-lint
115+
$(GOLANGCI_LINT): # Download golanci-lint using hack script into tools folder.
116+
hack/ensure-golangci-lint.sh \
117+
-b $(TOOLS_DIR)/$(BIN_DIR) \
118+
v1.40.1
117119

118120
$(RELEASE_NOTES): $(TOOLS_DIR)/go.mod
119121
cd $(TOOLS_DIR) && go build -tags=tools -o $(RELEASE_NOTES_BIN) sigs.k8s.io/cluster-api/hack/tools/release

api/v1alpha4/groupversion_info.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
// Package v1alpha4 contains API Schema definitions for the infrastructure v1alpha4 API group
18-
//+kubebuilder:object:generate=true
19-
//+groupName=infrastructure.cluster.x-k8s.io
17+
// Package v1alpha4 contains API Schema definitions for the infrastructure v1alpha4 API group.
18+
// +kubebuilder:object:generate=true
19+
// +groupName=infrastructure.cluster.x-k8s.io
2020
package v1alpha4
2121

2222
import (
@@ -25,10 +25,10 @@ import (
2525
)
2626

2727
var (
28-
// GroupVersion is group version used to register these objects
28+
// GroupVersion is group version used to register these objects.
2929
GroupVersion = schema.GroupVersion{Group: "infrastructure.cluster.x-k8s.io", Version: "v1alpha4"}
3030

31-
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
31+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
3232
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
3333

3434
// AddToScheme adds the types in this group-version to the given scheme.

api/v1alpha4/nestedcluster_types.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ import (
2121
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
2222
)
2323

24-
// NestedClusterSpec defines the desired state of NestedCluster
24+
// NestedClusterSpec defines the desired state of NestedCluster.
2525
type NestedClusterSpec struct {
2626
// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
2727
// +optional
2828
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`
2929
}
3030

31-
// NestedClusterStatus defines the observed state of NestedCluster
31+
// NestedClusterStatus defines the observed state of NestedCluster.
3232
type NestedClusterStatus struct {
3333
// Ready is when the NestedControlPlane has a API server URL.
3434
// +optional
@@ -41,7 +41,7 @@ type NestedClusterStatus struct {
4141
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
4242
//+kubebuilder:subresource:status
4343

44-
// NestedCluster is the Schema for the nestedclusters API
44+
// NestedCluster is the Schema for the nestedclusters API.
4545
type NestedCluster struct {
4646
metav1.TypeMeta `json:",inline"`
4747
metav1.ObjectMeta `json:"metadata,omitempty"`
@@ -52,7 +52,7 @@ type NestedCluster struct {
5252

5353
//+kubebuilder:object:root=true
5454

55-
// NestedClusterList contains a list of NestedCluster
55+
// NestedClusterList contains a list of NestedCluster.
5656
type NestedClusterList struct {
5757
metav1.TypeMeta `json:",inline"`
5858
metav1.ListMeta `json:"metadata,omitempty"`

config/crd/bases/infrastructure.cluster.x-k8s.io_nestedclusters.yaml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
44
kind: CustomResourceDefinition
55
metadata:
66
annotations:
7-
controller-gen.kubebuilder.io/version: v0.4.1-0.20201002000720-57250aac17f6
7+
controller-gen.kubebuilder.io/version: v0.6.0-beta.0
88
creationTimestamp: null
99
name: nestedclusters.infrastructure.cluster.x-k8s.io
1010
spec:
@@ -31,21 +31,26 @@ spec:
3131
name: v1alpha4
3232
schema:
3333
openAPIV3Schema:
34-
description: NestedCluster is the Schema for the nestedclusters API
34+
description: NestedCluster is the Schema for the nestedclusters API.
3535
properties:
3636
apiVersion:
37-
description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
37+
description: 'APIVersion defines the versioned schema of this representation
38+
of an object. Servers should convert recognized schemas to the latest
39+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
3840
type: string
3941
kind:
40-
description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
42+
description: 'Kind is a string value representing the REST resource this
43+
object represents. Servers may infer this from the endpoint the client
44+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
4145
type: string
4246
metadata:
4347
type: object
4448
spec:
45-
description: NestedClusterSpec defines the desired state of NestedCluster
49+
description: NestedClusterSpec defines the desired state of NestedCluster.
4650
properties:
4751
controlPlaneEndpoint:
48-
description: ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
52+
description: ControlPlaneEndpoint represents the endpoint used to
53+
communicate with the control plane.
4954
properties:
5055
host:
5156
description: The hostname on which the API server is serving.
@@ -60,10 +65,11 @@ spec:
6065
type: object
6166
type: object
6267
status:
63-
description: NestedClusterStatus defines the observed state of NestedCluster
68+
description: NestedClusterStatus defines the observed state of NestedCluster.
6469
properties:
6570
ready:
66-
description: Ready is when the NestedControlPlane has a API server URL.
71+
description: Ready is when the NestedControlPlane has a API server
72+
URL.
6773
type: boolean
6874
type: object
6975
type: object

controllers/nestedcluster_controller.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
// Package controllers contains all the Infrastructure group controllers for
18+
// running nested clusters.
1719
package controllers
1820

1921
import (
@@ -37,7 +39,7 @@ import (
3739
//+kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=nestedclusters/finalizers,verbs=update
3840
//+kubebuilder:rbac:groups=controlplane.cluster.x-k8s.io,resources=nestedcontrolplanes,verbs=get;list;watch
3941

40-
// NestedClusterReconciler reconciles a NestedCluster object
42+
// NestedClusterReconciler reconciles a NestedCluster object.
4143
type NestedClusterReconciler struct {
4244
client.Client
4345
Log logr.Logger

controlplane/nested/api/v1alpha4/groupversion_info.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
// Package v1alpha4 contains API Schema definitions for the controlplane v1alpha4 API group
17+
// Package v1alpha4 contains API Schema definitions for the controlplane v1alpha4 API group.
1818
// +kubebuilder:object:generate=true
1919
// +groupName=controlplane.cluster.x-k8s.io
2020
package v1alpha4
@@ -25,10 +25,10 @@ import (
2525
)
2626

2727
var (
28-
// GroupVersion is group version used to register these objects
28+
// GroupVersion is group version used to register these objects.
2929
GroupVersion = schema.GroupVersion{Group: "controlplane.cluster.x-k8s.io", Version: "v1alpha4"}
3030

31-
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
31+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
3232
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
3333

3434
// AddToScheme adds the types in this group-version to the given scheme.

controlplane/nested/api/v1alpha4/nestedapiserver_types.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@ import (
2222
addonv1alpha1 "sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/addon/pkg/apis/v1alpha1"
2323
)
2424

25-
// NestedAPIServerSpec defines the desired state of NestedAPIServer
25+
// NestedAPIServerSpec defines the desired state of NestedAPIServer.
2626
type NestedAPIServerSpec struct {
2727
// NestedComponentSpec contains the common and user-specified information that are
28-
// required for creating the component
28+
// required for creating the component.
2929
// +optional
3030
NestedComponentSpec `json:",inline"`
3131
}
3232

33-
// NestedAPIServerStatus defines the observed state of NestedAPIServer
33+
// NestedAPIServerStatus defines the observed state of NestedAPIServer.
3434
type NestedAPIServerStatus struct {
35-
// APIServerService is the reference to the service that expose the APIServer
35+
// APIServerService is the reference to the service that expose the APIServer.
3636
// +optional
3737
APIServerService *corev1.ObjectReference `json:"apiserverService,omitempty"`
3838

39-
// CommonStatus allows addons status monitoring
39+
// CommonStatus allows addons status monitoring.
4040
addonv1alpha1.CommonStatus `json:",inline"`
4141
}
4242

@@ -46,7 +46,7 @@ type NestedAPIServerStatus struct {
4646
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
4747
//+kubebuilder:subresource:status
4848

49-
// NestedAPIServer is the Schema for the nestedapiservers API
49+
// NestedAPIServer is the Schema for the nestedapiservers API.
5050
type NestedAPIServer struct {
5151
metav1.TypeMeta `json:",inline"`
5252
metav1.ObjectMeta `json:"metadata,omitempty"`
@@ -57,7 +57,7 @@ type NestedAPIServer struct {
5757

5858
//+kubebuilder:object:root=true
5959

60-
// NestedAPIServerList contains a list of NestedAPIServer
60+
// NestedAPIServerList contains a list of NestedAPIServer.
6161
type NestedAPIServerList struct {
6262
metav1.TypeMeta `json:",inline"`
6363
metav1.ListMeta `json:"metadata,omitempty"`
@@ -72,30 +72,30 @@ var _ addonv1alpha1.CommonObject = &NestedAPIServer{}
7272
var _ addonv1alpha1.Patchable = &NestedAPIServer{}
7373

7474
// ComponentName returns the name of the component for use with
75-
// addonv1alpha1.CommonObject
75+
// addonv1alpha1.CommonObject.
7676
func (c *NestedAPIServer) ComponentName() string {
7777
return string(APIServer)
7878
}
7979

8080
// CommonSpec returns the addons spec of the object allowing common funcs like
81-
// Channel & Version to be usable
81+
// Channel & Version to be usable.
8282
func (c *NestedAPIServer) CommonSpec() addonv1alpha1.CommonSpec {
8383
return c.Spec.CommonSpec
8484
}
8585

8686
// GetCommonStatus will return the common status for checking is a component
87-
// was successfully deployed
87+
// was successfully deployed.
8888
func (c *NestedAPIServer) GetCommonStatus() addonv1alpha1.CommonStatus {
8989
return c.Status.CommonStatus
9090
}
9191

9292
// SetCommonStatus will set the status so that abstract representations can set
93-
// Ready and Phases
93+
// Ready and Phases.
9494
func (c *NestedAPIServer) SetCommonStatus(s addonv1alpha1.CommonStatus) {
9595
c.Status.CommonStatus = s
9696
}
9797

98-
// PatchSpec returns the patches to be applied
98+
// PatchSpec returns the patches to be applied.
9999
func (c *NestedAPIServer) PatchSpec() addonv1alpha1.PatchSpec {
100100
return c.Spec.PatchSpec
101101
}

0 commit comments

Comments
 (0)