Skip to content

Commit

Permalink
update group to x-copilot.io
Browse files Browse the repository at this point in the history
  • Loading branch information
lengrongfu committed May 16, 2023
1 parent 36de789 commit 1d741a6
Show file tree
Hide file tree
Showing 11 changed files with 267 additions and 91 deletions.
163 changes: 163 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
run:
timeout: 10m

# The default concurrency value is the number of available CPU.
concurrency: 4

# which dirs to skip: issues from them won't be reported;
# can use regexp here: generated.*, regexp is applied on full path;
# default value is empty list, but default dirs are skipped independently
# from this option's value (see skip-dirs-use-default).
# "/" will be replaced by current OS file path separator to properly work
# on Windows.
skip-dirs:
- hack/tools/preferredimports # This code is directly lifted from the Kubernetes codebase, skip checking

# default is true. Enables skipping of directories:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs-use-default: true

# One of 'readonly' and 'vendor'.
# - readonly: the go command is disallowed from the implicit automatic updating of go.mod described above.
# Instead, it fails when any changes to go.mod are needed. This setting is most useful to check
# that go.mod does not need updates, such as in a continuous integration and testing system.
# - vendor: the go command assumes that the vendor directory holds the correct copies of dependencies and ignores
# the dependency descriptions in go.mod.
modules-download-mode: readonly

linters-settings:
depguard:
list-type: blacklist
include-go-root: false
dupl:
threshold: 800
errcheck:
check-type-assertions: true
check-blank: true
# exclude: .errcheckignore
errorlint:
errorf: true
asserts: true
comparison: true
goconst:
min-len: 3
min-occurrences: 3
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- commentedOutCode
- whyNoLint
settings:
hugeParam:
sizeThreshold: 80
rangeExprCopy:
sizeThreshold: 512
rangeValCopy:
sizeThreshold: 128
godot:
scope: declarations
capital: false
gofmt:
simplify: true
gofumpt:
extra-rules: true
goimports:
local-prefixes: github.com/copilot-io/runtime-copilot
gocyclo:
# minimal code complexity to report, 30 by default (but we recommend 10-20)
min-complexity: 20
nestif:
min-complexity: 20

output:
format: colored-line-number
print-issued-lines: true
print-linter-name: true
uniq-by-line: true
sort-results: true

