Skip to content

Commit

Permalink
chore: add golangci-lint (#584)
Browse files Browse the repository at this point in the history
  • Loading branch information
JorTurFer authored Jan 27, 2023
1 parent 30108da commit b5c41c8
Show file tree
Hide file tree
Showing 85 changed files with 547 additions and 337 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/.devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// inspired from
// inspired from
// https://github.com/microsoft/vscode-dev-containers/blob/main/containers/go/.devcontainer/devcontainer.json
{
"name": "Go",
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ RUN apt-get update && \
apt-get install -y apt-transport-https ca-certificates curl && \
sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg && \
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list && \
sudo apt-get update && \
sudo apt-get update && \
sudo apt-get install -y kubectl

# [Optional] Uncomment this section to install additional OS packages.
Expand Down
2 changes: 1 addition & 1 deletion .github/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ closeComment: >
limitPerRun: 30

# Limit to only `issues` or `pulls`
only: issues
only: issues
2 changes: 1 addition & 1 deletion .github/workflows/build_canary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ jobs:
- name: Publish on GitHub Container Registry
run: make publish-multiarch
env:
VERSION: canary
VERSION: canary
2 changes: 1 addition & 1 deletion .github/workflows/build_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ jobs:
- name: Publish on GitHub Container Registry
run: make publish-multiarch
env:
VERSION: ${{ steps.get_version.outputs.VERSION }}
VERSION: ${{ steps.get_version.outputs.VERSION }}
2 changes: 1 addition & 1 deletion .github/workflows/images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
run: |
COMMIT=$(git rev-parse --short HEAD)
VERSION=${COMMIT} make docker-build-scaler
build_operator:
runs-on: ubuntu-latest
container: ghcr.io/kedacore/build-tools:1.19.5
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,18 @@ jobs:

- name: Test
run: ARCH=${{ matrix.name }} make test

statics:
name: Static Checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/[email protected]
with:
python-version: 3.x
- uses: actions/setup-go@v3
with:
go-version: 1.19
- name: Get golangci
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.49.0
- uses: pre-commit/[email protected]
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -354,4 +354,4 @@ admin/target
admin/Cargo.lock

/target
.envrc
.envrc
60 changes: 60 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# options for analysis running
run:
# default concurrency is a available CPU number
concurrency: 4
# timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 10m
linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
enable:
- typecheck
- dupl
- goprintffuncname
- govet
- nolintlint
#- rowserrcheck
- gofmt
- revive
- goimports
- misspell
- bodyclose
- unconvert
- ineffassign
- staticcheck
- exportloopref
- depguard
- dogsled
- errcheck
#- funlen
- gci
- goconst
- gocritic
- gocyclo
- gosimple
- stylecheck
- unused
- unparam
- unconvert
- whitespace

issues:
include:
- EXC0002 # disable excluding of issues about comments from golint
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
- path: _test\.go
linters:
- gomnd
- dupl
- unparam
linters-settings:
funlen:
lines: 80
statements: 40
gci:
sections:
- standard
- default
- prefix(github.com/kedacore/http-add-on)
39 changes: 39 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
default_stages: [commit, push]
minimum_pre_commit_version: "1.20.0"
repos:
- repo: https://github.com/dnephin/pre-commit-golang
rev: v0.3.5
hooks:
- id: go-fmt
name: Run go fmt against the code
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
hooks:
- id: trailing-whitespace
- id: detect-private-key
- id: end-of-file-fixer
- id: check-merge-conflict
- id: mixed-line-ending
- repo: https://github.com/thlorenz/doctoc.git
rev: v2.0.0
hooks:
- id: doctoc
name: Add TOC for md files
files: ^README\.md$|^CONTRIBUTING\.md$
args:
- "--maxlevel"
- "3"
- repo: local
hooks:
- id: language-matters
language: pygrep
name: Check for language that we do not accept as community
description: Please use "deny_list" or "allow_list" instead.
entry: "(?i)(black|white)[_-]?(list|List)"
pass_filenames: true
- id: golangci-lint
language: golang
name: Run golangci against the code
entry: golangci-lint run
types: [go]
pass_filenames: false
2 changes: 1 addition & 1 deletion .whitesource
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
"issueSettings": {
"minSeverityLevel": "LOW"
}
}
}
24 changes: 11 additions & 13 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,17 @@ There are many areas we can use contributions - ranging from code, documentation
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
## Table of contents

