diff --git a/pkg/conversion/conversion_test.go b/pkg/conversion/conversion_test.go new file mode 100644 index 0000000000..24897ecf89 --- /dev/null +++ b/pkg/conversion/conversion_test.go @@ -0,0 +1,97 @@ +/* +Copyright 2015 Google Inc. All rights reserved. + +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 conversion_test + +import ( + "io/ioutil" + "testing" + + "github.com/GoogleCloudPlatform/kubernetes/pkg/api" + "github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi" + _ "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1" + _ "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta2" + _ "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta3" +) + +func BenchmarkPodConversion(b *testing.B) { + 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 := api.Scheme.DecodeInto(data, &pod); err != nil { + b.Fatalf("unexpected error decoding pod: %v", err) + } + + scheme := api.Scheme.Raw() + for i := 0; i < b.N; i++ { + versionedObj, err := scheme.ConvertToVersion(&pod, testapi.Version()) + if err != nil { + b.Fatalf("Conversion error: %v", err) + } + _, err = scheme.ConvertToVersion(versionedObj, scheme.InternalVersion) + if err != nil { + b.Fatalf("Conversion error: %v", err) + } + } +} + +func BenchmarkNodeConversion(b *testing.B) { + data, err := ioutil.ReadFile("node_example.json") + if err != nil { + b.Fatalf("unexpected error while reading file: %v", err) + } + var node api.Node + if err := api.Scheme.DecodeInto(data, &node); err != nil { + b.Fatalf("unexpected error decoding node: %v", err) + } + + scheme := api.Scheme.Raw() + for i := 0; i < b.N; i++ { + versionedObj, err := scheme.ConvertToVersion(&node, testapi.Version()) + if err != nil { + b.Fatalf("Conversion error: %v", err) + } + _, err = scheme.ConvertToVersion(versionedObj, scheme.InternalVersion) + if err != nil { + b.Fatalf("Conversion error: %v", err) + } + } +} + +func BenchmarkReplicationControllerConversion(b *testing.B) { + data, err := ioutil.ReadFile("replication_controller_example.json") + if err != nil { + b.Fatalf("unexpected error while reading file: %v", err) + } + var replicationController api.ReplicationController + if err := api.Scheme.DecodeInto(data, &replicationController); err != nil { + b.Fatalf("unexpected error decoding node: %v", err) + } + + scheme := api.Scheme.Raw() + for i := 0; i < b.N; i++ { + versionedObj, err := scheme.ConvertToVersion(&replicationController, testapi.Version()) + if err != nil { + b.Fatalf("Conversion error: %v", err) + } + _, err = scheme.ConvertToVersion(versionedObj, scheme.InternalVersion) + if err != nil { + b.Fatalf("Conversion error: %v", err) + } + } +} diff --git a/pkg/conversion/node_example.json b/pkg/conversion/node_example.json new file mode 100644 index 0000000000..792995b84d --- /dev/null +++ b/pkg/conversion/node_example.json @@ -0,0 +1,49 @@ +{ + "kind": "Node", + "apiVersion": "v1beta3", + "metadata": { + "name": "e2e-test-wojtekt-minion-etd6", + "selfLink": "/api/v1beta1/nodes/e2e-test-wojtekt-minion-etd6", + "uid": "a7e89222-e8e5-11e4-8fde-42010af09327", + "resourceVersion": "379", + "creationTimestamp": "2015-04-22T11:49:39Z" + }, + "spec": { + "externalID": "15488322946290398375" + }, + "status": { + "capacity": { + "cpu": "1", + "memory": "1745152Ki" + }, + "conditions": [ + { + "type": "Ready", + "status": "True", + "lastHeartbeatTime": "2015-04-22T11:58:17Z", + "lastTransitionTime": "2015-04-22T11:49:52Z", + "reason": "kubelet is posting ready status" + } + ], + "addresses": [ + { + "type": "ExternalIP", + "address": "104.197.49.213" + }, + { + "type": "LegacyHostIP", + "address": "104.197.20.11" + } + ], + "nodeInfo": { + "machineID": "", + "systemUUID": "D59FA3FA-7B5B-7287-5E1A-1D79F13CB577", + "bootID": "44a832f3-8cfb-4de5-b7d2-d66030b6cd95", + "kernelVersion": "3.16.0-0.bpo.4-amd64", + "osImage": "Debian GNU/Linux 7 (wheezy)", + "containerRuntimeVersion": "docker://1.5.0", + "kubeletVersion": "v0.15.0-484-g0c8ee980d705a3-dirty", + "KubeProxyVersion": "v0.15.0-484-g0c8ee980d705a3-dirty" + } + } +} diff --git a/pkg/conversion/pod_example.json b/pkg/conversion/pod_example.json new file mode 100644 index 0000000000..0bfa6adab9 --- /dev/null +++ b/pkg/conversion/pod_example.json @@ -0,0 +1,102 @@ +{ + "kind": "Pod", + "apiVersion": "v1beta3", + "metadata": { + "name": "etcd-server-e2e-test-wojtekt-master", + "namespace": "default", + "selfLink": "/api/v1beta1/pods/etcd-server-e2e-test-wojtekt-master?namespace=default", + "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", + "host": "e2e-test-wojtekt-master", + "hostNetwork": true + }, + "status": { + "phase": "Running", + "Condition": [ + { + "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" + } + ] + } +} diff --git a/pkg/conversion/replication_controller_example.json b/pkg/conversion/replication_controller_example.json new file mode 100644 index 0000000000..8d2b3594ba --- /dev/null +++ b/pkg/conversion/replication_controller_example.json @@ -0,0 +1,82 @@ +{ + "kind": "ReplicationController", + "apiVersion": "v1beta3", + "metadata": { + "name": "elasticsearch-logging-controller", + "namespace": "default", + "selfLink": "/api/v1beta1/replicationControllers/elasticsearch-logging-controller?namespace=default", + "uid": "aa76f162-e8e5-11e4-8fde-42010af09327", + "resourceVersion": "98", + "creationTimestamp": "2015-04-22T11:49:43Z", + "labels": { + "kubernetes.io/cluster-service": "true", + "name": "elasticsearch-logging" + } + }, + "spec": { + "replicas": 1, + "selector": { + "name": "elasticsearch-logging" + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "kubernetes.io/cluster-service": "true", + "name": "elasticsearch-logging" + } + }, + "spec": { + "volumes": [ + { + "name": "es-persistent-storage", + "hostPath": null, + "emptyDir": { + "medium": "" + }, + "gcePersistentDisk": null, + "awsElasticBlockStore": null, + "gitRepo": null, + "secret": null, + "nfs": null, + "iscsi": null, + "glusterfs": null + } + ], + "containers": [ + { + "name": "elasticsearch-logging", + "image": "gcr.io/google_containers/elasticsearch:1.0", + "ports": [ + { + "name": "es-port", + "containerPort": 9200, + "protocol": "TCP" + }, + { + "name": "es-transport-port", + "containerPort": 9300, + "protocol": "TCP" + } + ], + "resources": {}, + "volumeMounts": [ + { + "name": "es-persistent-storage", + "mountPath": "/data" + } + ], + "terminationMessagePath": "/dev/termination-log", + "imagePullPolicy": "IfNotPresent", + "capabilities": {} + } + ], + "restartPolicy": "Always", + "dnsPolicy": "ClusterFirst" + } + } + }, + "status": { + "replicas": 1 + } +} diff --git a/pkg/runtime/scheme.go b/pkg/runtime/scheme.go index b8047c7dc3..2670c0946e 100644 --- a/pkg/runtime/scheme.go +++ b/pkg/runtime/scheme.go @@ -36,6 +36,10 @@ type Scheme struct { // Function to convert a field selector to internal representation. type FieldLabelConversionFunc func(label, value string) (internalLabel, internalValue string, err error) +func (self *Scheme) Raw() *conversion.Scheme { + return self.raw +} + // fromScope gets the input version, desired output version, and desired Scheme // from a conversion.Scope. func (self *Scheme) fromScope(s conversion.Scope) (inVersion, outVersion string, scheme *Scheme) {