linters:
disable-all: true
disabled:
- exhaustivestruct # Checks if all struct's fields are initialized
- forbidigo # Forbids identifiers
- forcetypeassert # finds forced type assertions
- gci # Gci control golang package import order and make it always deterministic.
- gochecknoglobals # check that no global variables exist
- gochecknoinits # Checks that no init functions are present in Go code
- goconst # Finds repeated strings that could be replaced by a constant
- godox # Tool for detection of FIXME, TODO and other comment keywords
- goerr113 # Golang linter to check the errors handling expressions
- golint # Golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes
- gomnd # An analyzer to detect magic numbers.
- gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod.
- gomodguard # Allow and block list linter for direct Go module dependencies.
- interfacer # Linter that suggests narrower interface types
- lll # Reports long lines
- maligned # Tool to detect Go structs that would take less memory if their fields were sorted
- promlinter # Check Prometheus metrics naming via promlint
- scopelint # Scopelint checks for unpinned variables in go programs
- sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed.
- testpackage # Linter that makes you use a separate _test package
- tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes
- wrapcheck # Checks that errors returned from external packages are wrapped
- wsl # Whitespace Linter
- paralleltest # paralleltest detects missing usage of t.Parallel() method in your Go test
- noctx # noctx finds sending http request without context.Context
- wastedassign # wastedassign finds wasted assignment statements.
- exhaustive # check exhaustiveness of enum switch statements
- cyclop # checks function and package cyclomatic complexity
- errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases
- unparam # Reports unused function parameters
- gosec # Inspects source code for security problems
- funlen # Tool for detection of long functions
- gocognit # Computes and checks the cognitive complexity of functions
- gocyclo # Computes and checks the cyclomatic complexity of functions
- nlreturn # nlreturn checks for a new line before return and branch statements to increase code clarity
- gocritic # Provides many diagnostics that check for bugs, performance and style issues.
- nestif # Reports deeply nested if statements
- bodyclose # checks whether HTTP response body is closed successfully
- errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13.
- tagliatelle # Checks the struct tags.
enable:
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers
- deadcode # Finds unused code
- depguard # Go linter that checks if package imports are in a list of acceptable packages
- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())
- dupl # Tool for code clone detection
- durationcheck # check for two durations multiplied together
- exportloopref # checks for pointers to enclosing loop variables
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification
- gofumpt # Gofumpt checks whether code was gofumpt-ed.
- goheader # Checks is file header matches to pattern
- goimports # Goimports does everything that gofmt does. Additionally it checks unused imports
- goprintffuncname # Checks that printf-like functions are named with `f` at the end
- gosimple # Linter for Go source code that specializes in simplifying a code
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
- ifshort # Checks that your code uses short syntax for if-statements whenever possible
- importas # Enforces consistent import aliases
- ineffassign # Detects when assignments to existing variables are not used
- makezero # Finds slice declarations with non-zero initial length
- misspell # Finds commonly misspelled English words in comments
- nakedret # Finds naked returns in functions greater than a specified function length
- nilerr # Finds the code that returns nil even if it checks that the error is not nil.
- nolintlint # Reports ill-formed or insufficient nolint directives
- prealloc # Finds slice declarations that could potentially be preallocated
- predeclared # find code that shadows one of Go's predeclared identifiers
- revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint.
- rowserrcheck # checks whether Err of rows is checked successfully
- staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks
- structcheck # Finds unused struct fields
- stylecheck # Stylecheck is a replacement for golint
- thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
- unconvert # Remove unnecessary type conversions
- unused # Checks Go code for unused constants, variables, functions and types
- varcheck # Finds unused global variables and constants
- whitespace # Tool for detection of leading and trailing whitespace
- godot # Check if comments end in a period
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ vet: ## Run go vet against code.
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out

.PHONY: lint
lint:
bash hack/verify-staticcheck.sh

.PHONY: verify-import-alias
verify-import-alias:
bash hack/verify-import-aliases.sh

##@ Build

.PHONY: build
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ The main function of the runtime copilot is to assist the operation of the conta

This project is a runtime copilot, auxiliary manager runtime, current function introduce the config insecure registry to runtime(such as: containerd、docker、cri-o), It mainly has the following functions:

[ ] Manager insecure registry in runtime.
[ ] Upgrade runtime version.
[ ] Replace runtime with another runtime.
[ ] Manager runtime plugins.


- [ ] Manager insecure registry in runtime.
- [ ] Upgrade runtime version.
- [ ] Replace runtime with another runtime.
- [ ] Manager runtime plugins.

### Manager insecure registry

Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "registry.runtime.x-copilot.io", 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
20 changes: 9 additions & 11 deletions api/v1alpha1/noderegistryconfigs_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ import (
)

type (
// RuntimeType is the type of runtime
// RuntimeType is the type of runtime.
RuntimeType string
// CapabilitieType is the type of capability
// CapabilitieType is the type of capability.
CapabilitieType string
// StatusState is the state of status
// StatusState is the state of status.
StatusState string
// ConditionType is the type of condition
// ConditionType is the type of condition.
ConditionType string
)

Expand All @@ -49,7 +49,7 @@ const (
ConditionTypeWriteDataError ConditionType = "WriteDataError"
ConditionTypeReadDataError ConditionType = "ReadDataError"

// MaxRetryNum is the max retry num
// MaxRetryNum is the max retry num.
MaxRetryNum = 3
)

