Skip to content

Commit

Permalink
style(pkg/common): improve code readability and maintainability
Browse files Browse the repository at this point in the history
Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com>
  • Loading branch information
cubxxw committed Mar 22, 2023
1 parent 9f84736 commit 687ec01
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ifeq ($(OS),Windows_NT)
SHELL:=cmd.exe

# Need BLANK due to makefile parsing of `\`
# (see: <https://stackoverflow.com/questions/54733231/how-to-escape-a-backslash-in-the-end-to-mean-literal-backslash-in-makefile/54733416#54733416>)
# (see: https://stackoverflow.com/questions/54733231/how-to-escape-a-backslash-in-the-end-to-mean-literal-backslash-in-makefile/54733416#54733416)
BLANK:=

# Define variable named `/` to represent OS path separator (usable as `$/` in this file)
Expand Down Expand Up @@ -87,7 +87,7 @@ lint: install-golangci-lint
## test: Run unit and acceptance tests
test: unit acceptance

## unit: Run unit tests
## unit: Append coverage arguments
ifeq ($(TEST_COVERAGE), 1)
unit: GOTESTFLAGS:=$(GOTESTFLAGS) -coverprofile=./out/tests/coverage-unit.txt -covermode=atomic
endif
Expand Down
10 changes: 3 additions & 7 deletions pkg/client/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (c *Client) parseTagReference(imageName string) (name.Reference, error) {
return nil, errors.New("image is a required parameter")
}
if _, err := name.ParseReference(imageName, name.WeakValidation); err != nil {
return nil, err
return nil, fmt.Errorf("'%s' is not a valid tag reference: %s", imageName, err)
}
ref, err := name.NewTag(imageName, name.WeakValidation)
if err != nil {
Expand Down Expand Up @@ -108,17 +108,13 @@ func contains(slc []string, v string) bool {
}

func getBestRunMirror(registry string, runImage string, mirrors []string, preferredMirrors []string) string {
var runImageList []string
runImageList = append(runImageList, preferredMirrors...)
runImageList = append(runImageList, runImage)
runImageList = append(runImageList, mirrors...)

runImageList := append(append(append([]string{}, preferredMirrors...), runImage), mirrors...)
for _, img := range runImageList {
ref, err := name.ParseReference(img, name.WeakValidation)
if err != nil {
continue
}
if ref.Context().RegistryStr() == registry {
if reg := ref.Context().RegistryStr(); reg == registry {
return img
}
}
Expand Down

0 comments on commit 687ec01

Please sign in to comment.