Skip to content

Commit

Permalink
Add verification scripts
Browse files Browse the repository at this point in the history
Signed-off-by: Yuan Chen <[email protected]>

Add verify and update to Makefile

Signed-off-by: Yuan Chen <[email protected]>
  • Loading branch information
yuanchen8911 committed May 9, 2024
1 parent cc2121e commit a4a52b6
Show file tree
Hide file tree
Showing 1,173 changed files with 203,496 additions and 2 deletions.
196 changes: 196 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
# https://golangci-lint.run/usage/linters
linters:
disable-all: true
enable:
- asciicheck
- bodyclose
- depguard
- dogsled
- errcheck
- errorlint
- exportloopref
- gci
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- goprintffuncname
- gosec
- gosimple
- govet
- importas
- ineffassign
- misspell
- nakedret
- nilerr
- nolintlint
- prealloc
- revive
- staticcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
- whitespace

linters-settings:
gci:
sections:
- standard
- default
- prefix(sigs.k8s.io/kwok)
- blank
- dot
skip-generated: true
custom-order: true
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
staticcheck:
go: "1.21"
stylecheck:
go: "1.21"
# STxxxx checks in https://staticcheck.io/docs/configuration/options/#checks
checks: ["all", "-ST1000", "-ST1003"]
depguard:
rules:
main:
deny:
# https://go.dev/doc/go1.16#ioutil
- pkg: "io/ioutil"
desc: "please see https://go.dev/doc/go1.16#ioutil"
# Use sigs.k8s.io/kwok/pkg/log, which is a wrapper around slog
- pkg: "k8s.io/klog/v2"
desc: "please use `sigs.k8s.io/kwok/pkg/log` instead"
- pkg: "k8s.io/klog"
desc: "please use `sigs.k8s.io/kwok/pkg/log` instead"
- pkg: "golang.org/x/exp/slog"
desc: "please use `sigs.k8s.io/kwok/pkg/log` instead"
- pkg: "log/slog"
desc: "please use `sigs.k8s.io/kwok/pkg/log` instead"
- pkg: "log"
desc: "please use `sigs.k8s.io/kwok/pkg/log` instead"
# Use sigs.k8s.io/kwok/pkg/utils/yaml, which is a wrapper around yaml
- pkg: "k8s.io/apimachinery/pkg/util/yaml"
desc: "please use `sigs.k8s.io/kwok/pkg/utils/yaml` instead"
- pkg: "sigs.k8s.io/yaml"
desc: "please use `sigs.k8s.io/kwok/pkg/utils/yaml` instead"
# Use sigs.k8s.io/kwok/pkg/utils/wait, which is a wrapper around wait
- pkg: "k8s.io/apimachinery/pkg/util/wait"
desc: "please use `sigs.k8s.io/kwok/pkg/utils/wait` instead"
# Use sigs.k8s.io/kwok/pkg/utils/slices, which is a wrapper around slices
- pkg: "k8s.io/utils/strings/slices"
desc: "please use `sigs.k8s.io/kwok/pkg/utils/slices` instead"
gocyclo:
min-complexity: 50
gosec:
excludes:
- G110
- G304
config:
G301: "0750"
G302: "0640"
G306: "0640"
goconst:
min-len: 5
min-occurrences: 10
ignore-tests: true
match-constant: false
revive:
ignore-generated-header: true
severity: error
enable-all-rules: true
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md
rules:
- name: add-constant
disabled: true
- name: argument-limit
disabled: true
- name: cognitive-complexity
disabled: true
- name: confusing-naming
disabled: true
- name: cyclomatic
disabled: true
- name: early-return
disabled: true
- name: enforce-map-style
disabled: true
- name: exported
disabled: true
- name: file-header
disabled: true
- name: flag-parameter
disabled: true
- name: function-length
disabled: true
- name: get-return
disabled: true
- name: if-return
disabled: true
- name: import-shadowing
disabled: true
- name: line-length-limit
disabled: true
- name: modifies-parameter
disabled: true
- name: nested-structs
disabled: true
- name: optimize-operands-order
disabled: true
- name: unused-parameter
disabled: true
- name: unused-receiver
disabled: true
- name: use-any
disabled: true
- name: unchecked-type-assertion
disabled: true
- name: function-result-limit
disabled: true
- name: deep-exit
disabled: true
- name: superfluous-else
disabled: true
- name: confusing-results
disabled: true
- name: defer
disabled: true
- name: var-naming
disabled: true
- name: max-public-structs
disabled: true
- name: comment-spacings
disabled: true
- name: struct-tag
disabled: true
- name: unhandled-error
disabled: true
- name: error-strings
disabled: true
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
run:
concurrency: 1
timeout: 10m
allow-parallel-runners: false
skip-dirs-use-default: true
skip-files:
- ".*\\.zz_generated\\..*"
go: '1.21'
14 changes: 14 additions & 0 deletions .yamllint.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# configuration file rules
# https://yamllint.readthedocs.io/en/stable/rules.html

