Commit 85882ade authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #39418 from wojtek-t/reflection_based_conversion_to_unstructured_2

Automatic merge from submit-queue (batch tested with PRs 39418, 41175, 40355, 41114, 32325) runtime.Object <-> Unstructured conversion Ref #39017
parents b31cf72f 2dd0f10d
...@@ -93,6 +93,7 @@ go_test( ...@@ -93,6 +93,7 @@ go_test(
"//vendor:k8s.io/apimachinery/pkg/api/testing", "//vendor:k8s.io/apimachinery/pkg/api/testing",
"//vendor:k8s.io/apimachinery/pkg/apis/meta/v1", "//vendor:k8s.io/apimachinery/pkg/apis/meta/v1",
"//vendor:k8s.io/apimachinery/pkg/conversion", "//vendor:k8s.io/apimachinery/pkg/conversion",
"//vendor:k8s.io/apimachinery/pkg/conversion/unstructured",
"//vendor:k8s.io/apimachinery/pkg/runtime", "//vendor:k8s.io/apimachinery/pkg/runtime",
"//vendor:k8s.io/apimachinery/pkg/runtime/schema", "//vendor:k8s.io/apimachinery/pkg/runtime/schema",
"//vendor:k8s.io/apimachinery/pkg/runtime/serializer/protobuf", "//vendor:k8s.io/apimachinery/pkg/runtime/serializer/protobuf",
......
...@@ -28,6 +28,8 @@ import ( ...@@ -28,6 +28,8 @@ import (
kapitesting "k8s.io/kubernetes/pkg/api/testing" kapitesting "k8s.io/kubernetes/pkg/api/testing"
"k8s.io/kubernetes/pkg/api/v1" "k8s.io/kubernetes/pkg/api/v1"
"k8s.io/apimachinery/pkg/conversion/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apimachinery/pkg/util/json" "k8s.io/apimachinery/pkg/util/json"
...@@ -95,27 +97,23 @@ func doRoundTrip(t *testing.T, group testapi.TestGroup, kind string) { ...@@ -95,27 +97,23 @@ func doRoundTrip(t *testing.T, group testapi.TestGroup, kind string) {
return return
} }
// TODO; Enable the following part of test once to/from unstructured newUnstr := make(map[string]interface{})
// format conversions are implemented. err = unstructured.NewConverter().ToUnstructured(item, &newUnstr)
/* if err != nil {
newUnstr := make(map[string]interface{}) t.Errorf("ToUnstructured failed: %v", err)
err = unstructured.NewConverter().ToUnstructured(item, &newUnstr) return
if err != nil { }
t.Errorf("ToUnstructured failed: %v", err)
return
}
newObj := reflect.New(reflect.TypeOf(item).Elem()).Interface().(runtime.Object) newObj := reflect.New(reflect.TypeOf(item).Elem()).Interface().(runtime.Object)
err = unstructured.NewConverter().FromUnstructured(newUnstr, newObj) err = unstructured.NewConverter().FromUnstructured(newUnstr, newObj)
if err != nil { if err != nil {
t.Errorf("FromUnstructured failed: %v", err) t.Errorf("FromUnstructured failed: %v", err)
return return
} }
if !apiequality.Semantic.DeepEqual(item, newObj) { if !apiequality.Semantic.DeepEqual(item, newObj) {
t.Errorf("Object changed, diff: %v", diff.ObjectReflectDiff(item, newObj)) t.Errorf("Object changed, diff: %v", diff.ObjectReflectDiff(item, newObj))
} }
*/
} }
func TestRoundTrip(t *testing.T) { func TestRoundTrip(t *testing.T) {
...@@ -135,11 +133,8 @@ func TestRoundTrip(t *testing.T) { ...@@ -135,11 +133,8 @@ func TestRoundTrip(t *testing.T) {
} }
} }
// TODO; Enable the following benchmark once to/from unstructured
// format conversions are implemented.
/*
func BenchmarkToFromUnstructured(b *testing.B) { func BenchmarkToFromUnstructured(b *testing.B) {
items := benchmarkItems() items := benchmarkItems(b)
size := len(items) size := len(items)
b.ResetTimer() b.ResetTimer()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
...@@ -154,7 +149,6 @@ func BenchmarkToFromUnstructured(b *testing.B) { ...@@ -154,7 +149,6 @@ func BenchmarkToFromUnstructured(b *testing.B) {
} }
b.StopTimer() b.StopTimer()
} }
*/
func BenchmarkToFromUnstructuredViaJSON(b *testing.B) { func BenchmarkToFromUnstructuredViaJSON(b *testing.B) {
items := benchmarkItems(b) items := benchmarkItems(b)
......
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package unstructured provides conversion from runtime objects
// to map[string]interface{} representation.
package unstructured // import "k8s.io/apimachinery/pkg/conversion/unstructured"
...@@ -15414,3 +15414,29 @@ go_library( ...@@ -15414,3 +15414,29 @@ go_library(
"//vendor:k8s.io/sample-apiserver/pkg/apis/wardle", "//vendor:k8s.io/sample-apiserver/pkg/apis/wardle",
], ],
) )
go_test(
name = "k8s.io/apimachinery/pkg/conversion/unstructured_test",
srcs = ["k8s.io/apimachinery/pkg/conversion/unstructured/converter_test.go"],
library = ":k8s.io/apimachinery/pkg/conversion/unstructured",
tags = ["automanaged"],
deps = [
"//vendor:k8s.io/apimachinery/pkg/runtime",
"//vendor:k8s.io/apimachinery/pkg/runtime/schema",
"//vendor:k8s.io/apimachinery/pkg/util/diff",
"//vendor:k8s.io/apimachinery/pkg/util/json",
],
)
go_library(
name = "k8s.io/apimachinery/pkg/conversion/unstructured",
srcs = [
"k8s.io/apimachinery/pkg/conversion/unstructured/converter.go",
"k8s.io/apimachinery/pkg/conversion/unstructured/doc.go",
],
tags = ["automanaged"],
deps = [
"//vendor:k8s.io/apimachinery/pkg/runtime",
"//vendor:k8s.io/apimachinery/pkg/util/json",
],
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment