Skip to content

Commit d58b51e

Browse files
authored
handle newfound lint errors (#1142)
Signed-off-by: Jason Hall <[email protected]>
1 parent 65a3fe4 commit d58b51e

File tree

10 files changed

+28
-51
lines changed

10 files changed

+28
-51
lines changed

.golangci.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ issues:
1010
linters:
1111
enable:
1212
- asciicheck
13-
- deadcode
14-
- depguard
1513
- errorlint
1614
- gofmt
1715
- gosec
@@ -28,3 +26,5 @@ linters:
2826

2927
disable:
3028
- errcheck
29+
- depguard
30+
- deadcode

internal/sbom/cyclonedx.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func GenerateImageCycloneDX(mod []byte) ([]byte, error) {
126126
return buf.Bytes(), nil
127127
}
128128

129-
func GenerateIndexCycloneDX(sii oci.SignedImageIndex) ([]byte, error) {
129+
func GenerateIndexCycloneDX(oci.SignedImageIndex) ([]byte, error) {
130130
return nil, nil
131131
}
132132

pkg/build/cache.go

+4-8
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ func (c *layerCache) get(ctx context.Context, file string, miss layerFactory) (v
4848
}
4949

5050
// Cache hit.
51-
if diffid, desc, err := c.getMeta(ctx, file); err == nil {
51+
if diffid, desc, err := c.getMeta(ctx, file); err != nil {
52+
logs.Debug.Printf("getMeta(%q): %v", file, err)
53+
} else {
5254
return &lazyLayer{
5355
diffid: *diffid,
5456
desc: *desc,
5557
buildLayer: miss,
5658
}, nil
57-
} else {
58-
logs.Debug.Printf("getMeta(%q): %v", file, err)
5959
}
6060

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

159159
enc = json.NewEncoder(dtodf)
160160
enc.SetIndent("", " ")
161-
if err := enc.Encode(&dtod); err != nil {
162-
return err
163-
}
164-
165-
return nil
161+
return enc.Encode(&dtod)
166162
}
167163

168164
func (c *layerCache) readDiffToDesc(file string) (diffIDToDescriptor, error) {

pkg/build/gobuild.go

+8-15
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232
"strings"
3333
"text/template"
3434

35-
"github.com/containerd/stargz-snapshotter/estargz"
3635
"github.com/google/go-containerregistry/pkg/name"
3736
v1 "github.com/google/go-containerregistry/pkg/v1"
3837
"github.com/google/go-containerregistry/pkg/v1/empty"
@@ -394,7 +393,7 @@ func writeSBOM(sbom []byte, appFileName, dir, ext string) error {
394393
}
395394
sbomPath := filepath.Join(sbomDir, appFileName+"."+ext)
396395
log.Printf("Writing SBOM to %s", sbomPath)
397-
return os.WriteFile(sbomPath, sbom, 0644)
396+
return os.WriteFile(sbomPath, sbom, 0644) //nolint:gosec
398397
}
399398
return nil
400399
}
@@ -956,10 +955,7 @@ func buildLayer(appPath, file string, platform *v1.Platform, layerMediaType type
956955
binaryLayerBytes := binaryLayerBuf.Bytes()
957956
return tarball.LayerFromOpener(func() (io.ReadCloser, error) {
958957
return io.NopCloser(bytes.NewBuffer(binaryLayerBytes)), nil
959-
}, tarball.WithCompressedCaching, tarball.WithEstargzOptions(estargz.WithPrioritizedFiles([]string{
960-
// When using estargz, prioritize downloading the binary entrypoint.
961-
appPath,
962-
})), tarball.WithMediaType(layerMediaType))
958+
}, tarball.WithCompressedCaching, tarball.WithMediaType(layerMediaType))
963959
}
964960

