diff --git a/Makefile b/Makefile index 6afbc785..cf1acddc 100644 --- a/Makefile +++ b/Makefile @@ -84,7 +84,7 @@ GOLANGCI_LINT_BIN := golangci-lint GOLANGCI_LINT := $(abspath $(OUTPUT_TOOLS_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER)) GOLANGCI_LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint -GORELEASER_VER := $(shell cat .github/workflows/releaser.yaml | grep [[:space:]]version | sed 's/.*version: //') +GORELEASER_VER := v2.5.1 GORELEASER_BIN := goreleaser GORELEASER := $(abspath $(OUTPUT_TOOLS_DIR)/$(GORELEASER_BIN)-$(GORELEASER_VER)) GORELEASER_PKG := github.com/goreleaser/goreleaser/v2 diff --git a/pkg/proxy/internal/file_storage.go b/pkg/proxy/internal/file_storage.go index 23fd5040..2609aab5 100644 --- a/pkg/proxy/internal/file_storage.go +++ b/pkg/proxy/internal/file_storage.go @@ -103,8 +103,10 @@ func (s fileStorage) Create(_ context.Context, key string, obj, out runtime.Obje if err != nil { return errors.Wrapf(err, "failed to encode object %q", key) } - if err := decode(s.codec, data, out); err != nil { - return err + if out != nil { + if err := runtime.DecodeInto(s.codec, data, out); err != nil { + return errors.Wrapf(err, "unable to decode the created object data for %q", key) + } } // render to file if err := os.WriteFile(key+yamlSuffix, data, os.ModePerm); err != nil { @@ -156,7 +158,7 @@ func (s fileStorage) Get(_ context.Context, key string, _ apistorage.GetOptions, return err } - return decode(s.codec, data, out) + return runtime.DecodeInto(s.codec, data, out) } // GetList local resource files. @@ -416,9 +418,8 @@ func (s fileStorage) GuaranteedUpdate(ctx context.Context, key string, destinati } // render to destination if destination != nil { - err = decode(s.codec, data, destination) - if err != nil { - return err + if err := runtime.DecodeInto(s.codec, data, destination); err != nil { + return errors.Wrapf(err, "unable to decode the updated object data for %q", key) } } // render to file @@ -481,20 +482,6 @@ func (s fileStorage) RequestWatchProgress(context.Context) error { return nil } -// decode decodes value of bytes into object. It will also set the object resource version to rev. -// On success, objPtr would be set to the object. -func decode(codec runtime.Codec, value []byte, objPtr runtime.Object) error { - if _, err := conversion.EnforcePtr(objPtr); err != nil { - return errors.Wrap(err, "failed to convert output object to pointer") - } - _, _, err := codec.Decode(value, nil, objPtr) - if err != nil { - return errors.Wrap(err, "failed to decode output object") - } - - return nil -} - func getNewItem(listObj runtime.Object, v reflect.Value) runtime.Object { // For unstructured lists with a target group/version, preserve the group/version in the instantiated list items if unstructuredList, isUnstructured := listObj.(*unstructured.UnstructuredList); isUnstructured {