Skip to content

Commit

Permalink
Merge pull request #4547 from werf/chore-fix-linters-formatters
Browse files Browse the repository at this point in the history
chore: fix and update linters/formatters
  • Loading branch information
ilya-lesikov committed Jun 16, 2022
2 parents 6219381 + 0343969 commit 3edb2de
Show file tree
Hide file tree
Showing 57 changed files with 128 additions and 124 deletions.
10 changes: 9 additions & 1 deletion .golangci.yaml
Expand Up @@ -2,10 +2,18 @@ run:
timeout: 10m
skip-dirs:
- playground
- docs
- scripts
- stapel

linters-settings:
gofumpt:
extra-rules: true
gci:
local-prefixes: github.com/werf/
sections:
- standard
- default
- prefix(github.com/werf/)
gocritic:
disabled-checks:
- ifElseChain
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Expand Up @@ -41,8 +41,8 @@ unit-tests:
CGO_ENABLED=1 go test -v -compiler gc -ldflags="-linkmode external -extldflags=-static" -tags="dfrunmount dfssh containers_image_openpgp osusergo exclude_graphdriver_devicemapper netgo no_devmapper static_build" github.com/werf/werf/pkg/...

fmt:
gci -w -local github.com/werf/ pkg/ cmd/ test/
gofumpt -w cmd/ pkg/ test/ integration/
gci write -s Standard -s Default -s 'Prefix(github.com/werf)' pkg/ cmd/ test/ integration/
gofumpt -extra -w cmd/ pkg/ test/ integration/

lint:
golangci-lint run ./... --build-tags="dfrunmount dfssh containers_image_openpgp osusergo exclude_graphdriver_devicemapper netgo no_devmapper static_build"
Expand Down
2 changes: 1 addition & 1 deletion cmd/werf/common/templates/templater.go
Expand Up @@ -250,7 +250,7 @@ func appendIfNotPresent(s, stringToAppend string) string {
return s + " " + stringToAppend
}

