mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-02 00:07:50 +00:00
log info on invalid --output-version
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:
parent
6e5b455b77
commit
9c7b5c3425
@ -27,6 +27,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/meta",
|
||||
|
@ -20,6 +20,8 @@ import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"github.com/golang/glog"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
"k8s.io/apimachinery/pkg/apimachinery/registered"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@ -229,6 +231,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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user