Merge pull request #112556 from ardaguclu/patch-smp-error-msg

(kubectl patch): Add descriptive message when patch type is unsupported
This commit is contained in:
Kubernetes Prow Robot 2022-09-19 21:17:19 -07:00 committed by GitHub
commit 6ee3cbd931
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,9 +23,11 @@ import (
"strings"
jsonpatch "github.com/evanphx/json-patch"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"k8s.io/klog/v2"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
@ -272,6 +274,9 @@ func (o *PatchOptions) RunPatch() error {
WithSubresource(o.Subresource)
patchedObj, err := helper.Patch(namespace, name, patchType, patchBytes, nil)
if err != nil {
if apierrors.IsUnsupportedMediaType(err) {
return errors.Wrap(err, fmt.Sprintf("%s is not supported by %s", patchType, mapping.GroupVersionKind))
}
return err
}