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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃尡 Upgrade Golang CI & Fix Lint #90

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
135 changes: 112 additions & 23 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,122 @@
linters:
enable-all: true
disable:
- dupl
- funlen
- gochecknoglobals
- gochecknoinits
- lll
- godox
- wsl
- whitespace
- gocognit
- gomnd
- interfacer
- godot
- goerr113
- nestif
# Run with --fast=false for more extensive checks
fast: true
disable-all: true
enable:
- asciicheck
- bodyclose
- deadcode
- depguard
- dogsled
- exportloopref
- errcheck
- goconst
- gocritic
- gocyclo
- godot
- gofmt
- goimports
- goprintffuncname
- gosec
- gosimple
- govet
- importas
- ineffassign
- misspell
- nakedret
- nolintlint
- prealloc
- revive
- rowserrcheck
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- varcheck
- whitespace

linters-settings:
staticcheck:
go: "1.16"
stylecheck:
go: "1.16"
importas:
no-unaliased: true
alias:
# Kubernetes
- pkg: k8s.io/api/core/v1
alias: corev1
- pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
alias: apiextensionsv1
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
alias: metav1
- pkg: k8s.io/apimachinery/pkg/api/errors
alias: apierrors
- pkg: k8s.io/apimachinery/pkg/util/errors
alias: kerrors
# Controller Runtime
- pkg: sigs.k8s.io/controller-runtime
alias: ctrl

issues:
max-same-issues: 0
max-issues-per-linter: 0
# We are disabling default golangci exclusions because we want to help reviewers to focus on reviewing the most relevant
# changes in PRs and avoid nitpicking.
exclude-use-default: false
# List of regexps of issue texts to exclude, empty list by default.
exclude:
- Using the variable on range scope `(tc)|(rt)|(tt)|(test)|(testcase)|(testCase)` in function literal
- "G108: Profiling endpoint is automatically exposed on /debug/pprof"
- "G108: Profiling endpoint is automatically exposed on /debug/pprof"
- Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
- "exported: exported method .*\\.(Reconcile|SetupWithManager|SetupWebhookWithManager) should have comment or be unexported"
# The following are being worked on to remove their exclusion. This list should be reduced or go away all together over time.
# If it is decided they will not be addressed they should be moved above this comment.
- Subprocess launch(ed with variable|ing should be audited)
- (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)
- (G104|G307)
exclude-rules:
# With Go 1.16, the new embed directive can be used with an un-named import,
# revive (previously, golint) only allows these to be imported in a main.go, which wouldn't work for us.
# This directive allows the embed package to be imported with an underscore everywhere.
- linters:
- revive
source: _ "embed"
# Exclude some packages or code to require comments, for example test code, or fake clients.
- linters:
- revive
text: exported (method|function|type|const) (.+) should have comment or be unexported
source: (func|type).*Fake.*
- linters:
- revive
text: exported (method|function|type|const) (.+) should have comment or be unexported
path: fake_\.go
- linters:
- revive
text: exported (method|function|type|const) (.+) should have comment or be unexported
path: .*test/(providers|framework|e2e).*.go
# Disable unparam "always receives" which might not be really
# useful when building libraries.
- linters:
- unparam
text: always receives
# Dot imports for gomega or ginkgo are allowed
# within test files.
- path: _test\.go
text: should not use dot imports
- path: _test\.go
text: cyclomatic complexity
- path: test/(framework|e2e).*.go
text: should not use dot imports
# Append should be able to assign to a different var/slice.
- linters:
- gocritic
text: "appendAssign: append result not assigned to the same slice"

run:
timeout: 10m
skip-files:
- "zz_generated.*\\.go$"
- ".*conversion.*\\.go$"
- "zz_generated.*\\.go$"
- ".*conversion.*\\.go$"
skip-dirs:
- third_party
- third_party
allow-parallel-runners: true
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ manager-nested-controlplane: ## Build manager binary
$(CONTROLLER_GEN): $(TOOLS_DIR)/go.mod # Build controller-gen from tools folder.
cd $(TOOLS_DIR); go build -tags=tools -o $(BIN_DIR)/controller-gen sigs.k8s.io/controller-tools/cmd/controller-gen

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