965961
// Append appPath to the PATH environment variable, if it exists. Otherwise,
@@ -1226,18 +1222,15 @@ func (pm *platformMatcher) matches(base *v1.Platform) bool {
12261222
if p.OS != "windows" {
12271223
// osversion mismatch is only possibly allowed when os == windows.
12281224
continue
1229-
} else {
1230-
if pcount, bcount := strings.Count(p.OSVersion, "."), strings.Count(base.OSVersion, "."); pcount == 2 && bcount == 3 {
1231-
if p.OSVersion != base.OSVersion[:strings.LastIndex(base.OSVersion, ".")] {
1232-
// If requested osversion is X.Y.Z and potential match is X.Y.Z.A, all of X.Y.Z must match.
1233-
// Any other form of these osversions are not a match.
1234-
continue
1235-
}
1236-
} else {
1237-
// Partial osversion matching only allows X.Y.Z to match X.Y.Z.A.
1225+
}
1226+
if pcount, bcount := strings.Count(p.OSVersion, "."), strings.Count(base.OSVersion, "."); pcount == 2 && bcount == 3 {
1227+
if p.OSVersion != base.OSVersion[:strings.LastIndex(base.OSVersion, ".")] {
1228+
// If requested osversion is X.Y.Z and potential match is X.Y.Z.A, all of X.Y.Z must match.
1229+
// Any other form of these osversions are not a match.
12381230
continue
12391231
}
12401232
}
1233+
// Otherwise, partial osversion matching only allows X.Y.Z to match X.Y.Z.A.
12411234
}
12421235
return true
12431236
}

pkg/build/limit_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ type sleeper struct{}
2727
var _ Interface = (*sleeper)(nil)
2828

2929
// QualifyImport implements Interface
30-
func (r *sleeper) QualifyImport(ip string) (string, error) {
30+
func (*sleeper) QualifyImport(ip string) (string, error) {
3131
return ip, nil
3232
}
3333

3434
// IsSupportedReference implements Interface
35-
func (r *sleeper) IsSupportedReference(ip string) error {
35+
func (*sleeper) IsSupportedReference(_ string) error {
3636
return nil
3737
}
3838

3939
// Build implements Interface
40-
func (r *sleeper) Build(_ context.Context, ip string) (Result, error) {
40+
func (*sleeper) Build(_ context.Context, _ string) (Result, error) {
4141
time.Sleep(50 * time.Millisecond)
4242
return nil, nil
4343
}

pkg/commands/apply.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func addApply(topLevel *cobra.Command) {
8686
// Issue a "kubectl apply" command reading from stdin,
8787
// to which we will pipe the resolved files, and any
8888
// remaining flags passed after '--'.
89-
kubectlCmd := exec.CommandContext(ctx, "kubectl", append([]string{"apply", "-f", "-"}, args...)...)
89+
kubectlCmd := exec.CommandContext(ctx, "kubectl", append([]string{"apply", "-f", "-"}, args...)...) //nolint:gosec
9090

9191
// Pass through our environment
9292
kubectlCmd.Env = os.Environ()

pkg/commands/create.go

+1-13
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"fmt"
2020
"os"
2121
"os/exec"
22-
"strings"
2322

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

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

137136
topLevel.AddCommand(create)
138137
}
139-
140-
func stripPassword(flags []string) []string {
141-
cp := make([]string, len(flags))
142-
for _, f := range flags {
143-
if strings.HasPrefix(f, "--password=") {
144-
f = "--password=REDACTED"
145-
}
146-
cp = append(cp, f)
147-
}
148-
return cp
149-
}

pkg/publish/kind/write_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ type fakeProvider struct {
165165
nodes []nodes.Node
166166
}
167167

168-
func (f *fakeProvider) ListInternalNodes(name string) ([]nodes.Node, error) {
168+
func (f *fakeProvider) ListInternalNodes(string) ([]nodes.Node, error) {
169169
return f.nodes, nil
170170
}
171171

@@ -174,7 +174,7 @@ type fakeNode struct {
174174
err error
175175
}
176176

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

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

196196
type fakeCmd struct {
197197
cmd string

pkg/publish/options.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type staticKeychain struct {
2525
auth authn.Authenticator
2626
}
2727

28-
func (s staticKeychain) Resolve(resource authn.Resource) (authn.Authenticator, error) {
28+
func (s staticKeychain) Resolve(authn.Resource) (authn.Authenticator, error) {
2929
return s.auth, nil
3030
}
3131

pkg/publish/shared_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type slowpublish struct {
3131
// slowpublish implements Interface
3232
var _ Interface = (*slowpublish)(nil)
3333

34-
func (sp *slowpublish) Publish(_ context.Context, br build.Result, ref string) (name.Reference, error) {
34+
func (sp *slowpublish) Publish(context.Context, build.Result, string) (name.Reference, error) {
3535
time.Sleep(sp.sleep)
3636
return makeRef()
3737
}

0 commit comments

Comments
 (0)