Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle newfound lint errors #1142

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ issues:
linters:
enable:
- asciicheck
- deadcode
- depguard
- errorlint
- gofmt
- gosec
Expand All @@ -28,3 +26,5 @@ linters:

disable:
- errcheck
- depguard
- deadcode
2 changes: 1 addition & 1 deletion internal/sbom/cyclonedx.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func GenerateImageCycloneDX(mod []byte) ([]byte, error) {
return buf.Bytes(), nil
}

func GenerateIndexCycloneDX(sii oci.SignedImageIndex) ([]byte, error) {
func GenerateIndexCycloneDX(oci.SignedImageIndex) ([]byte, error) {
return nil, nil
}

Expand Down
12 changes: 4 additions & 8 deletions pkg/build/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ func (c *layerCache) get(ctx context.Context, file string, miss layerFactory) (v
}

// Cache hit.
if diffid, desc, err := c.getMeta(ctx, file); err == nil {
if diffid, desc, err := c.getMeta(ctx, file); err != nil {
logs.Debug.Printf("getMeta(%q): %v", file, err)
} else {
return &lazyLayer{
diffid: *diffid,
desc: *desc,
buildLayer: miss,
}, nil
} else {
logs.Debug.Printf("getMeta(%q): %v", file, err)
}

// Cache miss.
Expand Down Expand Up @@ -158,11 +158,7 @@ func (c *layerCache) put(ctx context.Context, file string, layer v1.Layer) error

enc = json.NewEncoder(dtodf)
enc.SetIndent("", " ")
if err := enc.Encode(&dtod); err != nil {
return err
}

return nil
return enc.Encode(&dtod)
}

func (c *layerCache) readDiffToDesc(file string) (diffIDToDescriptor, error) {
Expand Down
23 changes: 8 additions & 15 deletions pkg/build/gobuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"strings"
"text/template"

"github.com/containerd/stargz-snapshotter/estargz"
"github.com/google/go-containerregistry/pkg/name"
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/empty"
Expand Down Expand Up @@ -394,7 +393,7 @@ func writeSBOM(sbom []byte, appFileName, dir, ext string) error {
}
sbomPath := filepath.Join(sbomDir, appFileName+"."+ext)
log.Printf("Writing SBOM to %s", sbomPath)
return os.WriteFile(sbomPath, sbom, 0644)
return os.WriteFile(sbomPath, sbom, 0644) //nolint:gosec
}
return nil
}
Expand Down Expand Up @@ -956,10 +955,7 @@ func buildLayer(appPath, file string, platform *v1.Platform, layerMediaType type
binaryLayerBytes := binaryLayerBuf.Bytes()
return tarball.LayerFromOpener(func() (io.ReadCloser, error) {
return io.NopCloser(bytes.NewBuffer(binaryLayerBytes)), nil
}, tarball.WithCompressedCaching, tarball.WithEstargzOptions(estargz.WithPrioritizedFiles([]string{
// When using estargz, prioritize downloading the binary entrypoint.
appPath,
})), tarball.WithMediaType(layerMediaType))
}, tarball.WithCompressedCaching, tarball.WithMediaType(layerMediaType))
}

