Skip to content

Commit

Permalink
chore: fix go lint.
Browse files Browse the repository at this point in the history
Signed-off-by: Syulin7 <735122171@qq.com>
  • Loading branch information
Syulin7 committed Jan 18, 2024
1 parent 10e1e62 commit 70aa5bb
Show file tree
Hide file tree
Showing 158 changed files with 465 additions and 1,199 deletions.
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,13 @@ fmt: ## Run go fmt against code.
vet: ## Run go vet against code.
go vet ./...

GOLANGCI_LINT=$(shell which golangci-lint)
golangci-lint:
ifeq ($(GOLANGCI_LINT),)
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.53.3
$(info golangci-lint has been installed)
endif
golangci-lint run --timeout 5m --go 1.18 ./...

build-dependabot:
python3 hack/create_dependabot.py
5 changes: 4 additions & 1 deletion cmd/arena/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ func main() {
defer cpuf.Close()

runtime.SetCPUProfileRate(getProfileHZ())
pprof.StartCPUProfile(cpuf)
err = pprof.StartCPUProfile(cpuf)
if err != nil {
log.Fatal(err)
}
log.Infof("Dump cpu profile file into /tmp/cpu_profile")
defer pprof.StopCPUProfile()
}
Expand Down
45 changes: 3 additions & 42 deletions cmd/uninstall/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ func deleteArenaArtifacts(force bool) error {
return err
}
}
execCommand([]string{"arena-helm", "del", "arena-artifacts", "-n", *arenaNamespace})
stdout, stderr, err = execCommand([]string{"arena-kubectl", "delete", "-f", tmpFile})
stdout, stderr, _ = execCommand([]string{"arena-helm", "del", "arena-artifacts", "-n", *arenaNamespace})
fmt.Printf("%v,%v\n", stdout, stderr)
stdout, stderr, _ = execCommand([]string{"arena-kubectl", "delete", "-f", tmpFile})
fmt.Printf("%v,%v\n", stdout, stderr)
stdout, stderr, err = execCommand([]string{"arena-kubectl", "delete", "ns", *arenaNamespace})
if err != nil {
Expand Down Expand Up @@ -232,46 +233,6 @@ func getAllCRDsInK8s() ([]string, error) {
return crds, nil
}

func deleteClientFiles() {
execCommand([]string{"rm", "-rf", "/charts"})
execCommand([]string{"rm", "-rf", "~/charts"})
execCommand([]string{"rm", "-rf", "/usr/local/bin/arena"})
execCommand([]string{"rm", "-rf", "/usr/local/bin/arena-kubectl"})
execCommand([]string{"rm", "-rf", "/usr/local/bin/arena-helm"})
if err := removeLines([]string{"source <(arena completion bash)"}); err != nil {
fmt.Printf("Error: failed to remove line 'source <(arena completion bash)' from ~/bashrc or ~/.zshrc\n")
os.Exit(4)
}
}

func removeLines(lines []string) error {
homeDir := os.Getenv("HOME")
bashFile := path.Join(homeDir, ".bashrc")
zshFile := path.Join(homeDir, ".zshrc")
updateFile := func(f string) error {
contentBytes, err := ioutil.ReadFile(f)
if err != nil {
return err
}
content := string(contentBytes)
for _, line := range lines {
content = strings.ReplaceAll(content, line, "")
}
return ioutil.WriteFile(f, []byte(content), 0744)
}
if CheckFileExist(zshFile) {
if err := updateFile(zshFile); err != nil {
return err
}
}
if CheckFileExist(bashFile) {
if err := updateFile(bashFile); err != nil {
return err
}
}
return nil
}

func execCommand(args []string) (string, string, error) {
var stdout bytes.Buffer
var stderr bytes.Buffer
Expand Down
4 changes: 3 additions & 1 deletion pkg/apis/arenaclient/cron_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ func (c *CronClient) Delete(names ...string) error {
continue
}

cron.DeleteCron(name, c.namespace, cronInfo.Type)
if err := cron.DeleteCron(name, c.namespace, cronInfo.Type); err != nil {
return err
}
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/arenaclient/serving_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (t *ServingJobClient) TrafficRouterSplit(args *types.TrafficRouterSplitArgs
func moreThanOneInstanceHelpInfo(instances []types.ServingInstance) string {
header := fmt.Sprintf("There is %d instances have been found:", len(instances))
lines := []string{}
footer := fmt.Sprintf("please use '-i' or '--instance' to filter.")
footer := "please use '-i' or '--instance' to filter."
for _, i := range instances {
lines = append(lines, fmt.Sprintf("%v", i.Name))
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/attach/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (a *AttachBuilder) IOStreams(stream genericclioptions.IOStreams) *AttachBui
}

func (a *AttachBuilder) Command(command []string) *AttachBuilder {
if command != nil && len(command) != 0 {
if len(command) != 0 {
a.args.Command = command
}
return a
Expand Down
14 changes: 0 additions & 14 deletions pkg/apis/config/arenaconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,17 +303,3 @@ func isolateUserInNamespace(namespaceName string, clientSet *kubernetes.Clientse
}
return namespace.Labels[types.MultiTenantIsolationLabel] == "true", nil
}

func getClusterInstalledCRDs(client *extclientset.Clientset) ([]string, error) {
selectorListOpts := metav1.ListOptions{}

list, err := client.ApiextensionsV1().CustomResourceDefinitions().List(context.TODO(), selectorListOpts)
if err != nil {
return nil, err
}
crds := []string{}
for _, crd := range list.Items {
crds = append(crds, crd.Name)
}
return crds, nil
}
10 changes: 5 additions & 5 deletions pkg/apis/evaluate/evaluatejob_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (e *EvaluateJobBuilder) WorkingDir(dir string) *EvaluateJobBuilder {

// Envs is used to set env of job containers,match option --env
func (e *EvaluateJobBuilder) Envs(envs map[string]string) *EvaluateJobBuilder {
if envs != nil && len(envs) != 0 {
if len(envs) != 0 {
envSlice := []string{}
for key, value := range envs {
envSlice = append(envSlice, fmt.Sprintf("%v=%v", key, value))
Expand All @@ -81,7 +81,7 @@ func (e *EvaluateJobBuilder) Tolerations(tolerations []string) *EvaluateJobBuild

// NodeSelectors is used to set node selectors for scheduling job,match option --selector
func (e *EvaluateJobBuilder) NodeSelectors(selectors map[string]string) *EvaluateJobBuilder {
if selectors != nil && len(selectors) != 0 {
if len(selectors) != 0 {
selectorsSlice := []string{}
for key, value := range selectors {
selectorsSlice = append(selectorsSlice, fmt.Sprintf("%v=%v", key, value))
Expand All @@ -93,7 +93,7 @@ func (e *EvaluateJobBuilder) NodeSelectors(selectors map[string]string) *Evaluat

// Annotations is used to add annotations for job pods,match option --annotation
func (e *EvaluateJobBuilder) Annotations(annotations map[string]string) *EvaluateJobBuilder {
if annotations != nil && len(annotations) != 0 {
if len(annotations) != 0 {
s := []string{}
for key, value := range annotations {
s = append(s, fmt.Sprintf("%v=%v", key, value))
Expand All @@ -105,7 +105,7 @@ func (e *EvaluateJobBuilder) Annotations(annotations map[string]string) *Evaluat

// DataDirs is used to mount host files to job containers,match option --data-dir
func (e *EvaluateJobBuilder) DataDirs(volumes map[string]string) *EvaluateJobBuilder {
if volumes != nil && len(volumes) != 0 {
if len(volumes) != 0 {
s := []string{}
for key, value := range volumes {
s = append(s, fmt.Sprintf("%v:%v", key, value))
Expand All @@ -117,7 +117,7 @@ func (e *EvaluateJobBuilder) DataDirs(volumes map[string]string) *EvaluateJobBui

// Datas is used to mount host files to job containers,match option --data
func (e *EvaluateJobBuilder) Datas(volumes map[string]string) *EvaluateJobBuilder {
if volumes != nil && len(volumes) != 0 {
if len(volumes) != 0 {
s := []string{}
for key, value := range volumes {
s = append(s, fmt.Sprintf("%v:%v", key, value))
Expand Down
12 changes: 6 additions & 6 deletions pkg/apis/model/benchmark_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (m *ModelBenchmarkArgsBuilder) Memory(memory string) *ModelBenchmarkArgsBui

// Envs is used to set env of job containers,match option --env
func (m *ModelBenchmarkArgsBuilder) Envs(envs map[string]string) *ModelBenchmarkArgsBuilder {
if envs != nil && len(envs) != 0 {
if len(envs) != 0 {
envSlice := []string{}
for key, value := range envs {
envSlice = append(envSlice, fmt.Sprintf("%v=%v", key, value))
Expand All @@ -141,7 +141,7 @@ func (m *ModelBenchmarkArgsBuilder) Tolerations(tolerations []string) *ModelBenc

// NodeSelectors is used to set node selectors for scheduling job,match option --selector
func (m *ModelBenchmarkArgsBuilder) NodeSelectors(selectors map[string]string) *ModelBenchmarkArgsBuilder {
if selectors != nil && len(selectors) != 0 {
if len(selectors) != 0 {
selectorsSlice := []string{}
for key, value := range selectors {
selectorsSlice = append(selectorsSlice, fmt.Sprintf("%v=%v", key, value))
Expand All @@ -153,7 +153,7 @@ func (m *ModelBenchmarkArgsBuilder) NodeSelectors(selectors map[string]string) *

// Annotations is used to add annotations for job pods,match option --annotation
func (m *ModelBenchmarkArgsBuilder) Annotations(annotations map[string]string) *ModelBenchmarkArgsBuilder {
if annotations != nil && len(annotations) != 0 {
if len(annotations) != 0 {
s := []string{}
for key, value := range annotations {
s = append(s, fmt.Sprintf("%v=%v", key, value))
Expand All @@ -165,7 +165,7 @@ func (m *ModelBenchmarkArgsBuilder) Annotations(annotations map[string]string) *

// Labels is used to add labels for job
func (m *ModelBenchmarkArgsBuilder) Labels(labels map[string]string) *ModelBenchmarkArgsBuilder {
if labels != nil && len(labels) != 0 {
if len(labels) != 0 {
s := []string{}
for key, value := range labels {
s = append(s, fmt.Sprintf("%v=%v", key, value))
Expand All @@ -177,7 +177,7 @@ func (m *ModelBenchmarkArgsBuilder) Labels(labels map[string]string) *ModelBench

// Datas is used to mount k8s pvc to job pods,match option --data
func (m *ModelBenchmarkArgsBuilder) Datas(volumes map[string]string) *ModelBenchmarkArgsBuilder {
if volumes != nil && len(volumes) != 0 {
if len(volumes) != 0 {
s := []string{}
for key, value := range volumes {
s = append(s, fmt.Sprintf("%v:%v", key, value))
Expand All @@ -189,7 +189,7 @@ func (m *ModelBenchmarkArgsBuilder) Datas(volumes map[string]string) *ModelBench

// DataDirs is used to mount host files to job containers,match option --data-dir
func (m *ModelBenchmarkArgsBuilder) DataDirs(volumes map[string]string) *ModelBenchmarkArgsBuilder {
if volumes != nil && len(volumes) != 0 {
if len(volumes) != 0 {
s := []string{}
for key, value := range volumes {
s = append(s, fmt.Sprintf("%v:%v", key, value))
Expand Down
12 changes: 6 additions & 6 deletions pkg/apis/model/evaluate_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (m *ModelEvaluateJobBuilder) Memory(memory string) *ModelEvaluateJobBuilder

// Envs is used to set env of job containers,match option --env
func (m *ModelEvaluateJobBuilder) Envs(envs map[string]string) *ModelEvaluateJobBuilder {
if envs != nil && len(envs) != 0 {
if len(envs) != 0 {
envSlice := []string{}
for key, value := range envs {
envSlice = append(envSlice, fmt.Sprintf("%v=%v", key, value))
Expand All @@ -141,7 +141,7 @@ func (m *ModelEvaluateJobBuilder) Tolerations(tolerations []string) *ModelEvalua

// NodeSelectors is used to set node selectors for scheduling job,match option --selector
func (m *ModelEvaluateJobBuilder) NodeSelectors(selectors map[string]string) *ModelEvaluateJobBuilder {
if selectors != nil && len(selectors) != 0 {
if len(selectors) != 0 {
selectorsSlice := []string{}
for key, value := range selectors {
selectorsSlice = append(selectorsSlice, fmt.Sprintf("%v=%v", key, value))
Expand All @@ -153,7 +153,7 @@ func (m *ModelEvaluateJobBuilder) NodeSelectors(selectors map[string]string) *Mo

// Annotations is used to add annotations for job pods,match option --annotation
func (m *ModelEvaluateJobBuilder) Annotations(annotations map[string]string) *ModelEvaluateJobBuilder {
if annotations != nil && len(annotations) != 0 {
if len(annotations) != 0 {
s := []string{}
for key, value := range annotations {
s = append(s, fmt.Sprintf("%v=%v", key, value))
Expand All @@ -165,7 +165,7 @@ func (m *ModelEvaluateJobBuilder) Annotations(annotations map[string]string) *Mo

// Labels is used to add labels for job
func (m *ModelEvaluateJobBuilder) Labels(labels map[string]string) *ModelEvaluateJobBuilder {
if labels != nil && len(labels) != 0 {
if len(labels) != 0 {
s := []string{}
for key, value := range labels {
s = append(s, fmt.Sprintf("%v=%v", key, value))
Expand All @@ -177,7 +177,7 @@ func (m *ModelEvaluateJobBuilder) Labels(labels map[string]string) *ModelEvaluat

// Datas is used to mount k8s pvc to job pods,match option --data
func (m *ModelEvaluateJobBuilder) Datas(volumes map[string]string) *ModelEvaluateJobBuilder {
if volumes != nil && len(volumes) != 0 {
if len(volumes) != 0 {
s := []string{}
for key, value := range volumes {
s = append(s, fmt.Sprintf("%v:%v", key, value))
Expand All @@ -189,7 +189,7 @@ func (m *ModelEvaluateJobBuilder) Datas(volumes map[string]string) *ModelEvaluat

// DataDirs is used to mount host files to job containers,match option --data-dir
func (m *ModelEvaluateJobBuilder) DataDirs(volumes map[string]string) *ModelEvaluateJobBuilder {
if volumes != nil && len(volumes) != 0 {
if len(volumes) != 0 {
s := []string{}
for key, value := range volumes {
s = append(s, fmt.Sprintf("%v:%v", key, value))
Expand Down
12 changes: 6 additions & 6 deletions pkg/apis/model/optimize_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (m *ModelOptimizeJobBuilder) Memory(memory string) *ModelOptimizeJobBuilder

// Envs is used to set env of job containers,match option --env
func (m *ModelOptimizeJobBuilder) Envs(envs map[string]string) *ModelOptimizeJobBuilder {
if envs != nil && len(envs) != 0 {
if len(envs) != 0 {
envSlice := []string{}
for key, value := range envs {
envSlice = append(envSlice, fmt.Sprintf("%v=%v", key, value))
Expand All @@ -141,7 +141,7 @@ func (m *ModelOptimizeJobBuilder) Tolerations(tolerations []string) *ModelOptimi

// NodeSelectors is used to set node selectors for scheduling job,match option --selector
func (m *ModelOptimizeJobBuilder) NodeSelectors(selectors map[string]string) *ModelOptimizeJobBuilder {
if selectors != nil && len(selectors) != 0 {
if len(selectors) != 0 {
selectorsSlice := []string{}
for key, value := range selectors {
selectorsSlice = append(selectorsSlice, fmt.Sprintf("%v=%v", key, value))
Expand All @@ -153,7 +153,7 @@ func (m *ModelOptimizeJobBuilder) NodeSelectors(selectors map[string]string) *Mo

// Annotations is used to add annotations for job pods,match option --annotation
func (m *ModelOptimizeJobBuilder) Annotations(annotations map[string]string) *ModelOptimizeJobBuilder {
if annotations != nil && len(annotations) != 0 {
if len(annotations) != 0 {
s := []string{}
for key, value := range annotations {
s = append(s, fmt.Sprintf("%v=%v", key, value))
Expand All @@ -165,7 +165,7 @@ func (m *ModelOptimizeJobBuilder) Annotations(annotations map[string]string) *Mo

// Labels is used to add labels for job
func (m *ModelOptimizeJobBuilder) Labels(labels map[string]string) *ModelOptimizeJobBuilder {
if labels != nil && len(labels) != 0 {
if len(labels) != 0 {
s := []string{}
for key, value := range labels {
s = append(s, fmt.Sprintf("%v=%v", key, value))
Expand All @@ -177,7 +177,7 @@ func (m *ModelOptimizeJobBuilder) Labels(labels map[string]string) *ModelOptimiz

// Datas is used to mount k8s pvc to job pods,match option --data
func (m *ModelOptimizeJobBuilder) Datas(volumes map[string]string) *ModelOptimizeJobBuilder {
if volumes != nil && len(volumes) != 0 {
if len(volumes) != 0 {
s := []string{}
for key, value := range volumes {
s = append(s, fmt.Sprintf("%v:%v", key, value))
Expand All @@ -189,7 +189,7 @@ func (m *ModelOptimizeJobBuilder) Datas(volumes map[string]string) *ModelOptimiz

// DataDirs is used to mount host files to job containers,match option --data-dir
func (m *ModelOptimizeJobBuilder) DataDirs(volumes map[string]string) *ModelOptimizeJobBuilder {
if volumes != nil && len(volumes) != 0 {
if len(volumes) != 0 {
s := []string{}
for key, value := range volumes {
s = append(s, fmt.Sprintf("%v:%v", key, value))
Expand Down
12 changes: 6 additions & 6 deletions pkg/apis/model/profile_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (m *ModelProfileJobBuilder) Memory(memory string) *ModelProfileJobBuilder {

// Envs is used to set env of job containers,match option --env
func (m *ModelProfileJobBuilder) Envs(envs map[string]string) *ModelProfileJobBuilder {
if envs != nil && len(envs) != 0 {
if len(envs) != 0 {
envSlice := []string{}
for key, value := range envs {
envSlice = append(envSlice, fmt.Sprintf("%v=%v", key, value))
Expand All @@ -141,7 +141,7 @@ func (m *ModelProfileJobBuilder) Tolerations(tolerations []string) *ModelProfile

// NodeSelectors is used to set node selectors for scheduling job,match option --selector
func (m *ModelProfileJobBuilder) NodeSelectors(selectors map[string]string) *ModelProfileJobBuilder {
if selectors != nil && len(selectors) != 0 {
if len(selectors) != 0 {
selectorsSlice := []string{}
for key, value := range selectors {
selectorsSlice = append(selectorsSlice, fmt.Sprintf("%v=%v", key, value))
Expand All @@ -153,7 +153,7 @@ func (m *ModelProfileJobBuilder) NodeSelectors(selectors map[string]string) *Mod

// Annotations is used to add annotations for job pods,match option --annotation
func (m *ModelProfileJobBuilder) Annotations(annotations map[string]string) *ModelProfileJobBuilder {
if annotations != nil && len(annotations) != 0 {
if len(annotations) != 0 {
s := []string{}
for key, value := range annotations {
s = append(s, fmt.Sprintf("%v=%v", key, value))
Expand All @@ -165,7 +165,7 @@ func (m *ModelProfileJobBuilder) Annotations(annotations map[string]string) *Mod

// Labels is used to add labels for job
func (m *ModelProfileJobBuilder) Labels(labels map[string]string) *ModelProfileJobBuilder {
if labels != nil && len(labels) != 0 {
if len(labels) != 0 {
s := []string{}
for key, value := range labels {
s = append(s, fmt.Sprintf("%v=%v", key, value))
Expand All @@ -177,7 +177,7 @@ func (m *ModelProfileJobBuilder) Labels(labels map[string]string) *ModelProfileJ

// Datas is used to mount k8s pvc to job pods,match option --data
func (m *ModelProfileJobBuilder) Datas(volumes map[string]string) *ModelProfileJobBuilder {
if volumes != nil && len(volumes) != 0 {
if len(volumes) != 0 {
s := []string{}
for key, value := range volumes {
s = append(s, fmt.Sprintf("%v:%v", key, value))
Expand All @@ -189,7 +189,7 @@ func (m *ModelProfileJobBuilder) Datas(volumes map[string]string) *ModelProfileJ

// DataDirs is used to mount host files to job containers,match option --data-dir
func (m *ModelProfileJobBuilder) DataDirs(volumes map[string]string) *ModelProfileJobBuilder {
if volumes != nil && len(volumes) != 0 {
if len(volumes) != 0 {
s := []string{}
for key, value := range volumes {
s = append(s, fmt.Sprintf("%v:%v", key, value))
Expand Down
Loading

0 comments on commit 70aa5bb

Please sign in to comment.