mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
(kubectl patch): Add descriptive message when patch type is unsupported
`kubectl patch` commands fails when patch type is strategic merge patch for CRDs. This PR handles `UnsupportedMediaType` error and shows descriptive message to user.
This commit is contained in:
parent
127f33f63d
commit
dc2c0ad831
@ -23,9 +23,11 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
jsonpatch "github.com/evanphx/json-patch"
|
jsonpatch "github.com/evanphx/json-patch"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
|
|
||||||
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
"k8s.io/apimachinery/pkg/api/meta"
|
||||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
@ -270,6 +272,9 @@ func (o *PatchOptions) RunPatch() error {
|
|||||||
WithSubresource(o.Subresource)
|
WithSubresource(o.Subresource)
|
||||||
patchedObj, err := helper.Patch(namespace, name, patchType, patchBytes, nil)
|
patchedObj, err := helper.Patch(namespace, name, patchType, patchBytes, nil)
|
||||||
if err != 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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user