Skip to content
Open
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
7 changes: 7 additions & 0 deletions .github/workflows/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ jobs:
cache-dependency-path: go.sum
cache: true

- name: Linting
uses: golangci/golangci-lint-action@v8
with:
version: v2.1
args: --timeout=5m
verify: false

- name: Run tests
shell: bash
run: |
Expand Down
11 changes: 11 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: "2"
linters:
enable:
- govet
- staticcheck
- errcheck
- gosec
run:
timeout: 5m
issues:
exclude-use-default: false
12 changes: 9 additions & 3 deletions cmd/atc/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/json"
"fmt"
"io"
"log"
"log/slog"
"net/http"
"time"
Expand Down Expand Up @@ -106,7 +107,7 @@ func Handler(client *k8s.Client, cache *wasm.ModuleCache, controllers *atc.Contr
continue
}

unstructured.SetNestedField(raw, originalStatus, "status")
_ = unstructured.SetNestedField(raw, originalStatus, "status")

data, err := json.Marshal(raw)
if err != nil {
Expand Down Expand Up @@ -232,7 +233,10 @@ func Handler(client *k8s.Client, cache *wasm.ModuleCache, controllers *atc.Contr

addRequestAttrs(r.Context(), slog.Bool("skipped", true))

json.NewEncoder(w).Encode(&review)
if err := json.NewEncoder(w).Encode(&review); err != nil {
log.Fatalf("error in encoding: %v", err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Definitely cannot be fatal. Client connections to our server can dissappear, or there can be other reasons that we might fail to write to any give http.ResponseWriter.
We definitely do not want to crash the program.

I believe we already have a logger in scope

}

return
}

Expand Down Expand Up @@ -354,7 +358,9 @@ func Handler(client *k8s.Client, cache *wasm.ModuleCache, controllers *atc.Contr
"allowed", review.Response.Allowed,
"details", review.Response.Result.Message,
))
json.NewEncoder(w).Encode(review)
if err := json.NewEncoder(w).Encode(review); err != nil {
log.Fatalf("error in encoding: %v", err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as above

}
}()

addRequestAttrs(r.Context(), slog.String("resourceId", internal.Canonical(prev)))
Expand Down
7 changes: 5 additions & 2 deletions cmd/atc/internal/testing/flights/crossnamespace/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"encoding/json"
"log"
"os"

corev1 "k8s.io/api/core/v1"
Expand All @@ -12,7 +13,7 @@ import (

func main() {
// This flight needs cross-namespace to be set in order to work and serves to test that feature.
json.NewEncoder(os.Stdout).Encode(flight.Resources{
if err := json.NewEncoder(os.Stdout).Encode(flight.Resources{
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is just testing. If it fails it will get caught in the tests.
Easier to just ignore the error explicitly:

_ = json.NewEncoder(...).Encode(...)

&corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Expand All @@ -33,5 +34,7 @@ func main() {
Namespace: "bar",
},
},
})
}); err != nil {
log.Fatalf("error: %v\n", err)
}
}
7 changes: 5 additions & 2 deletions cmd/atc/internal/testing/flights/longrunning/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"encoding/json"
"log"
"os"

batchv1 "k8s.io/api/batch/v1"
Expand All @@ -12,7 +13,7 @@ import (
)

func main() {
json.NewEncoder(os.Stdout).Encode(flight.Resources{
if err := json.NewEncoder(os.Stdout).Encode(flight.Resources{
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as above

&batchv1.Job{
TypeMeta: metav1.TypeMeta{
APIVersion: batchv1.SchemeGroupVersion.Identifier(),
Expand All @@ -37,5 +38,7 @@ func main() {
},
},
},
})
}); err != nil {
log.Fatalf("error: %v\n", err)
}
}
6 changes: 4 additions & 2 deletions cmd/atc/internal/testing/wasmcache/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func main() {

logger.Info("booting up server", "port", port)

http.ListenAndServe(port, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if err := http.ListenAndServe(port, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
path := "wasm/" + strings.TrimLeft(r.URL.Path, "/")

data, err := wasm.ReadFile(path)
Expand All @@ -39,5 +39,7 @@ func main() {
return
}
logger.Info("successfully served wasm asset")
}))
})); err != nil {
logger.Error("error in listening", "error", err.Error())
}
}
8 changes: 6 additions & 2 deletions cmd/atc/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,9 @@ func TestHistoryCap(t *testing.T) {
if err != nil {
return err
}
unstructured.SetNestedMap(backend.Object, map[string]any{"test": strconv.Itoa(i + 1)}, "spec", "labels")
if err := unstructured.SetNestedMap(backend.Object, map[string]any{"test": strconv.Itoa(i + 1)}, "spec", "labels"); err != nil {
return err
}
backend, err = backendIntf.Update(ctx, backend, metav1.UpdateOptions{})
return err
})
Expand Down Expand Up @@ -1106,7 +1108,9 @@ func TestHistoryCap(t *testing.T) {
if err != nil {
return err
}
unstructured.SetNestedMap(backend.Object, map[string]any{"test": "test"}, "spec", "labels")
if err := unstructured.SetNestedMap(backend.Object, map[string]any{"test": "test"}, "spec", "labels"); err != nil {
return err
}
backend, err = backendIntf.Update(ctx, backend, metav1.UpdateOptions{})
return err
})
Expand Down
6 changes: 4 additions & 2 deletions cmd/internal/changelog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func run() error {

var changelog Changelog

commits.ForEach(func(c *object.Commit) error {
if err := commits.ForEach(func(c *object.Commit) error {
if tags := tags[c.Hash.String()]; len(tags) > 0 {
changelog = append(changelog, Entry{Tags: tags, Date: tags[0].CreatedAt})
}
Expand All @@ -82,7 +82,9 @@ func run() error {
Sha: c.Hash.String(),
})
return nil
})
}); err != nil {
return err
}