// Append appPath to the PATH environment variable, if it exists. Otherwise,
Expand Down Expand Up @@ -1226,18 +1222,15 @@ func (pm *platformMatcher) matches(base *v1.Platform) bool {
if p.OS != "windows" {
// osversion mismatch is only possibly allowed when os == windows.
continue
} else {
if pcount, bcount := strings.Count(p.OSVersion, "."), strings.Count(base.OSVersion, "."); pcount == 2 && bcount == 3 {
if p.OSVersion != base.OSVersion[:strings.LastIndex(base.OSVersion, ".")] {
// If requested osversion is X.Y.Z and potential match is X.Y.Z.A, all of X.Y.Z must match.
// Any other form of these osversions are not a match.
continue
}
} else {
// Partial osversion matching only allows X.Y.Z to match X.Y.Z.A.
}
if pcount, bcount := strings.Count(p.OSVersion, "."), strings.Count(base.OSVersion, "."); pcount == 2 && bcount == 3 {
if p.OSVersion != base.OSVersion[:strings.LastIndex(base.OSVersion, ".")] {
// If requested osversion is X.Y.Z and potential match is X.Y.Z.A, all of X.Y.Z must match.
// Any other form of these osversions are not a match.
continue
}
}
// Otherwise, partial osversion matching only allows X.Y.Z to match X.Y.Z.A.
}
return true
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/build/limit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ type sleeper struct{}
var _ Interface = (*sleeper)(nil)

// QualifyImport implements Interface
func (r *sleeper) QualifyImport(ip string) (string, error) {
func (*sleeper) QualifyImport(ip string) (string, error) {
return ip, nil
}

// IsSupportedReference implements Interface
func (r *sleeper) IsSupportedReference(ip string) error {
func (*sleeper) IsSupportedReference(_ string) error {
return nil
}

// Build implements Interface
func (r *sleeper) Build(_ context.Context, ip string) (Result, error) {
func (*sleeper) Build(_ context.Context, _ string) (Result, error) {
time.Sleep(50 * time.Millisecond)
return nil, nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func addApply(topLevel *cobra.Command) {
// Issue a "kubectl apply" command reading from stdin,
// to which we will pipe the resolved files, and any
// remaining flags passed after '--'.
kubectlCmd := exec.CommandContext(ctx, "kubectl", append([]string{"apply", "-f", "-"}, args...)...)
kubectlCmd := exec.CommandContext(ctx, "kubectl", append([]string{"apply", "-f", "-"}, args...)...) //nolint:gosec

// Pass through our environment
kubectlCmd.Env = os.Environ()
Expand Down
14 changes: 1 addition & 13 deletions pkg/commands/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"fmt"
"os"
"os/exec"
"strings"

"github.com/google/ko/pkg/commands/options"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -87,7 +86,7 @@ func addCreate(topLevel *cobra.Command) {
// Issue a "kubectl create" command reading from stdin,
// to which we will pipe the resolved files, and any
// remaining flags passed after '--'.
kubectlCmd := exec.CommandContext(ctx, "kubectl", append([]string{"create", "-f", "-"}, args...)...)
kubectlCmd := exec.CommandContext(ctx, "kubectl", append([]string{"create", "-f", "-"}, args...)...) //nolint:gosec

// Pass through our environment
kubectlCmd.Env = os.Environ()
Expand Down Expand Up @@ -136,14 +135,3 @@ func addCreate(topLevel *cobra.Command) {

topLevel.AddCommand(create)
}

func stripPassword(flags []string) []string {
cp := make([]string, len(flags))
for _, f := range flags {
if strings.HasPrefix(f, "--password=") {
f = "--password=REDACTED"
}
cp = append(cp, f)
}
return cp
}
12 changes: 6 additions & 6 deletions pkg/publish/kind/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ type fakeProvider struct {
nodes []nodes.Node
}

func (f *fakeProvider) ListInternalNodes(name string) ([]nodes.Node, error) {
func (f *fakeProvider) ListInternalNodes(string) ([]nodes.Node, error) {
return f.nodes, nil
}

Expand All @@ -174,7 +174,7 @@ type fakeNode struct {
err error
}

func (f *fakeNode) CommandContext(ctx context.Context, cmd string, args ...string) exec.Cmd {
func (f *fakeNode) CommandContext(_ context.Context, cmd string, args ...string) exec.Cmd {
command := &fakeCmd{
cmd: strings.Join(append([]string{cmd}, args...), " "),
err: f.err,
Expand All @@ -188,10 +188,10 @@ func (f *fakeNode) String() string {
}

// The following functions are not used by our code at all.
func (f *fakeNode) Command(string, ...string) exec.Cmd { return nil }
func (f *fakeNode) Role() (string, error) { return "", nil }
func (f *fakeNode) IP() (ipv4 string, ipv6 string, err error) { return "", "", nil }
func (f *fakeNode) SerialLogs(writer io.Writer) error { return nil }
func (f *fakeNode) Command(string, ...string) exec.Cmd { return nil }
func (f *fakeNode) Role() (string, error) { return "", nil }
func (f *fakeNode) IP() (string, string, error) { return "", "", nil }
func (f *fakeNode) SerialLogs(io.Writer) error { return nil }

type fakeCmd struct {
cmd string
Expand Down
2 changes: 1 addition & 1 deletion pkg/publish/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type staticKeychain struct {
auth authn.Authenticator
}

func (s staticKeychain) Resolve(resource authn.Resource) (authn.Authenticator, error) {
func (s staticKeychain) Resolve(authn.Resource) (authn.Authenticator, error) {
return s.auth, nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/publish/shared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type slowpublish struct {
// slowpublish implements Interface
var _ Interface = (*slowpublish)(nil)

func (sp *slowpublish) Publish(_ context.Context, br build.Result, ref string) (name.Reference, error) {
func (sp *slowpublish) Publish(context.Context, build.Result, string) (name.Reference, error) {
time.Sleep(sp.sleep)
return makeRef()
}
Expand Down
Loading