- [Contributing to KEDA](#contributing-to-keda)
- [Table of contents](#table-of-contents)
- [Project governance](#project-governance)
- [Including Documentation Changes](#including-documentation-changes)
- [Development Environment Setup](#development-environment-setup)
- [Locally Build & Deploy KEDA HTTP Addon](#locally-build--deploy-keda-http-addon)
- [Pre-requisite](#pre-requisite)
- [Building](#building)
- [Deploying](#deploying)
- [Load testing with k9s](#load-testing-with-k9s)
- [Developer Certificate of Origin: Signing your work](#developer-certificate-of-origin-signing-your-work)
- [Every commit needs to be signed](#every-commit-needs-to-be-signed)
- [I didn't sign my commit, now what?!](#i-didnt-sign-my-commit-now-what)
- [Project governance](#project-governance)
- [Including Documentation Changes](#including-documentation-changes)
- [Development Environment Setup](#development-environment-setup)
- [Locally Build & Deploy KEDA HTTP Addon](#locally-build--deploy-keda-http-addon)
- [Pre-requisite:](#pre-requisite)
- [Building:](#building)
- [Deploying:](#deploying)
- [Load testing with k9s:](#load-testing-with-k9s)
- [Developer Certificate of Origin: Signing your work](#developer-certificate-of-origin-signing-your-work)
- [Every commit needs to be signed](#every-commit-needs-to-be-signed)
- [I didn't sign my commit, now what?!](#i-didnt-sign-my-commit-now-what)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

Expand Down
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ e2e-test:
./tests/e2e-test.sh

# Docker targets
docker-build-operator:
docker-build-operator:
DOCKER_BUILDKIT=1 docker build . -t ${IMAGE_OPERATOR} -f operator/Dockerfile --build-arg VERSION=${VERSION} --build-arg GIT_COMMIT=${GIT_COMMIT}

docker-build-interceptor:
docker-build-interceptor:
DOCKER_BUILDKIT=1 docker build . -t ${IMAGE_INTERCEPTOR} -f interceptor/Dockerfile --build-arg VERSION=${VERSION} --build-arg GIT_COMMIT=${GIT_COMMIT}

docker-build-scaler:
docker-build-scaler:
DOCKER_BUILDKIT=1 docker build . -t ${IMAGE_SCALER} -f scaler/Dockerfile --build-arg VERSION=${VERSION} --build-arg GIT_COMMIT=${GIT_COMMIT}

docker-build: docker-build-operator docker-build-interceptor docker-build-scaler
Expand All @@ -76,7 +76,7 @@ publish-multiarch: publish-operator-multiarch publish-interceptor-multiarch publ
manifests: controller-gen ## Generate ClusterRole and CustomResourceDefinition objects for core componenets.
$(CONTROLLER_GEN) crd:crdVersions=v1 rbac:roleName=keda-http-add-on paths="./..." output:crd:artifacts:config=config/crd/bases

verify-manifests:
verify-manifests:
./hack/verify-manifests.sh

fmt: ## Run go fmt against code.
Expand All @@ -85,8 +85,8 @@ fmt: ## Run go fmt against code.
vet: ## Run go vet against code.
go vet ./...

golangci: ## Run golangci against code.
golangci-lint run
pre-commit: ## Run static-checks.
pre-commit run --all-files

proto-gen: protoc-gen-go ## Scaler protobuffers
protoc --proto_path=proto scaler.proto --go_out=proto --go-grpc_out=proto
Expand Down Expand Up @@ -118,4 +118,4 @@ deploy: manifests kustomize ## Deploy to the K8s cluster specified in ~/.kube/co
$(KUSTOMIZE) build config/default | kubectl apply -f -

undeploy:
$(KUSTOMIZE) build config/default | kubectl delete -f -
$(KUSTOMIZE) build config/default | kubectl delete -f -
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*

- [HTTP Autoscaling Made Simple](#http-autoscaling-made-simple)
- [Adopters - Become a listed KEDA user!](#adopters---become-a-listed-keda-user)
- [Walkthrough](#walkthrough)
- [Design](#design)
- [Installation](#installation)
- [Roadmap](#roadmap)
- [Contributing](#contributing)
- [Code of Conduct](#code-of-conduct)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

<p align="center"><img src="https://github.com/kedacore/keda/raw/main/images/logos/keda-word-colour.png" width="300"/></p>

<p style="font-size: 25px" align="center"><b>Kubernetes-based Event Driven Autoscaling - HTTP Add-on</b></p>
Expand Down Expand Up @@ -47,7 +62,7 @@ customizable installations while allowing us to ship reasonable defaults.
## Installation

Please see the [complete installation instructions](./docs/install.md).

## Roadmap
We use GitHub issues to build our backlog, a complete overview of all open items and our planning.

Expand Down
4 changes: 2 additions & 2 deletions RELEASE-PROCESS.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ appVersion: 1.2.3
```yaml
images:
# tag is the image tag to use for all images.
# for example, if the operator image is "myoperator" and
# for example, if the operator image is "myoperator" and
# tag is "mytag", the operator image used will be
# "myoperator:mytag". `latest` is used to indicate the latest
# stable release in the official images, `canary` is
# stable release in the official images, `canary` is
# the build for the latest commit to the `main` branch,
# and you can target any other commit with `sha-<GIT_SHA[0:7]>`
tag: 1.2.3
Expand Down
2 changes: 1 addition & 1 deletion config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
resources:
- bases/http.keda.sh_httpscaledobjects.yaml

# +kubebuilder:scaffold:crdkustomizeresource
# +kubebuilder:scaffold:crdkustomizeresource
1 change: 0 additions & 1 deletion config/default/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,3 @@ resources:
- ../scaler
- ../service_account
- ../shared

4 changes: 2 additions & 2 deletions config/interceptor/interceptor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ spec:
- name: interceptor
image: ghcr.io/kedacore/http-add-on-interceptor:latest
command:
- /interceptor
- /interceptor
imagePullPolicy: IfNotPresent
resources:
requests:
cpu: 100m
memory: 100Mi
limits:
cpu: 1000m
memory: 1000Mi
memory: 1000Mi
ports:
- containerPort: 9090
name: inter-admin
Expand Down
2 changes: 1 addition & 1 deletion config/interceptor/service-admin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ spec:
targetPort: inter-admin
selector:
control-plane: interceptor
app: keda-http-add-on
app: keda-http-add-on
4 changes: 2 additions & 2 deletions config/operator/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ spec:
control-plane: controller-manager
app: keda-http-add-on
name: keda-http-add-on-operator
spec:
spec:
serviceAccountName: keda-http-add-on
containers:
- name: kube-rbac-proxy
Expand All @@ -48,7 +48,7 @@ spec:
- name: operator
image: ghcr.io/kedacore/http-add-on-operator:latest
command:
- /operator
- /operator
args:
- --metrics-addr=127.0.0.1:8080
- --enable-leader-election
Expand Down
2 changes: 1 addition & 1 deletion config/operator/service-admin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ spec:
targetPort: admin-http
selector:
control-plane: controller-manager
app: keda-http-add-on
app: keda-http-add-on
4 changes: 2 additions & 2 deletions config/scaler/scaler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ spec:
securityContext:
runAsNonRoot: true
serviceAccountName: keda-http-add-on
containers:
containers:
- name: external-scaler
image: ghcr.io/kedacore/http-add-on-scaler:latest
command:
- /scaler
- /scaler
imagePullPolicy: IfNotPresent
resources:
requests:
Expand Down
2 changes: 1 addition & 1 deletion config/scaler/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ spec:
targetPort: scaler-health
selector:
control-plane: external-scaler
app: keda-http-add-on
app: keda-http-add-on
4 changes: 3 additions & 1 deletion docs/developing.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ to have the following tools installed:

- [Golang](http://golang.org/) for development
- [Docker](https://docker.com) for building the images and testing it locally
- [Pre-commit](https://pre-commit.com/) for static checks (_optional_)

## Prerequisites

Expand Down Expand Up @@ -48,10 +49,11 @@ The Makefile located in the root directory has targets useful for the whole proj
- `make publish-multiarch`: Build and push all Docker images for `linux/arm64` and `linux/amd64`
- `make manifests`: Generate all the manifest files for Kubernetes, it's important to build after every change
- `make deploy`: Deploys the HTTP Add-on to the cluster selected in `~/.kube/config` using `config` folder manifests
- `make pre-commit`: Execute static checks

### Required Environment Variables

Some of the above commands support changes in the default values:
Some of the above commands support changes in the default values:

- `IMAGE_REGISTRY`: Image registry to be used for docker images
- `IMAGE_REPO`: Repository to be used for docker images
Expand Down
Loading

0 comments on commit b5c41c8

Please sign in to comment.