extends: default

ignore-from-file: .gitignore

rules:
indentation: disable
document-start: disable
comments: disable
line-length: disable
truthy:
check-keys: false
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ IMAGE_REPO ?=docker.io/nvidia/knavigator
GIT_REF =$(shell git rev-parse --abbrev-ref HEAD)
IMAGE_TAG ?=$(GIT_REF)

## verify: Verify code
.PHONY: verify
verify:
@./hack/verify-all.sh

## update: Update all the generated
.PHONY: update
update:
@./hack/update-all.sh

.PHONY: build
build:
@for target in $(TARGETS); do \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Knavigator is a project designed to analyze, optimize, and compare scheduling sy

The term "knavigator" is derived from "navigator," with a silent "k" prefix representing "kubernetes." Much like a navigator, this initiative assists in charting a secure route and steering clear of obstacles within the cluster.

Knavigator interfaces with Kubernetes clusters to manage tasks such as manupulating with Kubernetes objects, evaluating PromQL queries, as well as executing specific operations.
Knavigator interfaces with Kubernetes clusters to manage tasks such as manipulating with Kubernetes objects, evaluating PromQL queries, as well as executing specific operations.

Knavigator can operate both outside and inside a Kubernetes cluster, leveraging the Kubernetes API for task management.

Expand Down
1 change: 1 addition & 0 deletions hack/spelling.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
importas
64 changes: 64 additions & 0 deletions hack/update-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env bash
# Copyright 2023 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

DIR="$(dirname "${BASH_SOURCE[0]}")"

ROOT_DIR="$(realpath "${DIR}/..")"

failed=()

if [[ "${UPDATE_GO_FORMAT:-true}" == "true" ]]; then
echo "[*] Update go format..."
"${ROOT_DIR}"/hack/update-go-format.sh || failed+=(go-format)
fi

if [[ "${UPDATE_GO_MOD:-true}" == "true" ]]; then
echo "[*] Update go mod..."
"${ROOT_DIR}"/hack/update-go-mod.sh || failed+=(go-mod)
fi

if [[ "${UPDATE_GO_LINT:-true}" == "true" ]]; then
echo "[*] Update go lint..."
"${ROOT_DIR}"/hack/update-go-lint.sh || failed+=(go-lint)
fi

if [[ "${UPDATE_ENDS_NEWLINE:-true}" == "true" ]]; then
echo "[*] Update ends newline..."
"${ROOT_DIR}"/hack/update-ends-newline.sh || failed+=(ends-newline)
fi

if [[ "${UPDATE_SHELL_FORMAT:-true}" == "true" ]]; then
echo "[*] Update shell format..."
"${ROOT_DIR}"/hack/update-shell-format.sh || failed+=(shell-format)
fi

if [[ "${UPDATE_YAML_FORMAT:-true}" == "true" ]]; then
echo "[*] Update yaml format..."
"${ROOT_DIR}"/hack/update-yaml-format.sh || failed+=(yaml-format)
fi

if [[ "${UPDATE_SPELLING:-true}" == "true" ]]; then
echo "[*] Update spelling..."
"${ROOT_DIR}"/hack/update-spelling.sh || failed+=(spelling)
fi

if [[ "${#failed[@]}" != 0 ]]; then
echo "Update failed for: ${failed[*]}"
exit 1
fi
42 changes: 42 additions & 0 deletions hack/update-ends-newline.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash
# Copyright 2023 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

DIR="$(dirname "${BASH_SOURCE[0]}")"

ROOT_DIR="$(realpath "${DIR}/..")"

function update_ends_newline() {
find . \( \
-iname "*.md" \
-o -iname "*.sh" \
-o -iname "*.go" \
-o -iname "*.tpl" \
-o -iname "*.yaml" \
-o -iname "*.yml" \
\) \
-not \( \
-path ./.git/\* \
-o -path ./vendor/\* \
-o -path ./demo/node_modules/\* \
-o -path ./site/themes/\* \
\) \
-exec sh -c '[ -n "$(tail -c 1 $1)" ] && echo >> $1' sh {} \;
}

cd "${ROOT_DIR}" && update_ends_newline
37 changes: 37 additions & 0 deletions hack/update-go-format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
# Copyright 2023 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

DIR="$(dirname "${BASH_SOURCE[0]}")"

ROOT_DIR="$(realpath "${DIR}/..")"

function format() {
echo "Update go format"
mapfile -t findfiles < <(find . \( \
-iname "*.go" \
\) \
-not \( \
-path ./vendor/\* \
-o -path ./demo/node_modules/\* \
-o -path ./site/themes/\* \
\))
gofmt -s -w "${findfiles[@]}"
}

cd "${ROOT_DIR}" && format
Loading

0 comments on commit a4a52b6

Please sign in to comment.