mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 23:15:14 +00:00
Merge pull request #3441 from smarterclayton/fix_object_versioning_bug
Fix broken hack/cluster-validate.sh because output-versions were not locked
This commit is contained in:
commit
55b005732d
@ -94,29 +94,39 @@ kube_cmd=(
|
||||
"${KUBE_OUTPUT_HOSTBIN}/kubectl"
|
||||
)
|
||||
kube_api_versions=(
|
||||
""
|
||||
v1beta1
|
||||
v1beta2
|
||||
v1beta3
|
||||
)
|
||||
for version in "${kube_api_versions[@]}"; do
|
||||
kube_flags=(
|
||||
-s "http://127.0.0.1:${API_PORT}"
|
||||
--match-server-version
|
||||
--api-version="${version}"
|
||||
)
|
||||
if [[ -z "${version}" ]]; then
|
||||
kube_flags=(
|
||||
-s "http://127.0.0.1:${API_PORT}"
|
||||
--match-server-version
|
||||
)
|
||||
[ "$("${kube_cmd[@]}" get minions -t $'{{ .apiVersion }}' "${kube_flags[@]}")" == "v1beta1" ]
|
||||
else
|
||||
kube_flags=(
|
||||
-s "http://127.0.0.1:${API_PORT}"
|
||||
--match-server-version
|
||||
--api-version="${version}"
|
||||
)
|
||||
[ "$("${kube_cmd[@]}" get minions -t $'{{ .apiVersion }}' "${kube_flags[@]}")" == "${version}" ]
|
||||
fi
|
||||
|
||||
kube::log::status "Testing kubectl(${version}:pods)"
|
||||
"${kube_cmd[@]}" get pods "${kube_flags[@]}"
|
||||
"${kube_cmd[@]}" create -f examples/guestbook/redis-master.json "${kube_flags[@]}"
|
||||
"${kube_cmd[@]}" get pods "${kube_flags[@]}"
|
||||
"${kube_cmd[@]}" get pod redis-master "${kube_flags[@]}"
|
||||
[[ "$("${kube_cmd[@]}" get pod redis-master -o template --output-version=v1beta1 -t '{{ .id }}' "${kube_flags[@]}")" == "redis-master" ]]
|
||||
[ "$("${kube_cmd[@]}" get pod redis-master -o template --output-version=v1beta1 -t '{{ .id }}' "${kube_flags[@]}")" == "redis-master" ]
|
||||
output_pod=$("${kube_cmd[@]}" get pod redis-master -o json --output-version=v1beta1 "${kube_flags[@]}")
|
||||
"${kube_cmd[@]}" delete pod redis-master "${kube_flags[@]}"
|
||||
before="$("${kube_cmd[@]}" get pods -o template -t "{{ len .items }}" "${kube_flags[@]}")"
|
||||
echo $output_pod | "${kube_cmd[@]}" create -f - "${kube_flags[@]}"
|
||||
after="$("${kube_cmd[@]}" get pods -o template -t "{{ len .items }}" "${kube_flags[@]}")"
|
||||
[[ "$((${after} - ${before}))" -eq 1 ]]
|
||||
[ "$((${after} - ${before}))" -eq 1 ]
|
||||
"${kube_cmd[@]}" get pods -o yaml --output-version=v1beta1 "${kube_flags[@]}" | grep -q "id: redis-master"
|
||||
"${kube_cmd[@]}" describe pod redis-master "${kube_flags[@]}" | grep -q 'Name:.*redis-master'
|
||||
"${kube_cmd[@]}" delete -f examples/guestbook/redis-master.json "${kube_flags[@]}"
|
||||
@ -142,6 +152,9 @@ for version in "${kube_api_versions[@]}"; do
|
||||
kube::log::status "Testing kubectl(${version}:minions)"
|
||||
"${kube_cmd[@]}" get minions "${kube_flags[@]}"
|
||||
"${kube_cmd[@]}" get minions 127.0.0.1 "${kube_flags[@]}"
|
||||
"${kube_cmd[@]}" get minions -o template -t $'{{range.items}}{{.id}}\n{{end}}' "${kube_flags[@]}"
|
||||
# TODO: I should be a MinionList instead of List
|
||||
[ "$("${kube_cmd[@]}" get minions -t $'{{ .kind }}' "${kube_flags[@]}")" == "List" ]
|
||||
fi
|
||||
done
|
||||
|
||||
|
@ -325,17 +325,9 @@ func (c *clientCache) ClientConfigForVersion(version string) (*client.Config, er
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: remove when SetKubernetesDefaults gets added
|
||||
if len(version) == 0 {
|
||||
version = c.defaultConfig.Version
|
||||
}
|
||||
|
||||
// TODO: have a better config copy method
|
||||
config := *c.defaultConfig
|
||||
|
||||
// TODO: call new client.SetKubernetesDefaults method
|
||||
// instead of doing this
|
||||
config.Version = version
|
||||
client.SetKubernetesDefaults(&config)
|
||||
return &config, nil
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ import (
|
||||
"io"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/meta"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/resource"
|
||||
@ -126,7 +127,15 @@ func RunGet(f *Factory, out io.Writer, cmd *cobra.Command, args []string) {
|
||||
|
||||
if generic {
|
||||
// the outermost object will be converted to the output-version
|
||||
printer = kubectl.NewVersionedPrinter(printer, api.Scheme, outputVersion(cmd))
|
||||
version := outputVersion(cmd)
|
||||
if len(version) == 0 {
|
||||
// TODO: add a new ResourceBuilder mode for Object() that attempts to ensure the objects
|
||||
// are in the appropriate version if one exists (and if not, use the best effort).
|
||||
// TODO: ensure api-version is set with the default preferred api version by the client
|
||||
// builder on initialization
|
||||
version = latest.Version
|
||||
}
|
||||
printer = kubectl.NewVersionedPrinter(printer, api.Scheme, version)
|
||||
|
||||
obj, err := b.Flatten().Do().Object()
|
||||
checkErr(err)
|
||||
@ -174,7 +183,14 @@ func printerForMapping(f *Factory, cmd *cobra.Command, mapping *meta.RESTMapping
|
||||
return nil, err
|
||||
}
|
||||
if ok {
|
||||
printer = kubectl.NewVersionedPrinter(printer, mapping.ObjectConvertor, outputVersion(cmd))
|
||||
version := outputVersion(cmd)
|
||||
if len(version) == 0 {
|
||||
version = mapping.APIVersion
|
||||
}
|
||||
if len(version) == 0 {
|
||||
return nil, fmt.Errorf("you must specify an output-version when using this output format")
|
||||
}
|
||||
printer = kubectl.NewVersionedPrinter(printer, mapping.ObjectConvertor, version)
|
||||
} else {
|
||||
printer, err = f.Printer(cmd, mapping, GetFlagBool(cmd, "no-headers"))
|
||||
if err != nil {
|
||||
|
@ -109,6 +109,9 @@ func NewVersionedPrinter(printer ResourcePrinter, convertor runtime.ObjectConver
|
||||
|
||||
// PrintObj implements ResourcePrinter
|
||||
func (p *VersionedPrinter) PrintObj(obj runtime.Object, w io.Writer) error {
|
||||
if len(p.version) == 0 {
|
||||
return fmt.Errorf("no version specified, object cannot be converted")
|
||||
}
|
||||
converted, err := p.convertor.ConvertToVersion(obj, p.version)
|
||||
if err != nil {
|
||||
return err
|
||||
|
Loading…
Reference in New Issue
Block a user