mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-15 14:14:39 +00:00
Turn pkg/api/pod_example.json into go struct to avoid noise in pprof
This commit is contained in:
@@ -38,15 +38,7 @@ func BenchmarkPodConversion(b *testing.B) {
|
||||
}
|
||||
|
||||
// add a fixed item
|
||||
data, err := ioutil.ReadFile("pod_example.json")
|
||||
if err != nil {
|
||||
b.Fatalf("Unexpected error while reading file: %v", err)
|
||||
}
|
||||
var pod api.Pod
|
||||
if err := runtime.DecodeInto(testapi.Default.Codec(), data, &pod); err != nil {
|
||||
b.Fatalf("Unexpected error decoding pod: %v", err)
|
||||
}
|
||||
items = append(items, pod)
|
||||
items = append(items, benchmarkPod)
|
||||
width := len(items)
|
||||
|
||||
scheme := api.Scheme
|
||||
|
@@ -19,32 +19,129 @@ package api_test
|
||||
import (
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/testapi"
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/types"
|
||||
)
|
||||
|
||||
func BenchmarkPodCopy(b *testing.B) {
|
||||
data, err := ioutil.ReadFile("pod_example.json")
|
||||
func parseTimeOrDie(ts string) unversioned.Time {
|
||||
t, err := time.Parse(time.RFC3339, ts)
|
||||
if err != nil {
|
||||
b.Fatalf("Unexpected error while reading file: %v", err)
|
||||
}
|
||||
var pod api.Pod
|
||||
if err := runtime.DecodeInto(testapi.Default.Codec(), data, &pod); err != nil {
|
||||
b.Fatalf("Unexpected error decoding pod: %v", err)
|
||||
panic(err)
|
||||
}
|
||||
return unversioned.Time{Time: t}
|
||||
}
|
||||
|
||||
var benchmarkPod api.Pod = api.Pod{
|
||||
TypeMeta: unversioned.TypeMeta{
|
||||
Kind: "Pod",
|
||||
APIVersion: "v1",
|
||||
},
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "etcd-server-e2e-test-wojtekt-master",
|
||||
Namespace: "default",
|
||||
SelfLink: "/api/v1/namespaces/default/pods/etcd-server-e2e-test-wojtekt-master",
|
||||
UID: types.UID("a671734a-e8e5-11e4-8fde-42010af09327"),
|
||||
ResourceVersion: "22",
|
||||
CreationTimestamp: parseTimeOrDie("2015-04-22T11:49:36Z"),
|
||||
Annotations: map[string]string{
|
||||
"kubernetes.io/config.mirror": "mirror",
|
||||
"kubernetes.io/config.source": "file",
|
||||
},
|
||||
},
|
||||
Spec: api.PodSpec{
|
||||
Volumes: []api.Volume{
|
||||
{
|
||||
Name: "varetcd",
|
||||
VolumeSource: api.VolumeSource{
|
||||
HostPath: &api.HostPathVolumeSource{
|
||||
Path: "/mnt/master-pd/var/etcd",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Name: "etcd-container",
|
||||
Image: "gcr.io/google_containers/etcd:2.0.9",
|
||||
Command: []string{
|
||||
"/usr/local/bin/etcd",
|
||||
"--addr",
|
||||
"127.0.0.1:4001",
|
||||
"--bind-addr",
|
||||
"127.0.0.1:4001",
|
||||
"--data-dir",
|
||||
"/var/etcd/data",
|
||||
},
|
||||
Ports: []api.ContainerPort{
|
||||
{
|
||||
Name: "serverport",
|
||||
HostPort: 2380,
|
||||
ContainerPort: 2380,
|
||||
Protocol: "TCP",
|
||||
},
|
||||
{
|
||||
Name: "clientport",
|
||||
HostPort: 4001,
|
||||
ContainerPort: 4001,
|
||||
Protocol: "TCP",
|
||||
},
|
||||
},
|
||||
VolumeMounts: []api.VolumeMount{
|
||||
{
|
||||
Name: "varetcd",
|
||||
MountPath: "/var/etcd",
|
||||
},
|
||||
},
|
||||
TerminationMessagePath: "/dev/termination-log",
|
||||
ImagePullPolicy: api.PullIfNotPresent,
|
||||
},
|
||||
},
|
||||
RestartPolicy: api.RestartPolicyAlways,
|
||||
DNSPolicy: api.DNSClusterFirst,
|
||||
NodeName: "e2e-test-wojtekt-master",
|
||||
},
|
||||
Status: api.PodStatus{
|
||||
Phase: api.PodRunning,
|
||||
Conditions: []api.PodCondition{
|
||||
{
|
||||
Type: api.PodReady,
|
||||
Status: api.ConditionTrue,
|
||||
},
|
||||
},
|
||||
ContainerStatuses: []api.ContainerStatus{
|
||||
{
|
||||
Name: "etcd-container",
|
||||
State: api.ContainerState{
|
||||
Running: &api.ContainerStateRunning{
|
||||
StartedAt: parseTimeOrDie("2015-04-22T11:49:32Z"),
|
||||
},
|
||||
},
|
||||
Ready: true,
|
||||
RestartCount: 0,
|
||||
Image: "gcr.io/google_containers/etcd:2.0.9",
|
||||
ImageID: "docker://b6b9a86dc06aa1361357ca1b105feba961f6a4145adca6c54e142c0be0fe87b0",
|
||||
ContainerID: "docker://3cbbf818f1addfc252957b4504f56ef2907a313fe6afc47fc75373674255d46d",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func BenchmarkPodCopy(b *testing.B) {
|
||||
var result *api.Pod
|
||||
for i := 0; i < b.N; i++ {
|
||||
obj, err := api.Scheme.DeepCopy(&pod)
|
||||
obj, err := api.Scheme.DeepCopy(&benchmarkPod)
|
||||
if err != nil {
|
||||
b.Fatalf("Unexpected error copying pod: %v", err)
|
||||
}
|
||||
result = obj.(*api.Pod)
|
||||
}
|
||||
if !api.Semantic.DeepEqual(pod, *result) {
|
||||
b.Fatalf("Incorrect copy: expected %v, got %v", pod, *result)
|
||||
if !api.Semantic.DeepEqual(benchmarkPod, *result) {
|
||||
b.Fatalf("Incorrect copy: expected %v, got %v", benchmarkPod, *result)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,102 +0,0 @@
|
||||
{
|
||||
"kind": "Pod",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "etcd-server-e2e-test-wojtekt-master",
|
||||
"namespace": "default",
|
||||
"selfLink": "/api/v1/namespaces/default/pods/etcd-server-e2e-test-wojtekt-master",
|
||||
"uid": "a671734a-e8e5-11e4-8fde-42010af09327",
|
||||
"resourceVersion": "22",
|
||||
"creationTimestamp": "2015-04-22T11:49:36Z",
|
||||
"annotations": {
|
||||
"kubernetes.io/config.mirror": "mirror",
|
||||
"kubernetes.io/config.source": "file"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"volumes": [
|
||||
{
|
||||
"name": "varetcd",
|
||||
"hostPath": {
|
||||
"path": "/mnt/master-pd/var/etcd"
|
||||
},
|
||||
"emptyDir": null,
|
||||
"gcePersistentDisk": null,
|
||||
"awsElasticBlockStore": null,
|
||||
"gitRepo": null,
|
||||
"secret": null,
|
||||
"nfs": null,
|
||||
"iscsi": null,
|
||||
"glusterfs": null
|
||||
}
|
||||
],
|
||||
"containers": [
|
||||
{
|
||||
"name": "etcd-container",
|
||||
"image": "gcr.io/google_containers/etcd:2.0.9",
|
||||
"command": [
|
||||
"/usr/local/bin/etcd",
|
||||
"--addr",
|
||||
"127.0.0.1:4001",
|
||||
"--bind-addr",
|
||||
"127.0.0.1:4001",
|
||||
"--data-dir",
|
||||
"/var/etcd/data"
|
||||
],
|
||||
"ports": [
|
||||
{
|
||||
"name": "serverport",
|
||||
"hostPort": 2380,
|
||||
"containerPort": 2380,
|
||||
"protocol": "TCP"
|
||||
},
|
||||
{
|
||||
"name": "clientport",
|
||||
"hostPort": 4001,
|
||||
"containerPort": 4001,
|
||||
"protocol": "TCP"
|
||||
}
|
||||
],
|
||||
"resources": {},
|
||||
"volumeMounts": [
|
||||
{
|
||||
"name": "varetcd",
|
||||
"mountPath": "/var/etcd"
|
||||
}
|
||||
],
|
||||
"terminationMessagePath": "/dev/termination-log",
|
||||
"imagePullPolicy": "IfNotPresent",
|
||||
"capabilities": {}
|
||||
}
|
||||
],
|
||||
"restartPolicy": "Always",
|
||||
"dnsPolicy": "ClusterFirst",
|
||||
"nodeName": "e2e-test-wojtekt-master",
|
||||
"hostNetwork": true
|
||||
},
|
||||
"status": {
|
||||
"phase": "Running",
|
||||
"conditions": [
|
||||
{
|
||||
"type": "Ready",
|
||||
"status": "True"
|
||||
}
|
||||
],
|
||||
"containerStatuses": [
|
||||
{
|
||||
"name": "etcd-container",
|
||||
"state": {
|
||||
"running": {
|
||||
"startedAt": "2015-04-22T11:49:32Z"
|
||||
}
|
||||
},
|
||||
"lastState": {},
|
||||
"ready": true,
|
||||
"restartCount": 0,
|
||||
"image": "gcr.io/google_containers/etcd:2.0.9",
|
||||
"imageID": "docker://b6b9a86dc06aa1361357ca1b105feba961f6a4145adca6c54e142c0be0fe87b0",
|
||||
"containerID": "docker://3cbbf818f1addfc252957b4504f56ef2907a313fe6afc47fc75373674255d46d"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user