Expand All @@ -68,7 +68,7 @@ func (ss StatusState) String() string {
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// NodeRegistryConfigsSpec defines the desired state of NodeRegistryConfigs
// NodeRegistryConfigsSpec defines the desired state of NodeRegistryConfigs.
type NodeRegistryConfigsSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file
Expand All @@ -81,8 +81,6 @@ type NodeRegistryConfigsSpec struct {
RetryNum int `json:"retry_num,omitempty"`
// HostConfigs store the per-host configuration
HostConfigs []NodeRegistryHostConfig `json:"hostConfigs,omitempty"`
// HostConfig is registry config host config
//NodeRegistryHostConfig `json:",inline,omitempty"`
}

type NodeRegistryHostConfig struct {
Expand All @@ -96,7 +94,7 @@ type NodeRegistryHostConfig struct {
CaSecretRef string `json:"ca_secret_ref,omitempty"`
}

// NodeRegistryConfigsStatus defines the observed state of NodeRegistryConfigs
// NodeRegistryConfigsStatus defines the observed state of NodeRegistryConfigs.
type NodeRegistryConfigsStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
Expand All @@ -109,7 +107,7 @@ type NodeRegistryConfigsStatus struct {
//+kubebuilder:subresource:status
//+kubebuilder:resource:scope=Cluster

// NodeRegistryConfigs is the Schema for the noderegistryconfigs API
// NodeRegistryConfigs is the Schema for the noderegistryconfigs API.
type NodeRegistryConfigs struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -120,7 +118,7 @@ type NodeRegistryConfigs struct {

//+kubebuilder:object:root=true

// NodeRegistryConfigsList contains a list of NodeRegistryConfigs
// NodeRegistryConfigsList contains a list of NodeRegistryConfigs.
type NodeRegistryConfigsList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down
12 changes: 6 additions & 6 deletions api/v1alpha1/registryconfigs_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// RegistryConfigsSpec defines the desired state of RegistryConfigs
// RegistryConfigsSpec defines the desired state of RegistryConfigs.
type RegistryConfigsSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file
Expand All @@ -33,19 +33,19 @@ type RegistryConfigsSpec struct {
Template RegistryConfigsTemplate `json:"template,omitempty"`
}

// RegistryConfigsTemplate defines the template for the registry config
// RegistryConfigsTemplate defines the template for the registry config.
type RegistryConfigsTemplate struct {
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec NodeHostConfigsSpec `json:"spec"`
}

// NodeHostConfigsSpec defines the host config for the registry
// NodeHostConfigsSpec defines the host config for the registry.
type NodeHostConfigsSpec struct {
RetryNum int `json:"retry_num,omitempty"`
HostConfigs []NodeRegistryHostConfig `json:"hostConfigs"`
}

// RegistryConfigsStatus defines the observed state of RegistryConfigs
// RegistryConfigsStatus defines the observed state of RegistryConfigs.
type RegistryConfigsStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
Expand All @@ -67,7 +67,7 @@ type RuntimeNum struct {
//+kubebuilder:subresource:status
//+kubebuilder:resource:scope=Cluster

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

//+kubebuilder:object:root=true

// RegistryConfigsList contains a list of RegistryConfigs
// RegistryConfigsList contains a list of RegistryConfigs.
type RegistryConfigsList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down
5 changes: 2 additions & 3 deletions hack/tools/preferredimports/preferredimports.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"go/format"
"go/parser"
"go/token"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -135,7 +134,7 @@ func (a *analyzer) collect(dir string) {
panic(fmt.Sprintf("Error stat'ing file: %s\n%s\n", pathToFile, err.Error()))
}

err = ioutil.WriteFile(pathToFile, buffer.Bytes(), fileInfo.Mode())
err = os.WriteFile(pathToFile, buffer.Bytes(), fileInfo.Mode())
if err != nil {
panic(fmt.Sprintf("Error writing file: %s\n%s\n", pathToFile, err.Error()))
}
Expand Down Expand Up @@ -253,7 +252,7 @@ func main() {
sort.Strings(c.dirs)

if len(*importAliases) > 0 {
bytes, err := ioutil.ReadFile(*importAliases)
bytes, err := os.ReadFile(*importAliases)
if err != nil {
log.Fatalf("Error reading import aliases: %v", err)
}
Expand Down
Loading

0 comments on commit 1d741a6

Please sign in to comment.