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

feat: applying lint and fixing the lint issues #94

Merged
merged 1 commit into from
Nov 29, 2023
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
4 changes: 3 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: tests
name: tests and lint

on:
pull_request:
Expand Down Expand Up @@ -32,5 +32,7 @@ jobs:
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Run lint
run: make lint
- name: Run tests
run: make test
121 changes: 121 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
run:
go: "1.21"
timeout: 10m
tests: false
allow-parallel-runners: true
skip-dirs:
- "./*/mock"
skip-files:
- "pkg/ocm/fakes/ocm.go"

linters-settings:
funlen:
lines: 150
statements: 70
staticcheck:
go: "1.21"
stylecheck:
go: "1.21"
cyclop:
max-complexity: 20
skip-tests: true
gosec:
exclude-generated: true
lll:
line-length: 150
misspell:
locale: US
govet:
check-shadowing: true
nilaway:
nolintlint:
allow-unused: false
require-explanation: true
require-specific: false
varnamelen:
ignore-names:
- err
- wg
- fs
- id
- vm
- ns
- ip

issues:
max-same-issues: 0
max-issues-per-linter: 0
exclude-rules:
- text: "should not use dot imports|don't use an underscore in package name"
linters:
- golint
- source: "https://"
linters:
- lll
- path: pkg/defaults/
linters:
- lll
- path: _test\.go
linters:
- goerr113
- gocyclo
- errcheck
- gosec
- dupl
- funlen
- scopelint
- testpackage
- goconst
- godox
- path: internal/version/
linters:
- gochecknoglobals
- path: internal/command/
linters:
- exhaustivestruct
- lll
- wrapcheck
- source: "// .* #\\d+"
linters:
- godox
- path: test/e2e/
linters:
- goerr113
- gomnd
# remove this once https://github.com/golangci/golangci-lint/issues/2649 is closed
- path: /
linters:
- typecheck

linters:
enable-all: true
disable:
- gci
- depguard
- exhaustivestruct
- golint
- interfacer
- ireturn
- maligned
- nilnil
- scopelint
- tagliatelle
- gomoddirectives
- varcheck
- nosnakecase
- structcheck
- ifshort
- deadcode
- forbidigo
- prealloc
- gochecknoinits
- exhaustruct
- goerr113
- govet
- nonamedreturns
- varnamelen
- wrapcheck
- staticcheck
- gochecknoglobals
- paralleltest
- wsl
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ fmt: ## Run go fmt against code.
vet: ## Run go vet against code.
go vet ./...

.PHONY: lint
lint: golangci-lint ## Run golangci-lint.
$(GOLANGCI_LINT) run

.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... $(GO_TEST_ARGS) -coverprofile cover.out
Expand Down Expand Up @@ -133,10 +137,12 @@ $(LOCALBIN):
KUSTOMIZE ?= $(LOCALBIN)/kustomize
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint

## Tool Versions
KUSTOMIZE_VERSION ?= v3.8.7
CONTROLLER_TOOLS_VERSION ?= v0.11.1
GOLANGCI_LINT_VERSION ?= v1.55.2

KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
Expand All @@ -158,3 +164,8 @@ $(CONTROLLER_GEN): $(LOCALBIN)
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest

.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT)
$(GOLANGCI_LINT): $(LOCALBIN)
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s $(GOLANGCI_LINT_VERSION)
2 changes: 1 addition & 1 deletion api/v1alpha1/condition_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const (
// CreateSnapshotFailedReason is used when we fail to create an ocm-controller.Snapshot object in the cluster.
CreateSnapshotFailedReason = "CreateSnapshotFailed"

// CommitTemplateEmptyReason is used when a the commit template is not set.
// CommitTemplateEmptyReason is used when a commit template is not set.
CommitTemplateEmptyReason = "CommitTemplateEmpty"

// CreateComponentVersionFailedReason is used when we fail to create an ocm-controller.ComponentVersion object in the cluster.
Expand Down
10 changes: 10 additions & 0 deletions api/v1alpha1/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package v1alpha1

const (
// LevelDebug defines the debug level logs.
LevelDebug = 4
)

const (
WritePermissions = 0o777
)
4 changes: 2 additions & 2 deletions api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,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: "mpas.ocm.software", Version: "v1alpha1"}

