本文整理匯總了Golang中k8s/io/kubernetes/pkg/runtime.Unstructured.GetKind方法的典型用法代碼示例。如果您正苦於以下問題:Golang Unstructured.GetKind方法的具體用法?Golang Unstructured.GetKind怎麽用?Golang Unstructured.GetKind使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類k8s/io/kubernetes/pkg/runtime.Unstructured
的用法示例。
在下文中一共展示了Unstructured.GetKind方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestUnstructuredGetters
func TestUnstructuredGetters(t *testing.T) {
unstruct := runtime.Unstructured{
Object: map[string]interface{}{
"kind": "test_kind",
"apiVersion": "test_version",
"metadata": map[string]interface{}{
"name": "test_name",
"namespace": "test_namespace",
"generateName": "test_generateName",
"uid": "test_uid",
"resourceVersion": "test_resourceVersion",
"selfLink": "test_selfLink",
"creationTimestamp": "2009-11-10T23:00:00Z",
"deletionTimestamp": "2010-11-10T23:00:00Z",
"labels": map[string]interface{}{
"test_label": "test_value",
},
"annotations": map[string]interface{}{
"test_annotation": "test_value",
},
"ownerReferences": []map[string]interface{}{
{
"kind": "Pod",
"name": "poda",
"apiVersion": "v1",
"uid": "1",
},
{
"kind": "Pod",
"name": "podb",
"apiVersion": "v1",
"uid": "2",
},
},
"finalizers": []interface{}{
"finalizer.1",
"finalizer.2",
},
"clusterName": "cluster123",
},
},
}
if got, want := unstruct.GetAPIVersion(), "test_version"; got != want {
t.Errorf("GetAPIVersions() = %s, want %s", got, want)
}
if got, want := unstruct.GetKind(), "test_kind"; got != want {
t.Errorf("GetKind() = %s, want %s", got, want)
}
if got, want := unstruct.GetNamespace(), "test_namespace"; got != want {
t.Errorf("GetNamespace() = %s, want %s", got, want)
}
if got, want := unstruct.GetName(), "test_name"; got != want {
t.Errorf("GetName() = %s, want %s", got, want)
}
if got, want := unstruct.GetGenerateName(), "test_generateName"; got != want {
t.Errorf("GetGenerateName() = %s, want %s", got, want)
}
if got, want := unstruct.GetUID(), types.UID("test_uid"); got != want {
t.Errorf("GetUID() = %s, want %s", got, want)
}
if got, want := unstruct.GetResourceVersion(), "test_resourceVersion"; got != want {
t.Errorf("GetResourceVersion() = %s, want %s", got, want)
}
if got, want := unstruct.GetSelfLink(), "test_selfLink"; got != want {
t.Errorf("GetSelfLink() = %s, want %s", got, want)
}
if got, want := unstruct.GetCreationTimestamp(), unversioned.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC); !got.Equal(want) {
t.Errorf("GetCreationTimestamp() = %s, want %s", got, want)
}
if got, want := unstruct.GetDeletionTimestamp(), unversioned.Date(2010, time.November, 10, 23, 0, 0, 0, time.UTC); got == nil || !got.Equal(want) {
t.Errorf("GetDeletionTimestamp() = %s, want %s", got, want)
}
if got, want := unstruct.GetLabels(), map[string]string{"test_label": "test_value"}; !reflect.DeepEqual(got, want) {
t.Errorf("GetLabels() = %s, want %s", got, want)
}
if got, want := unstruct.GetAnnotations(), map[string]string{"test_annotation": "test_value"}; !reflect.DeepEqual(got, want) {
t.Errorf("GetAnnotations() = %s, want %s", got, want)
}
refs := unstruct.GetOwnerReferences()
expectedOwnerReferences := []metatypes.OwnerReference{
{
Kind: "Pod",
Name: "poda",
APIVersion: "v1",
UID: "1",
},
{
Kind: "Pod",
//.........這裏部分代碼省略.........
示例2: TestUnstructuredGetters
func TestUnstructuredGetters(t *testing.T) {
unstruct := runtime.Unstructured{
Object: map[string]interface{}{
"kind": "test_kind",
"apiVersion": "test_version",
"metadata": map[string]interface{}{
"name": "test_name",
"namespace": "test_namespace",
"generateName": "test_generateName",
"uid": "test_uid",
"resourceVersion": "test_resourceVersion",
"selfLink": "test_selfLink",
"creationTimestamp": "2009-11-10T23:00:00Z",
"deletionTimestamp": "2010-11-10T23:00:00Z",
"labels": map[string]interface{}{
"test_label": "test_value",
},
"annotations": map[string]interface{}{
"test_annotation": "test_value",
},
},
},
}
if got, want := unstruct.GetAPIVersion(), "test_version"; got != want {
t.Errorf("GetAPIVersions() = %s, want %s", got, want)
}
if got, want := unstruct.GetKind(), "test_kind"; got != want {
t.Errorf("GetKind() = %s, want %s", got, want)
}
if got, want := unstruct.GetNamespace(), "test_namespace"; got != want {
t.Errorf("GetNamespace() = %s, want %s", got, want)
}
if got, want := unstruct.GetName(), "test_name"; got != want {
t.Errorf("GetName() = %s, want %s", got, want)
}
if got, want := unstruct.GetGenerateName(), "test_generateName"; got != want {
t.Errorf("GetGenerateName() = %s, want %s", got, want)
}
if got, want := unstruct.GetUID(), types.UID("test_uid"); got != want {
t.Errorf("GetUID() = %s, want %s", got, want)
}
if got, want := unstruct.GetResourceVersion(), "test_resourceVersion"; got != want {
t.Errorf("GetResourceVersion() = %s, want %s", got, want)
}
if got, want := unstruct.GetSelfLink(), "test_selfLink"; got != want {
t.Errorf("GetSelfLink() = %s, want %s", got, want)
}
if got, want := unstruct.GetCreationTimestamp(), unversioned.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC); !got.Equal(want) {
t.Errorf("GetCreationTimestamp() = %s, want %s", got, want)
}
if got, want := unstruct.GetDeletionTimestamp(), unversioned.Date(2010, time.November, 10, 23, 0, 0, 0, time.UTC); got == nil || !got.Equal(want) {
t.Errorf("GetDeletionTimestamp() = %s, want %s", got, want)
}
if got, want := unstruct.GetLabels(), map[string]string{"test_label": "test_value"}; !reflect.DeepEqual(got, want) {
t.Errorf("GetLabels() = %s, want %s", got, want)
}
if got, want := unstruct.GetAnnotations(), map[string]string{"test_annotation": "test_value"}; !reflect.DeepEqual(got, want) {
t.Errorf("GetAnnotations() = %s, want %s", got, want)
}
}