$(RELEASE_NOTES): $(TOOLS_DIR)/go.mod
cd $(TOOLS_DIR) && go build -tags=tools -o $(RELEASE_NOTES_BIN) sigs.k8s.io/cluster-api/hack/tools/release
Expand Down
10 changes: 5 additions & 5 deletions api/v1alpha4/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

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

import (
Expand All @@ -25,10 +25,10 @@ import (
)

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

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
Expand Down
8 changes: 4 additions & 4 deletions api/v1alpha4/nestedcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import (
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
)

// NestedClusterSpec defines the desired state of NestedCluster
// NestedClusterSpec defines the desired state of NestedCluster.
type NestedClusterSpec struct {
// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
// +optional
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`
}

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

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

//+kubebuilder:object:root=true

// NestedClusterList contains a list of NestedCluster
// NestedClusterList contains a list of NestedCluster.
type NestedClusterList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.1-0.20201002000720-57250aac17f6
controller-gen.kubebuilder.io/version: v0.6.0-beta.0
creationTimestamp: null
name: nestedclusters.infrastructure.cluster.x-k8s.io
spec:
Expand All @@ -31,21 +31,26 @@ spec:
name: v1alpha4
schema:
openAPIV3Schema:
description: NestedCluster is the Schema for the nestedclusters API
description: NestedCluster is the Schema for the nestedclusters API.
properties:
apiVersion:
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'
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'
type: string
kind:
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'
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'
type: string
metadata:
type: object
spec:
description: NestedClusterSpec defines the desired state of NestedCluster
description: NestedClusterSpec defines the desired state of NestedCluster.
properties:
controlPlaneEndpoint:
description: ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
description: ControlPlaneEndpoint represents the endpoint used to
communicate with the control plane.
properties:
host:
description: The hostname on which the API server is serving.
Expand All @@ -60,10 +65,11 @@ spec:
type: object
type: object
status:
description: NestedClusterStatus defines the observed state of NestedCluster
description: NestedClusterStatus defines the observed state of NestedCluster.
properties:
ready:
description: Ready is when the NestedControlPlane has a API server URL.
description: Ready is when the NestedControlPlane has a API server
URL.
type: boolean
type: object
type: object
Expand Down
4 changes: 3 additions & 1 deletion controllers/nestedcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Package controllers contains all the Infrastructure group controllers for
// running nested clusters.
package controllers

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

// NestedClusterReconciler reconciles a NestedCluster object
// NestedClusterReconciler reconciles a NestedCluster object.
type NestedClusterReconciler struct {
client.Client
Log logr.Logger
Expand Down
6 changes: 3 additions & 3 deletions controlplane/nested/api/v1alpha4/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

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

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

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
Expand Down
24 changes: 12 additions & 12 deletions controlplane/nested/api/v1alpha4/nestedapiserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ import (
addonv1alpha1 "sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/addon/pkg/apis/v1alpha1"
)

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

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

// CommonStatus allows addons status monitoring
// CommonStatus allows addons status monitoring.
addonv1alpha1.CommonStatus `json:",inline"`
}

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

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

//+kubebuilder:object:root=true

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

// ComponentName returns the name of the component for use with
// addonv1alpha1.CommonObject
// addonv1alpha1.CommonObject.
func (c *NestedAPIServer) ComponentName() string {
return string(APIServer)
}

// CommonSpec returns the addons spec of the object allowing common funcs like
// Channel & Version to be usable
// Channel & Version to be usable.
func (c *NestedAPIServer) CommonSpec() addonv1alpha1.CommonSpec {
return c.Spec.CommonSpec
}

// GetCommonStatus will return the common status for checking is a component
// was successfully deployed
// was successfully deployed.
func (c *NestedAPIServer) GetCommonStatus() addonv1alpha1.CommonStatus {
return c.Status.CommonStatus
}

// SetCommonStatus will set the status so that abstract representations can set
// Ready and Phases
// Ready and Phases.
func (c *NestedAPIServer) SetCommonStatus(s addonv1alpha1.CommonStatus) {
c.Status.CommonStatus = s
}

// PatchSpec returns the patches to be applied
// PatchSpec returns the patches to be applied.
func (c *NestedAPIServer) PatchSpec() addonv1alpha1.PatchSpec {
return c.Spec.PatchSpec
}