diff --git a/.github/workflows/golangci-lint.yaml b/.github/workflows/golangci-lint.yaml index 92454b39..37c3994f 100644 --- a/.github/workflows/golangci-lint.yaml +++ b/.github/workflows/golangci-lint.yaml @@ -51,4 +51,4 @@ jobs: uses: golangci/golangci-lint-action@v6 with: version: v1.62.2 - args: --timeout=10m --go=${{ env.GO_VERSION }} --exclude-dirs=test --exclude-generated=true --issues-exit-code=0 \ No newline at end of file + args: --timeout=10m --go=${{ env.GO_VERSION }} --exclude-dirs=test --exclude-generated=true \ No newline at end of file diff --git a/cmd/porch/main.go b/cmd/porch/main.go index f44d8be2..c23546ab 100644 --- a/cmd/porch/main.go +++ b/cmd/porch/main.go @@ -21,7 +21,6 @@ import ( "net/url" "os" "strings" - "time" "github.com/nephio-project/porch/pkg/cmd/server" "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" @@ -44,7 +43,9 @@ func main() { func run() int { t := &telemetry{} - t.Start() + if err := t.Start(); err != nil { + klog.Warningf("failed to start telemetry: %v", err) + } defer t.Stop() http.DefaultTransport = otelhttp.NewTransport(http.DefaultClient.Transport) @@ -92,12 +93,8 @@ func (t *telemetry) Start() error { klog.Infof("tracing to %q", config) - // See https://github.com/open-telemetry/opentelemetry-go/issues/1484 - ctx, cancel := context.WithTimeout(ctx, time.Second) - defer cancel() - conn, err := grpc.DialContext(ctx, endpoint, + conn, err := grpc.NewClient(endpoint, grpc.WithTransportCredentials(insecure.NewCredentials()), - grpc.WithBlock(), ) if err != nil { return fmt.Errorf("failed to create gRPC connection to collector: %w", err) diff --git a/controllers/main.go b/controllers/main.go index b70d5528..a011043a 100644 --- a/controllers/main.go +++ b/controllers/main.go @@ -31,7 +31,7 @@ import ( _ "k8s.io/client-go/plugin/pkg/client/auth" "k8s.io/client-go/tools/leaderelection/resourcelock" "k8s.io/klog/v2" - "k8s.io/klog/v2/klogr" + "k8s.io/klog/v2/textlogger" "sigs.k8s.io/controller-runtime/pkg/client" metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" "sigs.k8s.io/controller-runtime/pkg/webhook" @@ -141,8 +141,12 @@ func run(ctx context.Context) error { }, }, } - - ctrl.SetLogger(klogr.New()) + + config := textlogger.NewConfig( + textlogger.Verbosity(4), + textlogger.Output(os.Stdout), + ) + ctrl.SetLogger(textlogger.NewLogger(config)) mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), managerOptions) if err != nil { diff --git a/controllers/packagevariants/pkg/controllers/packagevariant/injection.go b/controllers/packagevariants/pkg/controllers/packagevariant/injection.go index 59ef5c40..edad6a32 100644 --- a/controllers/packagevariants/pkg/controllers/packagevariant/injection.go +++ b/controllers/packagevariants/pkg/controllers/packagevariant/injection.go @@ -119,7 +119,10 @@ func ensureConfigInjection(ctx context.Context, return err } - setInjectionPointConditionsAndGates(kptfile, injectionPoints) + err = setInjectionPointConditionsAndGates(kptfile, injectionPoints) + if err != nil { + return err + } prr.Spec.Resources["Kptfile"] = kptfile.String() diff --git a/controllers/packagevariantsets/pkg/controllers/packagevariantset/render_test.go b/controllers/packagevariantsets/pkg/controllers/packagevariantset/render_test.go index da1b71e8..24800d7e 100644 --- a/controllers/packagevariantsets/pkg/controllers/packagevariantset/render_test.go +++ b/controllers/packagevariantsets/pkg/controllers/packagevariantset/render_test.go @@ -25,7 +25,7 @@ import ( kptfilev1 "github.com/nephio-project/porch/pkg/kpt/api/kptfile/v1" "github.com/stretchr/testify/require" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/pointer" + ptr "k8s.io/utils/ptr" "sigs.k8s.io/yaml" ) @@ -106,7 +106,7 @@ func TestRenderPackageVariantSpec(t *testing.T) { packageDefault: "p", template: &api.PackageVariantTemplate{ Downstream: &api.DownstreamTemplate{ - Repo: pointer.String("my-repo-2"), + Repo: ptr.To("my-repo-2"), }, }, }, @@ -125,7 +125,7 @@ func TestRenderPackageVariantSpec(t *testing.T) { packageDefault: "p", template: &api.PackageVariantTemplate{ Downstream: &api.DownstreamTemplate{ - Package: pointer.String("new-p"), + Package: ptr.To("new-p"), }, }, }, @@ -224,8 +224,8 @@ func TestRenderPackageVariantSpec(t *testing.T) { packageDefault: "p", template: &api.PackageVariantTemplate{ Downstream: &api.DownstreamTemplate{ - RepoExpr: pointer.String("'my-repo-2'"), - PackageExpr: pointer.String("repoDefault + '-' + packageDefault"), + RepoExpr: ptr.To("'my-repo-2'"), + PackageExpr: ptr.To("repoDefault + '-' + packageDefault"), }, }, }, @@ -244,8 +244,8 @@ func TestRenderPackageVariantSpec(t *testing.T) { packageDefault: "p", template: &api.PackageVariantTemplate{ Downstream: &api.DownstreamTemplate{ - RepoExpr: pointer.String("'my-repo-2'"), - PackageExpr: pointer.String("repoDefault + '-' + packageDefault"), + RepoExpr: ptr.To("'my-repo-2'"), + PackageExpr: ptr.To("repoDefault + '-' + packageDefault"), }, Labels: map[string]string{ "foo": "bar", @@ -253,16 +253,16 @@ func TestRenderPackageVariantSpec(t *testing.T) { }, LabelExprs: []api.MapExpr{ { - Key: pointer.String("foo"), - ValueExpr: pointer.String("repoDefault"), + Key: ptr.To("foo"), + ValueExpr: ptr.To("repoDefault"), }, { - KeyExpr: pointer.String("repository.labels['efg']"), - ValueExpr: pointer.String("packageDefault + '-' + repository.name"), + KeyExpr: ptr.To("repository.labels['efg']"), + ValueExpr: ptr.To("packageDefault + '-' + repository.name"), }, { - Key: pointer.String("hello"), - Value: pointer.String("goodbye"), + Key: ptr.To("hello"), + Value: ptr.To("goodbye"), }, }, Annotations: map[string]string{ @@ -271,12 +271,12 @@ func TestRenderPackageVariantSpec(t *testing.T) { }, AnnotationExprs: []api.MapExpr{ { - Key: pointer.String("foo.org/id"), - Value: pointer.String("54321"), + Key: ptr.To("foo.org/id"), + Value: ptr.To("54321"), }, { - Key: pointer.String("bigco.com/team"), - ValueExpr: pointer.String("upstream.annotations['bigco.com/team']"), + Key: ptr.To("bigco.com/team"), + ValueExpr: ptr.To("upstream.annotations['bigco.com/team']"), }, }, }, @@ -312,16 +312,16 @@ func TestRenderPackageVariantSpec(t *testing.T) { }, DataExprs: []api.MapExpr{ { - Key: pointer.String("foo"), - ValueExpr: pointer.String("upstream.name"), + Key: ptr.To("foo"), + ValueExpr: ptr.To("upstream.name"), }, { - KeyExpr: pointer.String("upstream.namespace"), - ValueExpr: pointer.String("upstream.name"), + KeyExpr: ptr.To("upstream.namespace"), + ValueExpr: ptr.To("upstream.name"), }, { - KeyExpr: pointer.String("upstream.name"), - Value: pointer.String("foo"), + KeyExpr: ptr.To("upstream.name"), + Value: ptr.To("foo"), }, }, RemoveKeys: []string{"foobar", "barfoo"}, @@ -354,19 +354,19 @@ func TestRenderPackageVariantSpec(t *testing.T) { template: &api.PackageVariantTemplate{ Injectors: []api.InjectionSelectorTemplate{ { - Group: pointer.String("kpt.dev"), - Version: pointer.String("v1alpha1"), - Kind: pointer.String("Foo"), - Name: pointer.String("bar"), + Group: ptr.To("kpt.dev"), + Version: ptr.To("v1alpha1"), + Kind: ptr.To("Foo"), + Name: ptr.To("bar"), }, { - Group: pointer.String("kpt.dev"), - Version: pointer.String("v1alpha1"), - Kind: pointer.String("Foo"), - NameExpr: pointer.String("repository.labels['abc']"), + Group: ptr.To("kpt.dev"), + Version: ptr.To("v1alpha1"), + Kind: ptr.To("Foo"), + NameExpr: ptr.To("repository.labels['abc']"), }, { - NameExpr: pointer.String("repository.name + '-test'"), + NameExpr: ptr.To("repository.name + '-test'"), }, }, }, @@ -379,15 +379,15 @@ func TestRenderPackageVariantSpec(t *testing.T) { }, Injectors: []pkgvarapi.InjectionSelector{ { - Group: pointer.String("kpt.dev"), - Version: pointer.String("v1alpha1"), - Kind: pointer.String("Foo"), + Group: ptr.To("kpt.dev"), + Version: ptr.To("v1alpha1"), + Kind: ptr.To("Foo"), Name: "bar", }, { - Group: pointer.String("kpt.dev"), - Version: pointer.String("v1alpha1"), - Kind: pointer.String("Foo"), + Group: ptr.To("kpt.dev"), + Version: ptr.To("v1alpha1"), + Kind: ptr.To("Foo"), Name: "def", }, { @@ -420,12 +420,12 @@ func TestRenderPackageVariantSpec(t *testing.T) { }, ConfigMapExprs: []api.MapExpr{ { - Key: pointer.String("k1"), - ValueExpr: pointer.String("repository.name"), + Key: ptr.To("k1"), + ValueExpr: ptr.To("repository.name"), }, { - KeyExpr: pointer.String("'k3'"), - Value: pointer.String("bar"), + KeyExpr: ptr.To("'k3'"), + Value: ptr.To("bar"), }, }, }, @@ -437,8 +437,8 @@ func TestRenderPackageVariantSpec(t *testing.T) { }, ConfigMapExprs: []api.MapExpr{ { - Key: pointer.String("k1"), - Value: pointer.String("yo"), + Key: ptr.To("k1"), + Value: ptr.To("yo"), }, }, }, @@ -591,16 +591,16 @@ func TestCopyAndOverlayMapExpr(t *testing.T) { inMap: map[string]string{}, mapExprs: []api.MapExpr{ { - Key: pointer.String("foo"), - Value: pointer.String("bar"), + Key: ptr.To("foo"), + Value: ptr.To("bar"), }, { - KeyExpr: pointer.String("repoDefault"), - Value: pointer.String("barbar"), + KeyExpr: ptr.To("repoDefault"), + Value: ptr.To("barbar"), }, { - Key: pointer.String("bar"), - ValueExpr: pointer.String("packageDefault"), + Key: ptr.To("bar"), + ValueExpr: ptr.To("packageDefault"), }, }, expectedResult: map[string]string{ @@ -616,12 +616,12 @@ func TestCopyAndOverlayMapExpr(t *testing.T) { }, mapExprs: []api.MapExpr{ { - Key: pointer.String("foo"), - Value: pointer.String("new-bar"), + Key: ptr.To("foo"), + Value: ptr.To("new-bar"), }, { - Key: pointer.String("foofoo"), - Value: pointer.String("barbar"), + Key: ptr.To("foofoo"), + Value: ptr.To("barbar"), }, }, expectedResult: map[string]string{ @@ -637,12 +637,12 @@ func TestCopyAndOverlayMapExpr(t *testing.T) { }, mapExprs: []api.MapExpr{ { - KeyExpr: pointer.String("'foo'"), - Value: pointer.String("new-bar"), + KeyExpr: ptr.To("'foo'"), + Value: ptr.To("new-bar"), }, { - Key: pointer.String("bar"), - ValueExpr: pointer.String("packageDefault"), + Key: ptr.To("bar"), + ValueExpr: ptr.To("packageDefault"), }, }, expectedResult: map[string]string{ diff --git a/func/client/main.go b/func/client/main.go index 03af9e8a..5b9f5445 100644 --- a/func/client/main.go +++ b/func/client/main.go @@ -92,7 +92,7 @@ func createResourceList(args []string) ([]byte, error) { } func call(rl []byte) (*pb.EvaluateFunctionResponse, error) { - cc, err := grpc.Dial(*addressFlag, grpc.WithTransportCredentials(insecure.NewCredentials())) + cc, err := grpc.NewClient(*addressFlag, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { return nil, fmt.Errorf("failed to connect to %s: %w", *addressFlag, err) } diff --git a/func/internal/podevaluator.go b/func/internal/podevaluator.go index 31673e91..643c7d1a 100644 --- a/func/internal/podevaluator.go +++ b/func/internal/podevaluator.go @@ -295,6 +295,7 @@ func forEachConcurrently(m map[string]string, fn func(k string, v string)) { // We must run this method in one single goroutine. Doing it this way simplify // design around concurrency. func (pcm *podCacheManager) podCacheManager() { + //nolint:staticcheck tick := time.Tick(pcm.gcScanInterval) for { select { @@ -493,7 +494,7 @@ func (pm *podManager) getFuncEvalPodClient(ctx context.Context, image string, tt return nil, fmt.Errorf("pod %s/%s did not have podIP", podKey.Namespace, podKey.Name) } address := net.JoinHostPort(podIP, defaultWrapperServerPort) - cc, err := grpc.Dial(address, + cc, err := grpc.NewClient(address, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(pm.maxGrpcMessageSize), diff --git a/func/internal/podevaluator_podmanager_test.go b/func/internal/podevaluator_podmanager_test.go index 43e22d66..19944a01 100644 --- a/func/internal/podevaluator_podmanager_test.go +++ b/func/internal/podevaluator_podmanager_test.go @@ -40,7 +40,7 @@ func (f *fakeFunctionEvalServer) Start(ctx context.Context) error { server := grpc.NewServer() pb.RegisterFunctionEvaluatorServer(server, f) - + //nolint:errcheck go server.Serve(lis) go func() { @@ -687,7 +687,7 @@ func TestPodManager(t *testing.T) { t.Errorf("Expected to get error, got ready pod") } var pod corev1.Pod - if tt.kubeClient.Get(ctx, cc.pod, &pod); err != nil { + if err := tt.kubeClient.Get(ctx, cc.pod, &pod); err != nil { t.Errorf("Failed to get pod: %v", err) } diff --git a/internal/kpt/errors/errors.go b/internal/kpt/errors/errors.go index a877970a..9f60a1b5 100644 --- a/internal/kpt/errors/errors.go +++ b/internal/kpt/errors/errors.go @@ -192,7 +192,7 @@ func E(args ...interface{}) error { case error: e.Err = a case string: - e.Err = fmt.Errorf(a) + e.Err = fmt.Errorf("%s", a) default: panic(fmt.Errorf("unknown type %T for value %v in call to error.E", a, a)) } diff --git a/internal/kpt/fnruntime/imagepullpolicy.go b/internal/kpt/fnruntime/imagepullpolicy.go index 9264569c..71a81f95 100644 --- a/internal/kpt/fnruntime/imagepullpolicy.go +++ b/internal/kpt/fnruntime/imagepullpolicy.go @@ -53,7 +53,7 @@ func (e *ImagePullPolicy) Set(v string) error { return nil } } - return fmt.Errorf("must must be one of " + strings.Join(e.AllStrings(), ", ")) + return fmt.Errorf("must must be one of %s" , strings.Join(e.AllStrings(), ", ")) } func (e *ImagePullPolicy) AllStrings() []string { diff --git a/internal/kpt/util/man/man.go b/internal/kpt/util/man/man.go index 01fd0606..0353e8b8 100644 --- a/internal/kpt/util/man/man.go +++ b/internal/kpt/util/man/man.go @@ -53,7 +53,7 @@ const ManFilename = "README.md" func (m Command) Run() error { _, err := exec.LookPath(m.GetExecCmd()) if err != nil { - return errors.Errorf(m.GetExecCmd() + " not installed") + return errors.Errorf("%s not installed", m.GetExecCmd()) } // lookup the path to the man page diff --git a/pkg/apiserver/webhooks.go b/pkg/apiserver/webhooks.go index c898d255..c80b111e 100644 --- a/pkg/apiserver/webhooks.go +++ b/pkg/apiserver/webhooks.go @@ -25,7 +25,7 @@ import ( "encoding/json" "encoding/pem" "fmt" - "io/ioutil" + "io" "math/big" "net/http" "os" @@ -492,7 +492,12 @@ func validateDeletion(w http.ResponseWriter, r *http.Request) { } w.Header().Set("Content-Type", "application/json") - w.Write(resp) + _, err = w.Write(resp) + if err != nil { + errMsg := fmt.Sprintf("error writing response: %v", err) + writeErr(errMsg, &w) + return + } } func decodeAdmissionReview(r *http.Request) (*admissionv1.AdmissionReview, error) { @@ -502,7 +507,7 @@ func decodeAdmissionReview(r *http.Request) (*admissionv1.AdmissionReview, error var requestData []byte if r.Body != nil { var err error - requestData, err = ioutil.ReadAll(r.Body) + requestData, err = io.ReadAll(r.Body) if err != nil { return nil, err } @@ -547,7 +552,7 @@ func createPorchClient() (client.Client, error) { } func writeErr(errMsg string, w *http.ResponseWriter) { - klog.Errorf(errMsg) + klog.Errorf("%s", errMsg) (*w).WriteHeader(500) if _, err := (*w).Write([]byte(errMsg)); err != nil { klog.Errorf("could not write error message: %v", err) diff --git a/pkg/apiserver/webhooks_test.go b/pkg/apiserver/webhooks_test.go index 60f804d1..644efdc1 100644 --- a/pkg/apiserver/webhooks_test.go +++ b/pkg/apiserver/webhooks_test.go @@ -118,6 +118,7 @@ func captureStderr(f func()) string { // Copy the output in a separate goroutine so printing can't block indefinitely. go func() { var buf bytes.Buffer + //nolint:errcheck io.Copy(&buf, read) outputChannel <- buf.String() }() diff --git a/pkg/cache/memory/repository.go b/pkg/cache/memory/repository.go index b50e511e..b8e43616 100644 --- a/pkg/cache/memory/repository.go +++ b/pkg/cache/memory/repository.go @@ -225,7 +225,10 @@ func (r *cachedRepository) update(ctx context.Context, updated repository.Packag // Create the main package revision if v1alpha1.LifecycleIsPublished(updated.Lifecycle()) { updatedMain := updated.ToMainPackageRevision() - r.createMainPackageRevision(ctx, updatedMain) + err := r.createMainPackageRevision(ctx, updatedMain) + if err != nil { + return nil, err + } } else { version, err := r.repo.Version(ctx) if err != nil { diff --git a/pkg/cli/commands/rpkg/push/command_test.go b/pkg/cli/commands/rpkg/push/command_test.go index eb1a5e7c..57ecb13f 100644 --- a/pkg/cli/commands/rpkg/push/command_test.go +++ b/pkg/cli/commands/rpkg/push/command_test.go @@ -98,6 +98,7 @@ func TestCmd(t *testing.T) { t.Errorf("unexpected error: %v", err) } }() + //nolint:errcheck io.Copy(output, read) os.Stdout = o os.Stderr = e diff --git a/pkg/cli/commands/rpkg/util/common.go b/pkg/cli/commands/rpkg/util/common.go index e918b634..6b3e6334 100644 --- a/pkg/cli/commands/rpkg/util/common.go +++ b/pkg/cli/commands/rpkg/util/common.go @@ -79,8 +79,12 @@ func GetResourceVersion(prr *api.PackageRevisionResources) (string, error) { func AddRevisionMetadata(prr *api.PackageRevisionResources) error { kptMetaDataKo := fnsdk.NewEmptyKubeObject() - kptMetaDataKo.SetAPIVersion(prr.APIVersion) - kptMetaDataKo.SetKind(kptfilev1.RevisionMetaDataKind) + if err := kptMetaDataKo.SetAPIVersion(prr.APIVersion); err != nil { + return fmt.Errorf("cannot set Api Version: %v", err) + } + if err := kptMetaDataKo.SetKind(kptfilev1.RevisionMetaDataKind); err != nil { + return fmt.Errorf("cannot set Kind: %v", err) + } if err := kptMetaDataKo.SetNestedField(prr.GetObjectMeta(), "metadata"); err != nil { return fmt.Errorf("cannot set metadata: %v", err) } diff --git a/pkg/engine/engine.go b/pkg/engine/engine.go index e67179f1..2af89e4e 100644 --- a/pkg/engine/engine.go +++ b/pkg/engine/engine.go @@ -228,7 +228,7 @@ func (cad *cadEngine) UpdatePackageRevision(ctx context.Context, version string, } if newRV != oldObj.GetResourceVersion() { - return nil, apierrors.NewConflict(api.Resource("packagerevisions"), oldObj.GetName(), fmt.Errorf(OptimisticLockErrorMsg)) + return nil, apierrors.NewConflict(api.Resource("packagerevisions"), oldObj.GetName(), fmt.Errorf("%s", OptimisticLockErrorMsg)) } repo, err := cad.cache.OpenRepository(ctx, repositoryObj) @@ -302,7 +302,9 @@ func (cad *cadEngine) UpdatePackageRevision(ctx context.Context, version string, return nil, err } - cad.taskHandler.DoPRMutations(ctx, repositoryObj.Namespace, repoPr, oldObj, newObj, draft) + if err := cad.taskHandler.DoPRMutations(ctx, repositoryObj.Namespace, repoPr, oldObj, newObj, draft); err != nil { + return nil, err + } if err := draft.UpdateLifecycle(ctx, newObj.Spec.Lifecycle); err != nil { return nil, err @@ -418,9 +420,7 @@ func (cad *cadEngine) ListPackages(ctx context.Context, repositorySpec *configap return nil, err } var packages []repository.Package - for _, p := range pkgs { - packages = append(packages, p) - } + packages = append(packages, pkgs...) return packages, nil } diff --git a/pkg/engine/grpcruntime.go b/pkg/engine/grpcruntime.go index b21de2e6..3d4ed36f 100644 --- a/pkg/engine/grpcruntime.go +++ b/pkg/engine/grpcruntime.go @@ -40,7 +40,7 @@ func newGRPCFunctionRuntime(address string, maxGrpcMessageSize int) (*grpcRuntim klog.Infof("Dialing grpc function runner %q", address) - cc, err := grpc.Dial(address, + cc, err := grpc.NewClient(address, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(maxGrpcMessageSize), diff --git a/pkg/git/commit.go b/pkg/git/commit.go index 173b1c5b..399250d5 100644 --- a/pkg/git/commit.go +++ b/pkg/git/commit.go @@ -210,23 +210,6 @@ func (h *commitHelper) storeFile(path, contents string) error { return nil } -// storeTree sets the tree of the provided path to the tree -// referenced by the provided hash. -func (h *commitHelper) storeTree(path string, hash plumbing.Hash) error { - parentPath, pkg := split(path) - tree := h.ensureTree(parentPath) - setOrAddTreeEntry(tree, object.TreeEntry{ - Name: pkg, - Mode: filemode.Dir, - }) - pTree, err := h.repository.getTree(hash) - if err != nil { - return err - } - h.trees[path] = pTree - return nil -} - // readFile returns the contents of the blob at path. // If the file is not found it returns an error satisfying os.IsNotExist func (h *commitHelper) readFile(path string) ([]byte, error) { diff --git a/pkg/git/git.go b/pkg/git/git.go index 7a6e84ab..b7f2c064 100644 --- a/pkg/git/git.go +++ b/pkg/git/git.go @@ -234,7 +234,8 @@ func (r *gitRepository) Version(ctx context.Context) (string, error) { } func (r *gitRepository) ListPackages(ctx context.Context, filter repository.ListPackageFilter) ([]repository.Package, error) { - ctx, span := tracer.Start(ctx, "gitRepository::ListPackages", trace.WithAttributes()) + //nolint:staticcheck + _, span := tracer.Start(ctx, "gitRepository::ListPackages", trace.WithAttributes()) defer span.End() // TODO @@ -242,7 +243,8 @@ func (r *gitRepository) ListPackages(ctx context.Context, filter repository.List } func (r *gitRepository) CreatePackage(ctx context.Context, obj *v1alpha1.PorchPackage) (repository.Package, error) { - ctx, span := tracer.Start(ctx, "gitRepository::CreatePackage", trace.WithAttributes()) + //nolint:staticcheck + _, span := tracer.Start(ctx, "gitRepository::CreatePackage", trace.WithAttributes()) defer span.End() // TODO: Create a 'Package' resource and an initial, empty 'PackageRevision' @@ -250,7 +252,8 @@ func (r *gitRepository) CreatePackage(ctx context.Context, obj *v1alpha1.PorchPa } func (r *gitRepository) DeletePackage(ctx context.Context, obj repository.Package) error { - ctx, span := tracer.Start(ctx, "gitRepository::DeletePackage", trace.WithAttributes()) + //nolint:staticcheck + _, span := tracer.Start(ctx, "gitRepository::DeletePackage", trace.WithAttributes()) defer span.End() // TODO: Support package deletion using subresources (similar to the package revision approval flow) @@ -351,7 +354,7 @@ func (r *gitRepository) listPackageRevisions(ctx context.Context, filter reposit } func (r *gitRepository) CreatePackageRevision(ctx context.Context, obj *v1alpha1.PackageRevision) (repository.PackageRevisionDraft, error) { - ctx, span := tracer.Start(ctx, "gitRepository::CreatePackageRevision", trace.WithAttributes()) + _, span := tracer.Start(ctx, "gitRepository::CreatePackageRevision", trace.WithAttributes()) defer span.End() r.mutex.Lock() defer r.mutex.Unlock() @@ -1235,31 +1238,6 @@ func (r *gitRepository) findLatestPackageCommit(ctx context.Context, startCommit // commitCallback is the function type that needs to be provided to the history iterator functions. type commitCallback func(*object.Commit) error -// packageRevisionHistoryIterator traverses the git history from the provided commit, and invokes -// the callback function for every commit pertaining to the provided packagerevision. -func (r *gitRepository) packageRevisionHistoryIterator(startCommit *object.Commit, packagePath, revision string, cb commitCallback) error { - return r.traverseHistory(startCommit, func(commit *object.Commit) error { - gitAnnotations, err := ExtractGitAnnotations(commit) - if err != nil { - return err - } - - for _, gitAnnotation := range gitAnnotations { - if gitAnnotation.PackagePath == packagePath && gitAnnotation.Revision == revision { - - if err := cb(commit); err != nil { - return err - } - - if gitAnnotation.Task != nil && (gitAnnotation.Task.Type == v1alpha1.TaskTypeClone || gitAnnotation.Task.Type == v1alpha1.TaskTypeInit) { - break - } - } - } - return nil - }) -} - // packageHistoryIterator traverses the git history from the provided commit and invokes // the callback function for every commit pertaining to the provided package. func (r *gitRepository) packageHistoryIterator(startCommit *object.Commit, packagePath string, cb commitCallback) error { @@ -1439,7 +1417,9 @@ func (r *gitRepository) UpdateDraftResources(ctx context.Context, draft *gitPack } for k, v := range new.Spec.Resources { - ch.storeFile(path.Join(draft.path, k), v) + if err := ch.storeFile(path.Join(draft.path, k), v); err != nil { + return err + } } // Because we can't read the package back without a Kptfile, make sure one is present diff --git a/pkg/git/git_test.go b/pkg/git/git_test.go index 1578caeb..dd4e9bd7 100644 --- a/pkg/git/git_test.go +++ b/pkg/git/git_test.go @@ -335,6 +335,7 @@ func (g GitSuite) initRepo(repo *gogit.Repository) error { } // gogit uses suboptimal default reference name; delete it + //nolint:errcheck repo.Storer.RemoveReference(plumbing.Master) // create correct HEAD as a symbolic reference of the branch @@ -685,8 +686,10 @@ func (g GitSuite) TestApproveDraft(t *testing.T) { if err != nil { t.Fatalf("UpdatePackageRevision failed: %v", err) } - - update.UpdateLifecycle(ctx, v1alpha1.PackageRevisionLifecyclePublished) + err = update.UpdateLifecycle(ctx, v1alpha1.PackageRevisionLifecyclePublished) + if err != nil { + t.Fatalf("UpdateLifecycle failed: %v", err) + } new, err := update.Close(ctx, "v1") if err != nil { @@ -747,8 +750,10 @@ func (g GitSuite) TestApproveDraftWithHistory(t *testing.T) { if err != nil { t.Fatalf("UpdatePackageRevision failed: %v", err) } - - update.UpdateLifecycle(ctx, v1alpha1.PackageRevisionLifecyclePublished) + err = update.UpdateLifecycle(ctx, v1alpha1.PackageRevisionLifecyclePublished) + if err != nil { + t.Fatalf("UpdateLifecycle failed: %v", err) + } new, err := update.Close(ctx, "v1") if err != nil { diff --git a/pkg/git/ref.go b/pkg/git/ref.go index b2adf11f..cb83853c 100644 --- a/pkg/git/ref.go +++ b/pkg/git/ref.go @@ -99,10 +99,6 @@ func getDraftBranchNameInLocal(n plumbing.ReferenceName) (BranchName, bool) { return BranchName(b), ok } -func isDeletionProposedBranchNameInLocal(n plumbing.ReferenceName) bool { - return strings.HasPrefix(n.String(), deletionProposedPrefixInLocalRepo) -} - func getdeletionProposedBranchNameInLocal(n plumbing.ReferenceName) (BranchName, bool) { b, ok := trimOptionalPrefix(n.String(), deletionProposedPrefixInLocalRepo) return BranchName(b), ok diff --git a/pkg/git/testing.go b/pkg/git/testing.go index 07b62941..8917f74e 100644 --- a/pkg/git/testing.go +++ b/pkg/git/testing.go @@ -453,8 +453,8 @@ func (s *GitServer) serveGitReceivePack(w http.ResponseWriter, r *http.Request, switch { case refUpdate.To.IsZero(): klog.Infof("Deleting reference %s", refUpdate.Ref) + //nolint:errcheck repo.gogit.Storer.RemoveReference(plumbing.ReferenceName(refUpdate.Ref)) - default: ref := plumbing.NewHashReference(plumbing.ReferenceName(refUpdate.Ref), refUpdate.To) if err := repo.gogit.Storer.SetReference(ref); err != nil { diff --git a/pkg/kpt/internal/set-labels.go b/pkg/kpt/internal/set-labels.go index cfad6efa..b12414ad 100644 --- a/pkg/kpt/internal/set-labels.go +++ b/pkg/kpt/internal/set-labels.go @@ -38,7 +38,9 @@ func setLabels(rl *framework.ResourceList) error { for k, v := range labels { l[k] = v } - n.SetLabels(l) + if err := n.SetLabels(l); err != nil { + return err + } } return nil diff --git a/pkg/kpt/internal/set-namespace.go b/pkg/kpt/internal/set-namespace.go index 7e038a02..91f19da8 100644 --- a/pkg/kpt/internal/set-namespace.go +++ b/pkg/kpt/internal/set-namespace.go @@ -41,7 +41,9 @@ func setNamespace(rl *framework.ResourceList) error { } for _, n := range rl.Items { - n.SetNamespace(namespace) + if err := n.SetNamespace(namespace); err != nil { + return err + } } return nil diff --git a/pkg/registry/porch/fieldselector.go b/pkg/registry/porch/fieldselector.go index 1c83b4a9..cc6e87c8 100644 --- a/pkg/registry/porch/fieldselector.go +++ b/pkg/registry/porch/fieldselector.go @@ -54,11 +54,6 @@ func convertPackageRevisionFieldSelector(label, value string) (internalLabel, in } } -// convertPackageRevisionResourcesFieldSelector is the schema conversion function for normalizing the the FieldSelector for PackageRevisionResources -func convertPackageRevisionResourcesFieldSelector(label, value string) (internalLabel, internalValue string, err error) { - return convertPackageRevisionFieldSelector(label, value) -} - // packageRevisionFilter filters packages, extending repository.ListPackageRevisionFilter type packageRevisionFilter struct { repository.ListPackageRevisionFilter diff --git a/pkg/registry/porch/storage.go b/pkg/registry/porch/storage.go index 874aa05a..e62673d7 100644 --- a/pkg/registry/porch/storage.go +++ b/pkg/registry/porch/storage.go @@ -90,8 +90,9 @@ func NewRESTStorage(scheme *runtime.Scheme, codecs serializer.CodecFactory, cad Version: apiv1alpha1.SchemeGroupVersion.Version, Kind: "Package", } - - scheme.AddFieldLabelConversionFunc(gvk, convertPackageFieldSelector) + if err := scheme.AddFieldLabelConversionFunc(gvk, convertPackageFieldSelector); err != nil { + return group, err + } } { gvk := schema.GroupVersionKind{ @@ -99,8 +100,9 @@ func NewRESTStorage(scheme *runtime.Scheme, codecs serializer.CodecFactory, cad Version: apiv1alpha1.SchemeGroupVersion.Version, Kind: "PackageRevision", } - - scheme.AddFieldLabelConversionFunc(gvk, convertPackageRevisionFieldSelector) + if err := scheme.AddFieldLabelConversionFunc(gvk, convertPackageRevisionFieldSelector); err != nil { + return group, err + } } { gvk := schema.GroupVersionKind{ @@ -108,8 +110,9 @@ func NewRESTStorage(scheme *runtime.Scheme, codecs serializer.CodecFactory, cad Version: apiv1alpha1.SchemeGroupVersion.Version, Kind: "PackageRevisionResources", } - - scheme.AddFieldLabelConversionFunc(gvk, convertPackageRevisionResourcesFieldSelector) + if err := scheme.AddFieldLabelConversionFunc(gvk, convertPackageRevisionFieldSelector); err != nil { + return group, err + } } return group, nil diff --git a/pkg/registry/porch/table.go b/pkg/registry/porch/table.go index accad4c1..1c89a239 100644 --- a/pkg/registry/porch/table.go +++ b/pkg/registry/porch/table.go @@ -69,12 +69,10 @@ func (c tableConvertor) ConvertToTable(ctx context.Context, object runtime.Objec table.Kind = "Table" if l, err := meta.ListAccessor(object); err == nil { table.ResourceVersion = l.GetResourceVersion() - table.SelfLink = l.GetSelfLink() table.Continue = l.GetContinue() table.RemainingItemCount = l.GetRemainingItemCount() } else if c, err := meta.CommonAccessor(object); err == nil { table.ResourceVersion = c.GetResourceVersion() - table.SelfLink = c.GetSelfLink() } if opt, ok := tableOptions.(*metav1.TableOptions); !ok || !opt.NoHeaders { table.ColumnDefinitions = c.columns diff --git a/pkg/task/clone_test.go b/pkg/task/clone_test.go index d9ecd57a..6856d252 100644 --- a/pkg/task/clone_test.go +++ b/pkg/task/clone_test.go @@ -80,6 +80,7 @@ func createRepoWithContents(t *testing.T, contentDir string) *gogit.Repository { if _, err := io.Copy(dst, src); err != nil { return fmt.Errorf("failed to copy file contents %q -> %q: %w", path, rel, err) } + //nolint:errcheck wt.Add(rel) return nil }); err != nil { diff --git a/pkg/task/generictaskhandler.go b/pkg/task/generictaskhandler.go index dc215288..1bd938e2 100644 --- a/pkg/task/generictaskhandler.go +++ b/pkg/task/generictaskhandler.go @@ -505,7 +505,10 @@ func healConfig(old, new map[string]string) (map[string]string, error) { n.GetName() == original.GetName() && n.GetApiVersion() == original.GetApiVersion() && n.GetKind() == original.GetKind() { - comments.CopyComments(original, n) + err = comments.CopyComments(original, n) + if err != nil { + return nil, fmt.Errorf("failed to copy comments: %w", err) + } } } } diff --git a/pkg/task/kio.go b/pkg/task/kio.go index 390ab714..4c94e87f 100644 --- a/pkg/task/kio.go +++ b/pkg/task/kio.go @@ -84,6 +84,7 @@ func (w *packageWriter) Write(nodes []*yaml.RNode) error { Writer: buf, ClearAnnotations: []string{ kioutil.PathAnnotation, + //nolint:staticcheck kioutil.LegacyPathAnnotation, }, } diff --git a/pkg/tokenexchange/gcptokensource/gcptokensource.go b/pkg/tokenexchange/gcptokensource/gcptokensource.go index 9146630a..f00319fb 100644 --- a/pkg/tokenexchange/gcptokensource/gcptokensource.go +++ b/pkg/tokenexchange/gcptokensource/gcptokensource.go @@ -20,10 +20,12 @@ import ( "time" iamv1 "cloud.google.com/go/iam/credentials/apiv1" + //nolint:staticcheck "github.com/golang/protobuf/ptypes" + //nolint:staticcheck + iampb "google.golang.org/genproto/googleapis/iam/credentials/v1" "golang.org/x/oauth2" "google.golang.org/api/option" - iampb "google.golang.org/genproto/googleapis/iam/credentials/v1" "k8s.io/klog/v2" ) @@ -70,6 +72,7 @@ func (ts *gcpTokenSource) Token() (*oauth2.Token, error) { klog.Infof("got GCP token for %v", ts.gcpServiceAccount) + //nolint:staticcheck expiry, err := ptypes.Timestamp(resp.ExpireTime) if err != nil { return nil, fmt.Errorf("failed to parse expire time on returned token: %w", err)