func flagsNotIntersected(l *flag.FlagSet, r *flag.FlagSet) *flag.FlagSet {
func flagsNotIntersected(l, r *flag.FlagSet) *flag.FlagSet {
f := flag.NewFlagSet("notIntersected", flag.ContinueOnError)
l.VisitAll(func(flag *flag.Flag) {
if r.Lookup(flag.Name) == nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/werf/export/export.go
Expand Up @@ -270,7 +270,7 @@ func getExportTagFunc(tmpl *template.Template, templateName string, imageNameLis

tagOrFormat := buf.String()
var tagFunc image.ExportTagFunc
tagFunc = func(imageName string, contentBasedTag string) string {
tagFunc = func(imageName, contentBasedTag string) string {
if strings.ContainsRune(tagOrFormat, '%') {
return fmt.Sprintf(tagOrFormat, imageName, slug.Slug(imageName), slug.DockerTag(imageName), contentBasedTag)
} else {
Expand Down
10 changes: 5 additions & 5 deletions cmd/werf/kube_run/kube_run.go
Expand Up @@ -510,7 +510,7 @@ func createPod(ctx context.Context, namespace, pod, image, secret string, extraA
return nil
}

func createKubectlRunArgs(pod string, image string, secret string, extraArgs []string) ([]string, error) {
func createKubectlRunArgs(pod, image, secret string, extraArgs []string) ([]string, error) {
args := []string{
"run",
pod,
Expand Down Expand Up @@ -639,7 +639,7 @@ func waitPodReadiness(ctx context.Context, namespace, pod string, extraArgs []st
}
}

func getPodPhase(namespace string, pod string, extraArgs []string) (corev1.PodPhase, error) {
func getPodPhase(namespace, pod string, extraArgs []string) (corev1.PodPhase, error) {
args := []string{
"get", "pod", "--template", "{{.status.phase}}", pod,
}
Expand All @@ -658,7 +658,7 @@ func getPodPhase(namespace string, pod string, extraArgs []string) (corev1.PodPh
return corev1.PodPhase(strings.TrimSpace(stdout.String())), nil
}

func isPodReady(namespace string, pod string, extraArgs []string) (bool, error) {
func isPodReady(namespace, pod string, extraArgs []string) (bool, error) {
args := []string{
"get", "pod", "--template", "{{range .status.conditions}}{{if eq .type \"Ready\"}}{{.status}}{{end}}{{end}}", pod,
}
Expand Down Expand Up @@ -907,7 +907,7 @@ func isNamespaceExist(ctx context.Context, namespace string) (bool, error) {
return false, nil
}

func isPodExist(ctx context.Context, pod string, namespace string) (bool, error) {
func isPodExist(ctx context.Context, pod, namespace string) (bool, error) {
if matchedPods, err := kube.Client.CoreV1().Pods(namespace).List(ctx, v1.ListOptions{
FieldSelector: fields.OneTermEqualSelector("metadata.name", pod).String(),
}); err != nil {
Expand All @@ -919,7 +919,7 @@ func isPodExist(ctx context.Context, pod string, namespace string) (bool, error)
return false, nil
}

func isSecretExist(ctx context.Context, secret string, namespace string) (bool, error) {
func isSecretExist(ctx context.Context, secret, namespace string) (bool, error) {
if matchedSecrets, err := kube.Client.CoreV1().Secrets(namespace).List(ctx, v1.ListOptions{
FieldSelector: fields.OneTermEqualSelector("metadata.name", secret).String(),
}); err != nil {
Expand Down
3 changes: 1 addition & 2 deletions cmd/werf/main.go
Expand Up @@ -6,10 +6,9 @@ import (
"os"
"path/filepath"

helm_v3 "helm.sh/helm/v3/cmd/helm"

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
helm_v3 "helm.sh/helm/v3/cmd/helm"

"github.com/werf/logboek"
"github.com/werf/werf/cmd/werf/build"
Expand Down
6 changes: 3 additions & 3 deletions integration/suites/build/stapel_image/git/stages_test.go
Expand Up @@ -547,23 +547,23 @@ func checkResultedFilesChecksum() {
)
}

func createAndCommitFile(dirPath string, filename string, contentSize int) {
func createAndCommitFile(dirPath, filename string, contentSize int) {
newFilePath := filepath.Join(dirPath, filename)
newFileData := []byte(utils.GetRandomString(contentSize))
utils.WriteFile(newFilePath, newFileData)

addAndCommitFile(dirPath, filename, "Add file "+filename)
}

func addFile(dirPath string, filename string) {
func addFile(dirPath, filename string) {
utils.RunSucceedCommand(
dirPath,
"git",
"add", filename,
)
}

func addAndCommitFile(dirPath string, filename string, commitMsg string) {
func addAndCommitFile(dirPath, filename, commitMsg string) {
addFile(dirPath, filename)

utils.RunSucceedCommand(
Expand Down
2 changes: 1 addition & 1 deletion integration/suites/cleanup/suite_test.go
Expand Up @@ -61,7 +61,7 @@ func perImplementationBeforeEach(implementationName string) func() {
}
}

func InitStagesStorage(stagesStorageAddress string, implementationName string, dockerRegistryOptions docker_registry.DockerRegistryOptions) {
func InitStagesStorage(stagesStorageAddress, implementationName string, dockerRegistryOptions docker_registry.DockerRegistryOptions) {
SuiteData.StagesStorage = utils.NewStagesStorage(stagesStorageAddress, implementationName, dockerRegistryOptions)
}

Expand Down
6 changes: 3 additions & 3 deletions integration/suites/giterminism/common_test.go
Expand Up @@ -60,7 +60,7 @@ func fileCreateOrAppend(relPath, content string) {
Ω(f.Close()).ShouldNot(HaveOccurred())
}

func symlinkFileCreateOrModify(relPath string, link string) {
func symlinkFileCreateOrModify(relPath, link string) {
relPath = filepath.ToSlash(relPath)
link = filepath.ToSlash(link)

Expand All @@ -73,7 +73,7 @@ func symlinkFileCreateOrModify(relPath string, link string) {
)
}

func symlinkFileCreateOrModifyAndAdd(relPath string, link string) {
func symlinkFileCreateOrModifyAndAdd(relPath, link string) {
relPath = filepath.ToSlash(relPath)
link = filepath.ToSlash(link)

Expand All @@ -100,7 +100,7 @@ func symlinkFileCreateOrModifyAndAdd(relPath string, link string) {
)
}

func getLinkTo(linkFile string, targetPath string) string {
func getLinkTo(linkFile, targetPath string) string {
target, err := filepath.Rel(filepath.Dir(linkFile), targetPath)
if err != nil {
panic(err)
Expand Down
13 changes: 6 additions & 7 deletions pkg/build/build_phase.go
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/werf/werf/pkg/container_backend"
"github.com/werf/werf/pkg/docker_registry"
"github.com/werf/werf/pkg/git_repo"
"github.com/werf/werf/pkg/image"
imagePkg "github.com/werf/werf/pkg/image"
"github.com/werf/werf/pkg/stapel"
"github.com/werf/werf/pkg/storage"
Expand All @@ -44,7 +43,7 @@ type BuildOptions struct {
ReportFormat ReportFormat

SkipImageMetadataPublication bool
CustomTagFuncList []image.CustomTagFunc
CustomTagFuncList []imagePkg.CustomTagFunc
}

type IntrospectOptions struct {
Expand Down Expand Up @@ -249,7 +248,7 @@ func (phase *BuildPhase) AfterImageStages(ctx context.Context, img *Image) error
}

var customTagStorage storage.StagesStorage
var customTagStage *image.StageDescription
var customTagStage *imagePkg.StageDescription
if phase.Conveyor.StorageManager.GetFinalStagesStorage() != nil {
customTagStorage = phase.Conveyor.StorageManager.GetFinalStagesStorage()
customTagStage = manager.ConvertStageDescriptionForStagesStorage(img.GetLastNonEmptyStage().GetStageImage().Image.GetStageDescription(), phase.Conveyor.StorageManager.GetFinalStagesStorage())
Expand Down Expand Up @@ -326,11 +325,11 @@ func (phase *BuildPhase) publishImageMetadata(ctx context.Context, img *Image) e
})
}

func (phase *BuildPhase) addCustomImageTagsToStagesStorage(ctx context.Context, imageName string, stageDesc *image.StageDescription, stagesStorage storage.StagesStorage) error {
func (phase *BuildPhase) addCustomImageTagsToStagesStorage(ctx context.Context, imageName string, stageDesc *imagePkg.StageDescription, stagesStorage storage.StagesStorage) error {
return addCustomImageTags(ctx, stagesStorage, imageName, stageDesc, phase.CustomTagFuncList)
}

func addCustomImageTags(ctx context.Context, stagesStorage storage.StagesStorage, imageName string, stageDesc *image.StageDescription, customTagFuncList []image.CustomTagFunc) error {
func addCustomImageTags(ctx context.Context, stagesStorage storage.StagesStorage, imageName string, stageDesc *imagePkg.StageDescription, customTagFuncList []imagePkg.CustomTagFunc) error {
if len(customTagFuncList) == 0 {
return nil
}
Expand All @@ -351,7 +350,7 @@ func addCustomImageTags(ctx context.Context, stagesStorage storage.StagesStorage
})
}

func addCustomImageTag(ctx context.Context, stagesStorage storage.StagesStorage, stageDesc *image.StageDescription, tag string) error {
func addCustomImageTag(ctx context.Context, stagesStorage storage.StagesStorage, stageDesc *imagePkg.StageDescription, tag string) error {
return logboek.Context(ctx).Default().LogProcess("tag %s", tag).
DoError(func() error {
if err := stagesStorage.AddStageCustomTag(ctx, stageDesc, tag); err != nil {
Expand All @@ -364,7 +363,7 @@ func addCustomImageTag(ctx context.Context, stagesStorage storage.StagesStorage,
})
}

func (phase *BuildPhase) checkCustomImageTagsExistence(ctx context.Context, imageName string, stageDesc *image.StageDescription, stagesStorage storage.StagesStorage) error {
func (phase *BuildPhase) checkCustomImageTagsExistence(ctx context.Context, imageName string, stageDesc *imagePkg.StageDescription, stagesStorage storage.StagesStorage) error {
if len(phase.CustomTagFuncList) == 0 {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/build/builder/ansible_assets.go
Expand Up @@ -214,6 +214,6 @@ func mkdirP(path string) error {
return os.MkdirAll(path, os.FileMode(0o775))
}

func writeFile(path string, content string) error {
func writeFile(path, content string) error {
return ioutil.WriteFile(path, []byte(content), os.FileMode(0o664))
}
3 changes: 1 addition & 2 deletions pkg/build/conveyor.go
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/werf/werf/pkg/container_backend"
"github.com/werf/werf/pkg/git_repo"
"github.com/werf/werf/pkg/giterminism_manager"
"github.com/werf/werf/pkg/image"
imagePkg "github.com/werf/werf/pkg/image"
"github.com/werf/werf/pkg/logging"
"github.com/werf/werf/pkg/path_matcher"
Expand Down Expand Up @@ -308,7 +307,7 @@ func (c *Conveyor) GetRemoteGitRepo(key string) *git_repo.Remote {
}

type ShouldBeBuiltOptions struct {
CustomTagFuncList []image.CustomTagFunc
CustomTagFuncList []imagePkg.CustomTagFunc
}

func (c *Conveyor) ShouldBeBuilt(ctx context.Context, opts ShouldBeBuiltOptions) error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/build/import_server/rsync_server.go
Expand Up @@ -28,7 +28,7 @@ type RsyncServer struct {
AuthUser, AuthPassword string
}

func RunRsyncServer(ctx context.Context, dockerImageName string, tmpDir string) (*RsyncServer, error) {
func RunRsyncServer(ctx context.Context, dockerImageName, tmpDir string) (*RsyncServer, error) {
logboek.Context(ctx).Debug().LogF("RunRsyncServer for docker image %q\n", dockerImageName)

srv := &RsyncServer{
Expand Down
8 changes: 4 additions & 4 deletions pkg/build/stage/dockerfile.go
Expand Up @@ -147,7 +147,7 @@ func (ds *DockerStages) resolveDockerMetaArgs(resolvedDependenciesArgsHash map[s
}

// addDockerMetaArg function sets --build-arg value or resolved meta ARG value
func (ds *DockerStages) resolveDockerMetaArg(key, value string, resolvedDockerMetaArgsHash map[string]string, resolvedDependenciesArgsHash map[string]string) (string, string, error) {
func (ds *DockerStages) resolveDockerMetaArg(key, value string, resolvedDockerMetaArgsHash, resolvedDependenciesArgsHash map[string]string) (string, string, error) {
resolvedKey, err := ds.ShlexProcessWordWithMetaArgs(key, resolvedDockerMetaArgsHash)
if err != nil {
return "", "", err
Expand Down Expand Up @@ -200,7 +200,7 @@ func resolveDependenciesArgsHash(dependencies []*config.Dependency, c Conveyor)
}

// resolveDockerStageArg function sets dependency arg value, or --build-arg value, or resolved dockerfile stage ARG value, or resolved meta ARG value (if stage ARG value is empty)
func (ds *DockerStages) resolveDockerStageArg(dockerStageID int, key, value string, resolvedDockerMetaArgsHash map[string]string, resolvedDependenciesArgsHash map[string]string) (string, string, error) {
func (ds *DockerStages) resolveDockerStageArg(dockerStageID int, key, value string, resolvedDockerMetaArgsHash, resolvedDependenciesArgsHash map[string]string) (string, string, error) {
resolvedKey, err := ds.ShlexProcessWordWithStageArgsAndEnvs(dockerStageID, key)
if err != nil {
return "", "", err
Expand Down Expand Up @@ -501,7 +501,7 @@ func (s *DockerfileStage) GetDependencies(ctx context.Context, c Conveyor, _ con
return util.Sha256Hash(dockerfileStageDependencies...), nil
}

func (s *DockerfileStage) dockerfileInstructionDependencies(ctx context.Context, giterminismManager giterminism_manager.Interface, resolvedDockerMetaArgsHash map[string]string, resolvedDependenciesArgsHash map[string]string, dockerStageID int, cmd interface{}, isOnbuildInstruction bool, isBaseImageOnbuildInstruction bool) ([]string, []string, error) {
func (s *DockerfileStage) dockerfileInstructionDependencies(ctx context.Context, giterminismManager giterminism_manager.Interface, resolvedDockerMetaArgsHash, resolvedDependenciesArgsHash map[string]string, dockerStageID int, cmd interface{}, isOnbuildInstruction, isBaseImageOnbuildInstruction bool) ([]string, []string, error) {
var dependencies []string
var onBuildDependencies []string

Expand Down Expand Up @@ -666,7 +666,7 @@ func (s *DockerfileStage) dockerfileInstructionDependencies(ctx context.Context,
return dependencies, onBuildDependencies, nil
}

func (s *DockerfileStage) dockerfileOnBuildInstructionDependencies(ctx context.Context, giterminismManager giterminism_manager.Interface, resolvedDockerMetaArgsHash map[string]string, resolvedDependenciesArgsHash map[string]string, dockerStageID int, expression string, isBaseImageOnbuildInstruction bool) ([]string, []string, error) {
func (s *DockerfileStage) dockerfileOnBuildInstructionDependencies(ctx context.Context, giterminismManager giterminism_manager.Interface, resolvedDockerMetaArgsHash, resolvedDependenciesArgsHash map[string]string, dockerStageID int, expression string, isBaseImageOnbuildInstruction bool) ([]string, []string, error) {
p, err := parser.Parse(bytes.NewReader([]byte(expression)))
if err != nil {
return nil, nil, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/build/stage/interface.go
Expand Up @@ -15,7 +15,7 @@ type Interface interface {
IsEmpty(ctx context.Context, c Conveyor, prevBuiltImage *StageImage) (bool, error)

FetchDependencies(ctx context.Context, c Conveyor, cb container_backend.ContainerBackend, dockerRegistry docker_registry.ApiInterface) error
GetDependencies(ctx context.Context, c Conveyor, cb container_backend.ContainerBackend, prevImage *StageImage, prevBuiltImage *StageImage) (string, error)
GetDependencies(ctx context.Context, c Conveyor, cb container_backend.ContainerBackend, prevImage, prevBuiltImage *StageImage) (string, error)
GetNextStageDependencies(ctx context.Context, c Conveyor) (string, error)

PrepareImage(ctx context.Context, c Conveyor, cb container_backend.ContainerBackend, prevBuiltImage, stageImage *StageImage) error
Expand Down
2 changes: 1 addition & 1 deletion pkg/buildah/common.go
Expand Up @@ -96,7 +96,7 @@ type Buildah interface {
Push(ctx context.Context, ref string, opts PushOpts) error
BuildFromDockerfile(ctx context.Context, dockerfile []byte, opts BuildFromDockerfileOpts) (string, error)
RunCommand(ctx context.Context, container string, command []string, opts RunCommandOpts) error
FromCommand(ctx context.Context, container string, image string, opts FromCommandOpts) (string, error)
FromCommand(ctx context.Context, container, image string, opts FromCommandOpts) (string, error)
Pull(ctx context.Context, ref string, opts PullOpts) error
Inspect(ctx context.Context, ref string) (*thirdparty.BuilderInfo, error)
Rm(ctx context.Context, ref string, opts RmOpts) error
Expand Down
4 changes: 2 additions & 2 deletions pkg/buildah/docker_with_fuse.go
Expand Up @@ -128,7 +128,7 @@ func (b *DockerWithFuseBuildah) RunCommand(ctx context.Context, container string
return err
}

func (b *DockerWithFuseBuildah) FromCommand(ctx context.Context, container string, image string, opts FromCommandOpts) (string, error) {
func (b *DockerWithFuseBuildah) FromCommand(ctx context.Context, container, image string, opts FromCommandOpts) (string, error) {
container, _, err := b.runBuildah(ctx, []string{}, []string{
"from", fmt.Sprintf("--tls-verify=%s", strconv.FormatBool(!b.Insecure)), "--name", container, "--shm-size", DefaultShmSize,
"--signature-policy", b.SignaturePolicyPath, "--quiet", "--isolation", b.Isolation.String(), "--format", "docker", image,
Expand Down Expand Up @@ -204,7 +204,7 @@ func (b *DockerWithFuseBuildah) Config(ctx context.Context, container string, op
return err
}

func (b *DockerWithFuseBuildah) runBuildah(ctx context.Context, dockerArgs []string, buildahArgs []string, logWriter io.Writer) (string, string, error) {
func (b *DockerWithFuseBuildah) runBuildah(ctx context.Context, dockerArgs, buildahArgs []string, logWriter io.Writer) (string, string, error) {
stdout := &bytes.Buffer{}
stderr := &bytes.Buffer{}

Expand Down
2 changes: 1 addition & 1 deletion pkg/buildah/native_linux.go
Expand Up @@ -277,7 +277,7 @@ func (b *NativeBuildah) RunCommand(ctx context.Context, container string, comman
return nil
}

func (b *NativeBuildah) FromCommand(ctx context.Context, container string, image string, opts FromCommandOpts) (string, error) {
func (b *NativeBuildah) FromCommand(ctx context.Context, container, image string, opts FromCommandOpts) (string, error) {
builder, err := buildah.NewBuilder(ctx, b.Store, buildah.BuilderOptions{
FromImage: image,
Container: container,
Expand Down
6 changes: 3 additions & 3 deletions pkg/cleaning/git_history_based_cleanup/reference_to_scan.go
Expand Up @@ -306,11 +306,11 @@ func applyImagesPerReference(policyBranchesRefs []*ReferenceToScan, imagesPerRef
}
}

func referencesOr(refs1 []*ReferenceToScan, refs2 []*ReferenceToScan) []*ReferenceToScan {
func referencesOr(refs1, refs2 []*ReferenceToScan) []*ReferenceToScan {
return mergeReferences(refs1, refs2)
}

func referencesAnd(refs1 []*ReferenceToScan, refs2 []*ReferenceToScan) []*ReferenceToScan {
func referencesAnd(refs1, refs2 []*ReferenceToScan) []*ReferenceToScan {
var result []*ReferenceToScan

outerLoop:
Expand Down Expand Up @@ -352,7 +352,7 @@ func filterReferencesByLast(refs []*ReferenceToScan, last int) []*ReferenceToSca
return refs[:last]
}

func mergeReferences(refs1 []*ReferenceToScan, refs2 []*ReferenceToScan) []*ReferenceToScan {
func mergeReferences(refs1, refs2 []*ReferenceToScan) []*ReferenceToScan {
result := refs2

outerLoop:
Expand Down
4 changes: 2 additions & 2 deletions pkg/cleaning/stage_manager/manager.go
Expand Up @@ -45,7 +45,7 @@ type imageMetadata struct {
isNonexistentStage bool
}

func (m *Manager) getOrCreateImageMetadata(imageName string, stageID string) *imageMetadata {
func (m *Manager) getOrCreateImageMetadata(imageName, stageID string) *imageMetadata {
for _, im := range m.imageMetadataList {
if im.imageName == imageName && im.stageID == stageID {
return im
Expand All @@ -58,7 +58,7 @@ func (m *Manager) getOrCreateImageMetadata(imageName string, stageID string) *im
return im
}

func (m *Manager) newImageMetadata(imageName string, stageID string) *imageMetadata {
func (m *Manager) newImageMetadata(imageName, stageID string) *imageMetadata {
return &imageMetadata{imageName: imageName, stageID: stageID, isNonexistentStage: !m.IsStageExist(stageID)}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/config/common.go
Expand Up @@ -80,7 +80,7 @@ func oneOrNone(conditions []bool) bool {
return true
}

func InterfaceToStringArray(stringOrStringArray interface{}, configSection interface{}, doc *doc) ([]string, error) {
func InterfaceToStringArray(stringOrStringArray, configSection interface{}, doc *doc) ([]string, error) {
if stringOrStringArray == nil {
return []string{}, nil
} else if val, ok := stringOrStringArray.(string); ok {
Expand Down

0 comments on commit 3edb2de

Please sign in to comment.