if *out == "-" {
fmt.Println(changelog)
Expand Down
6 changes: 4 additions & 2 deletions cmd/internal/releaser/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ func getTagVersions(repo *git.Repository) (map[string]TagVersion, error) {

versions := map[string]TagVersion{}

iter.ForEach(func(r *plumbing.Reference) error {
if err := iter.ForEach(func(r *plumbing.Reference) error {
release, version := path.Split(r.Name()[len("refs/tags/"):].String())
if !semver.IsValid(version) {
return nil
Expand All @@ -515,7 +515,9 @@ func getTagVersions(repo *git.Repository) (map[string]TagVersion, error) {
}
}
return nil
})
}); err != nil {
return nil, err
}

return versions, nil
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/yoke/cmd_atc.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func GetAtcParams(settings GlobalSettings, args []string) ATCParams {

flagset.StringVar(&params.Debug, "debug-file", "", "debug file")

flagset.Parse(args)
_ = flagset.Parse(args)

return params
}
Expand Down
6 changes: 4 additions & 2 deletions cmd/yoke/cmd_blackbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func GetBlackBoxParams(settings GlobalSettings, args []string) (*BlackboxParams,
flagset := flag.NewFlagSet("blackbox", flag.ExitOnError)

flagset.Usage = func() {
fmt.Fprintln(flagset.Output(), blackboxHelp)
_, _ = fmt.Fprintln(flagset.Output(), blackboxHelp)
flagset.PrintDefaults()
}

Expand All @@ -49,7 +49,9 @@ func GetBlackBoxParams(settings GlobalSettings, args []string) (*BlackboxParams,
RegisterGlobalFlags(flagset, &params.GlobalSettings)
flagset.IntVar(&params.Context, "context", 4, "number of lines of context in diff (ignored if not comparing revisions)")
flagset.StringVar(&params.Namespace, "namespace", "", "namespace of release to inspect")
flagset.Parse(args)
if err := flagset.Parse(args); err != nil {
return nil, err
}

params.Release = flagset.Arg(0)

Expand Down
5 changes: 4 additions & 1 deletion cmd/yoke/cmd_descent.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func GetDescentfParams(settings GlobalSettings, args []string) (*DescentParams,
flagset := flag.NewFlagSet("descent", flag.ExitOnError)

flagset.Usage = func() {
fmt.Fprintln(flagset.Output(), descentHelp)
_, _ = fmt.Fprintln(flagset.Output(), descentHelp)
flagset.PrintDefaults()
}

Expand All @@ -49,6 +49,9 @@ func GetDescentfParams(settings GlobalSettings, args []string) (*DescentParams,
flagset.BoolVar(&params.RemoveNamespaces, "remove-namespaces", false, "enables pruning of namespaces owned by the release.\nDestructive and dangerous use with caution.")

flagset.Parse(args)
if err := flagset.Parse(args); err != nil {
return nil, err
}

if removeAll {
params.RemoveCRDs = true
Expand Down
5 changes: 4 additions & 1 deletion cmd/yoke/cmd_mayday.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func GetMaydayParams(settings GlobalSettings, args []string) (*MaydayParams, err
flagset := flag.NewFlagSet("mayday", flag.ExitOnError)

flagset.Usage = func() {
fmt.Fprintln(flagset.Output(), maydayHelp)
_, _ = fmt.Fprintln(flagset.Output(), maydayHelp)
flagset.PrintDefaults()
}

Expand All @@ -43,6 +43,9 @@ func GetMaydayParams(settings GlobalSettings, args []string) (*MaydayParams, err
flagset.BoolVar(&params.RemoveNamespaces, "remove-namespaces", false, "deletes namespaces owned by the release. Destructive and dangerous use with caution.")

flagset.Parse(args)
if err := flagset.Parse(args); err != nil {
return nil, err
}

if removeAll {
params.RemoveCRDs = true
Expand Down
6 changes: 4 additions & 2 deletions cmd/yoke/cmd_stow.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func GetStowParams(args []string) (*yoke.StowParams, error) {
flagset := flag.NewFlagSet("stow", flag.ExitOnError)

flagset.Usage = func() {
fmt.Fprintln(flagset.Output(), stowHelp)
_, _ = fmt.Fprintln(flagset.Output(), stowHelp)
flagset.PrintDefaults()
}

Expand All @@ -32,7 +32,9 @@ func GetStowParams(args []string) (*yoke.StowParams, error) {
params.Tags = append(params.Tags, strings.Split(s, ",")...)
return nil
})
flagset.Parse(args)
if err := flagset.Parse(args); err != nil {
return nil, err
}

params.WasmFile = flagset.Arg(0)
params.URL = flagset.Arg(1)
Expand Down
6 changes: 4 additions & 2 deletions cmd/yoke/cmd_takeoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func GetTakeoffParams(settings GlobalSettings, source io.Reader, args []string)
flagset := flag.NewFlagSet("takeoff", flag.ExitOnError)

flagset.Usage = func() {
fmt.Fprintln(flagset.Output(), takeoffHelp)
_, _ = fmt.Fprintln(flagset.Output(), takeoffHelp)
flagset.PrintDefaults()
}

Expand Down Expand Up @@ -91,7 +91,9 @@ func GetTakeoffParams(settings GlobalSettings, source io.Reader, args []string)

args, params.Flight.Args = internal.CutArgs(args)

flagset.Parse(args)
if err := flagset.Parse(args); err != nil {
return nil, err
}

if removeAll {
params.RemoveCRDs = true
Expand Down
6 changes: 4 additions & 2 deletions cmd/yoke/cmd_turbulence.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func GetTurbulenceParams(settings GlobalSettings, args []string) (*TurbulencePar
flagset := flag.NewFlagSet("turbulence", flag.ExitOnError)

flagset.Usage = func() {
fmt.Fprintln(flagset.Output(), turbulenceHelp)
_, _ = fmt.Fprintln(flagset.Output(), turbulenceHelp)
flagset.PrintDefaults()
}

Expand All @@ -52,7 +52,9 @@ func GetTurbulenceParams(settings GlobalSettings, args []string) (*TurbulencePar
flagset.BoolVar(&params.Color, "color", term.IsTerminal(int(os.Stdout.Fd())), "outputs diff with color")
flagset.StringVar(&params.Namespace, "namespace", "default", "target namespace of release")

flagset.Parse(args)
if err := flagset.Parse(args); err != nil {
return nil, err
}

params.Release = flagset.Arg(0)
if params.Release == "" {
Expand Down
4 changes: 3 additions & 1 deletion cmd/yoke/internal/testing/flights/base/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ func run() error {

func RandomString() string {
buf := make([]byte, 6)
rand.Read(buf)
if _, err := rand.Read(buf); err != nil {
return ""
}
return fmt.Sprintf("%x", buf)
}
2 changes: 1 addition & 1 deletion cmd/yoke/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func run() error {
RegisterGlobalFlags(flag.CommandLine, &settings)

flag.Usage = func() {
fmt.Fprintln(flag.CommandLine.Output(), rootHelp)
_,_ = fmt.Fprintln(flag.CommandLine.Output(), rootHelp)
flag.PrintDefaults()
fmt.Fprintln(os.Stderr)
}
Expand Down
6 changes: 4 additions & 2 deletions cmd/yoke/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,13 @@ func TestCreateEmptyDeployment(t *testing.T) {

require.Len(t, deployments.Items, 0)
// Test cleanup in case a foo release already exists (best-effort)
Mayday(background, MaydayParams{
err = Mayday(background, MaydayParams{
GlobalSettings: settings,
MaydayParams: yoke.MaydayParams{
Release: "foo",
},
})
require.NoError(t, err)
}

func TestCreateThenEmptyCycle(t *testing.T) {
Expand Down Expand Up @@ -195,12 +196,13 @@ func TestCreateThenEmptyCycle(t *testing.T) {

require.Len(t, deployments.Items, 1)
// Test cleanup in case a foo release already exists (best-effort)
Mayday(background, MaydayParams{
err = Mayday(background, MaydayParams{
GlobalSettings: settings,
MaydayParams: yoke.MaydayParams{
Release: "foo",
},
})
require.NoError(t, err)
}

func TestCreateDeleteCycle(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion examples/lookup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func run() error {

func RandomString() string {
buf := make([]byte, 6)
rand.Read(buf)
_, _ = rand.Read(buf)

return fmt.Sprintf("%x", buf)
}
5 changes: 4 additions & 1 deletion internal/revision.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ func MustParseInt(value string) int {

func RandomString() string {
buf := make([]byte, 6)
rand.Read(buf)
_, err := rand.Read(buf)
if err != nil {
panic(err)
}
return fmt.Sprintf("%x", buf)
}
Loading