// 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
4 changes: 2 additions & 2 deletions api/v1alpha1/productdeployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (in *ProductDeployment) SetObservedGeneration(v int64) {
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

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

//+kubebuilder:object:root=true

// ProductDeploymentList contains a list of ProductDeployment
// ProductDeploymentList contains a list of ProductDeployment.
type ProductDeploymentList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down
12 changes: 6 additions & 6 deletions api/v1alpha1/productdeploymentgenerator_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ProductDeploymentGeneratorSpec defines the desired state of ProductDeploymentGenerator
// ProductDeploymentGeneratorSpec defines the desired state of ProductDeploymentGenerator.
type ProductDeploymentGeneratorSpec struct {
// Interval is the reconciliation interval, i.e. at what interval shall a reconciliation happen.
// This is used to requeue objects for reconciliation in case the related subscription hasn't been finished yet.
Expand All @@ -31,7 +31,7 @@ type ProductDeploymentGeneratorSpec struct {
ServiceAccountName string `json:"serviceAccountName"`
}

// ProductDeploymentGeneratorStatus defines the observed state of ProductDeploymentGenerator
// ProductDeploymentGeneratorStatus defines the observed state of ProductDeploymentGenerator.
type ProductDeploymentGeneratorStatus struct {
// ObservedGeneration is the last reconciled generation.
// +optional
Expand All @@ -53,12 +53,12 @@ type ProductDeploymentGeneratorStatus struct {
LastReconciledVersion string `json:"lastReconciledVersion,omitempty"`
}

// GetSnapshotDigest returns the latest snapshot digest for the localization
// GetSnapshotDigest returns the latest snapshot digest for the localization.
func (in ProductDeploymentGenerator) GetSnapshotDigest() string {
return in.Status.LatestSnapshotDigest
}

// GetSnapshotName returns the key for the snapshot produced by the Localization
// GetSnapshotName returns the key for the snapshot produced by the Localization.
func (in ProductDeploymentGenerator) GetSnapshotName() string {
return in.Status.SnapshotName
}
Expand Down Expand Up @@ -93,7 +93,7 @@ func (in *ProductDeploymentGenerator) SetObservedGeneration(v int64) {
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

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

//+kubebuilder:object:root=true

// ProductDeploymentGeneratorList contains a list of ProductDeploymentGenerator
// ProductDeploymentGeneratorList contains a list of ProductDeploymentGenerator.
type ProductDeploymentGeneratorList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down
9 changes: 5 additions & 4 deletions api/v1alpha1/productdeploymentpipeline_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ProductDeploymentPipelineSpec defines the desired state of ProductDeploymentPipeline
// ProductDeploymentPipelineSpec defines the desired state of ProductDeploymentPipeline.
type ProductDeploymentPipelineSpec struct {
// ComponentVersionRef is the name of the generated component version object.
// +required
Expand All @@ -29,7 +29,7 @@ type ProductDeploymentPipelineSpec struct {
TargetRef meta.NamespacedObjectReference `json:"targetRef"`
}

// ProductDeploymentPipelineStatus defines the observed state of ProductDeploymentPipeline
// ProductDeploymentPipelineStatus defines the observed state of ProductDeploymentPipeline.
type ProductDeploymentPipelineStatus struct {
// ObservedGeneration is the last reconciled generation.
// +optional
Expand Down Expand Up @@ -84,13 +84,14 @@ func (in *ProductDeploymentPipeline) Equals(spec ProductDeploymentPipelineSpec)
case in.Spec.ConfigMapRef != spec.ConfigMapRef:
return false
}

return true
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// ProductDeploymentPipeline is the Schema for the productdeploymentpipelines API
// ProductDeploymentPipeline is the Schema for the productdeploymentpipelines API.
type ProductDeploymentPipeline struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -101,7 +102,7 @@ type ProductDeploymentPipeline struct {

//+kubebuilder:object:root=true

// ProductDeploymentPipelineList contains a list of ProductDeploymentPipeline
// ProductDeploymentPipelineList contains a list of ProductDeploymentPipeline.
type ProductDeploymentPipelineList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down
8 changes: 4 additions & 4 deletions api/v1alpha1/productdescription_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ProductDescriptionSpec defines the desired state of ProductDescription
// ProductDescriptionSpec defines the desired state of ProductDescription.
type ProductDescriptionSpec struct {
// +required
Description string `json:"description"`
Expand All @@ -19,7 +19,7 @@ type ProductDescriptionSpec struct {
TargetRoles []TargetRoles `json:"targetRoles,omitempty"`
}

// ProductDescriptionStatus defines the observed state of ProductDescription
// ProductDescriptionStatus defines the observed state of ProductDescription.
type ProductDescriptionStatus struct{}

// TargetRoles defines a target role with a name.
Expand Down Expand Up @@ -54,7 +54,7 @@ type DescriptionConfiguration struct {
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

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

//+kubebuilder:object:root=true

// ProductDescriptionList contains a list of ProductDescription
// ProductDescriptionList contains a list of ProductDescription.
type ProductDescriptionList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down
8 changes: 4 additions & 4 deletions api/v1alpha1/target_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var (
OCIRepository TargetType = "ocirepository"
)

// TargetSpec defines the desired state of Target
// TargetSpec defines the desired state of Target.
type TargetSpec struct {
// +required
Type TargetType `json:"type"`
Expand All @@ -47,7 +47,7 @@ type TargetSpec struct {
SecretsSelector *metav1.LabelSelector `json:"selector,omitempty"`
}

// TargetStatus defines the observed state of Target
// TargetStatus defines the observed state of Target.
type TargetStatus struct {
// ObservedGeneration is the last reconciled generation.
// +optional
Expand Down Expand Up @@ -78,7 +78,7 @@ func (in Target) GetRequeueAfter() time.Duration {
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

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

//+kubebuilder:object:root=true

// TargetList contains a list of Target
// TargetList contains a list of Target.
type TargetList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down
Loading
Loading