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

Add new workflow for static analysis checks & address lint errors #30

Merged
merged 2 commits into from
Mar 22, 2024
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
16 changes: 16 additions & 0 deletions .github/workflows/static-analysis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
name: Static analysis
on: [push, pull_request]
permissions: read-all
jobs:
run:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.21
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
with:
version: v1.57.1
5 changes: 2 additions & 3 deletions cmd/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package cmd
import (
"fmt"
"io"
"io/ioutil"
"os"

"bufio"
Expand Down Expand Up @@ -181,7 +180,7 @@ func run(metaOnly bool, outMediaType string, in []byte, out io.Writer) error {
// Readinput reads command line input, either from a provided input file or from stdin.
func readInput(inputFilename string) ([]byte, error) {
if inputFilename != "" {
data, err := ioutil.ReadFile(inputFilename)
data, err := os.ReadFile(inputFilename)
if err != nil {
return nil, fmt.Errorf("error reading input file %s: %v", inputFilename, err)
}
Expand All @@ -197,7 +196,7 @@ func readInput(inputFilename string) ([]byte, error) {
fmt.Fprintln(os.Stderr, "warn: waiting on stdin from tty")
}

stdin, err := ioutil.ReadAll(os.Stdin)
stdin, err := io.ReadAll(os.Stdin)
if err != nil {
return nil, fmt.Errorf("unable to read data from stdin: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package cmd

import (
"bytes"
"io/ioutil"
"io"
"os"
"regexp"
"strings"
Expand Down Expand Up @@ -87,7 +87,7 @@ func readTestFile(t *testing.T, filename string) []byte {
if err != nil {
t.Fatalf("failed to open test data file: %v", err)
}
in, err := ioutil.ReadAll(f)
in, err := io.ReadAll(f)
if err != nil {
t.Fatalf("failed to read test data file, %v", err)
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func init() {
extractCmd.Flags().BoolVar(&opts.raw, "raw", false, "Don't attempt to decode the etcd value")
extractCmd.Flags().StringVar(&opts.fields, "fields", Key, fmt.Sprintf("Fields to include when listing entries, comma separated list of: %v", SummaryFields))
extractCmd.Flags().StringVar(&opts.template, "template", "", fmt.Sprintf("golang template to use when listing entries, see https://golang.org/pkg/text/template, template is provided an object with the fields: %v. The Value field contains the entire kubernetes resource object which also may be dereferenced using a dot seperated path.", templateFields()))
extractCmd.Flags().StringVar(&opts.filter, "filter", "", fmt.Sprintf("Filter entries using a comma separated list of '<field>=value' constraints. Fields used in filters use the same naming as --template fields, e.g. .Value.metadata.namespace"))
extractCmd.Flags().StringVar(&opts.filter, "filter", "", "Filter entries using a comma separated list of '<field>=value' constraints. Fields used in filters use the same naming as --template fields, e.g. .Value.metadata.namespace")
}

const (
Expand Down Expand Up @@ -319,15 +319,15 @@ func summarize(s *data.KeySummary, fields []string) (string, error) {
for i, field := range fields {
switch field {
case Key:
values[i] = fmt.Sprintf("%s", s.Key)
values[i] = s.Key
case ValueSize:
values[i] = fmt.Sprintf("%d", s.Stats.ValueSize)
case AllVersionsValueSize:
values[i] = fmt.Sprintf("%d", s.Stats.AllVersionsValueSize)
case VersionCount:
values[i] = fmt.Sprintf("%d", s.Stats.VersionCount)
case Value:
values[i] = fmt.Sprintf("%s", s.ValueJson())
values[i] = s.ValueJson()
default:
return "", fmt.Errorf("unrecognized field: %s", field)
}
Expand Down
2 changes: 0 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (
"github.com/spf13/cobra"
)

var cfgFile string

var RootCmd = &cobra.Command{
Use: "auger",
Short: "Inspect and analyze kubernetes storage data.",
Expand Down
22 changes: 3 additions & 19 deletions pkg/data/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ var (
keyBucket = []byte("key")
metaBucket = []byte("meta")

consistentIndexKeyName = []byte("consistent_index")
scheduledCompactKeyName = []byte("scheduledCompactRev")
finishedCompactKeyName = []byte("finishedCompactRev")
)

Expand Down Expand Up @@ -201,22 +199,6 @@ func getCompactRevision(db *bolt.DB) (int64, error) {
return compactRev, nil
}

func getConsistentIndex(db *bolt.DB) (int64, error) {
consistentIndex := int64(0)
err := db.View(func(tx *bolt.Tx) error {
b := tx.Bucket(metaBucket)
consistentIndexBytes := b.Get(consistentIndexKeyName)
if len(consistentIndexBytes) != 0 {
consistentIndex = int64(binary.BigEndian.Uint64(consistentIndexBytes[0:8]))
}
return nil
})
if err != nil {
return 0, err
}
return consistentIndex, nil
}

// ListKeySummaries returns a result set with all the provided filters and projections applied.
func ListKeySummaries(filename string, filters []Filter, proj *KeySummaryProjection, revision int64) ([]*KeySummary, error) {
var err error
Expand Down Expand Up @@ -409,7 +391,9 @@ func walkRevision(db *bolt.DB, revision int64, f func(r revKey, kv *mvccpb.KeyVa

for _, s := range sorted {
if !s.rev.tombstone {
f(s.rev, s.kv)
if _, err := f(s.rev, s.kv); err != nil {
return err
}
}
}
return nil
Expand Down
8 changes: 6 additions & 2 deletions pkg/encoding/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ func decodeTypeMeta(inMediaType string, in []byte) (*runtime.TypeMeta, error) {

func typeMetaFromJson(in []byte) (*runtime.TypeMeta, error) {
var meta runtime.TypeMeta
json.Unmarshal(in, &meta)
if err := json.Unmarshal(in, &meta); err != nil {
return nil, err
}
return &meta, nil
}

Expand All @@ -264,6 +266,8 @@ func typeMetaFromBinaryStorage(in []byte) (*runtime.TypeMeta, error) {

func typeMetaFromYaml(in []byte) (*runtime.TypeMeta, error) {
var meta runtime.TypeMeta
yaml.Unmarshal(in, &meta)
if err := yaml.Unmarshal(in, &meta); err != nil {
return nil, err
}
return &meta, nil
}
2 changes: 1 addition & 1 deletion pkg/encoding/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var findProtoTests = []struct {
}{
{string(ProtoEncodingPrefix), true, string(ProtoEncodingPrefix)},
{fmt.Sprintf("xxxxxx%s...end", ProtoEncodingPrefix), true, fmt.Sprintf("%s...end", ProtoEncodingPrefix)},
{fmt.Sprintf("xxxxxx{}"), false, ""},
{"xxxxxx{}", false, ""},
}

func TestTryFindProto(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions pkg/encoding/scheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func init() {
//
// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types
// correctly.
//nolint:errcheck
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a work in progress pr in relation to scheme so don't want to waste time sorting our error checking here for now so just added the nolint:errcheck

func AddToScheme(scheme *runtime.Scheme) {
admissionv1beta1.AddToScheme(scheme)

Expand Down
Loading