mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-02 11:18:16 +00:00
Merge pull request #34763 from juanvallejo/jvallejo/add-warning-on-export-invalid-output-version
Automatic merge from submit-queue
log info on invalid --output-version
**Release note**:
``` release-note
release-note-none
```
Object versions default to the current version (v1) when a specified
`--output-version` is invalid. This patch logs a warning when this is
the case. Cases affected are all commands with the `--output-version`
option, and anywhere runtime objects are converted to versioned objects.
**Example**
```
$ kubectl get pod <mypod> -o json --output-version=invalid
W1013 17:24:16.810278 26719 result.go:238] info: the output version
specified (invalid) is invalid, defaulting to v1
{
"kind": "Pod",
"apiVersion": "v1",
"metadata": {
"name": "mypod",
"namespace": "test",
...
```
This commit is contained in:
@@ -26,6 +26,7 @@ go_library(
|
||||
"//pkg/api/validation:go_default_library",
|
||||
"//pkg/apis/extensions:go_default_library",
|
||||
"//pkg/client/restclient:go_default_library",
|
||||
"//vendor:github.com/golang/glog",
|
||||
"//vendor:golang.org/x/text/encoding/unicode",
|
||||
"//vendor:golang.org/x/text/transform",
|
||||
"//vendor:k8s.io/apimachinery/pkg/api/errors",
|
||||
|
||||
@@ -20,6 +20,8 @@ import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"github.com/golang/glog"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
@@ -228,6 +230,15 @@ func AsVersionedObject(infos []*Info, forceList bool, version schema.GroupVersio
|
||||
}
|
||||
object = converted
|
||||
}
|
||||
|
||||
actualVersion := object.GetObjectKind().GroupVersionKind()
|
||||
if actualVersion.Version != version.Version {
|
||||
defaultVersionInfo := ""
|
||||
if len(actualVersion.Version) > 0 {
|
||||
defaultVersionInfo = fmt.Sprintf("Defaulting to %q", actualVersion.Version)
|
||||
}
|
||||
glog.V(1).Infof("info: the output version specified is invalid. %s\n", defaultVersionInfo)
|
||||
}
|
||||
return object, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user