Commit Graph

318 Commits (8dac9639e4a9aa84f7223e5781dc79de6099e5b6)

Author SHA1 Message Date
Clayton Coleman ce57455de6
Allow objects to serialize their nested objects
Introduce an optional interface for callers to encode themselves.
2016-08-18 14:45:01 -04:00
Clayton Coleman 12a5eeea17
Introduce GroupVersioner for capturing desired target version
Convert single GV and lists of GVs into an interface that can handle
more complex scenarios (everything internal, nothing supported). Pass
the interface down into conversion.
2016-08-18 14:45:00 -04:00
Kris 361f13ddf0 Add JSON encoding handlers to unstructured objects 2016-08-15 22:07:53 -07:00
Kris 69e0740b93 Properly decode lists into VersionedObjects 2016-08-15 14:18:40 -07:00
Daniel Smith f1fd638962 fix register.go files up + add test import 2016-08-11 17:06:54 -07:00
Daniel Smith caed8d85f4 add scheme builder 2016-08-11 13:18:26 -07:00
Timothy St. Clair 24993b0343 Update generated files due to dependency shift.
Also minor bug fix in federation api.
2016-08-09 10:41:09 -05:00
Chao Xu 4d2350632c only store typeMeta and objectMeta in the gc store 2016-08-08 17:23:13 -07:00
pweil- f51c1301f2 add asserts for RecognizingDecoder and update protobuf serializer to implement interface 2016-08-03 17:26:31 -04:00
k8s-merge-robot fa174bcdaf Merge pull request #29042 from dims/fixup-imports
Automatic merge from submit-queue

Use Go canonical import paths

Add canonical imports only in existing doc.go files.
https://golang.org/doc/go1.4#canonicalimports

Fixes #29014
2016-07-18 07:23:38 -07:00
Davanum Srinivas 2b0ed014b7 Use Go canonical import paths
Add canonical imports only in existing doc.go files.
https://golang.org/doc/go1.4#canonicalimports

Fixes #29014
2016-07-16 13:48:21 -04:00
Tim Hockin 3384e03920 Commit generated files
There's been enough people broken by not committing generated code, that we
should undo that until we have a proper client that is `go get` compatible.

This is temporary.
2016-07-15 10:27:51 -07:00
k8s-merge-robot 0af6d321e8 Merge pull request #28935 from smarterclayton/avoid_double_encode
Automatic merge from submit-queue

Don't double encode protobuf runtime.Unknown

When using runtime.Object and runtime.RawExtension, passing
runtime.Unknown to protobuf serializer should result in the raw message
being serialized (since all normal protobuf objects are
runtime.Unknown).

Also, avoid setting a content-type when decoding a protobuf object
except when the content appears to be proto.

@wojtek-t
2016-07-15 07:43:09 -07:00
Clayton Coleman b9845e7cb5
Don't double encode protobuf runtime.Unknown
When using runtime.Object and runtime.RawExtension, passing
runtime.Unknown to protobuf serializer should result in the raw message
being serialized (since all normal protobuf objects are
runtime.Unknown).

Also, avoid setting a content-type when decoding a protobuf object
except when the content appears to be proto.
2016-07-14 13:09:16 -04:00
Clayton Coleman 866e788aba
generate: New Stringers 2016-07-14 12:43:36 -04:00
k8s-merge-robot ae990defcf Merge pull request #26956 from joe2far/fix-typos
Automatic merge from submit-queue

Fixed several typos
2016-07-14 04:13:15 -07:00
Michael Taufen d3f3bedbb7 Fix typo in pkg/runtime/serializer/codec_factory.go 2016-07-13 10:41:02 -07:00
joe2far 5ead89b5bb Fixed several typos 2016-07-13 15:06:24 +01:00
Tim Hockin 58441e8775 Don't check in generated deep-copy code
This mostly takes the previously checked in files and removes them, and moves
the generation to be on-demand instead of manual.  Manually verified no change
in generated output.
2016-07-12 21:52:54 -07:00
Dr. Stefan Schimanski 629b25daf9 Run hack/update-all.sh 2016-07-12 20:36:48 +02:00
Dr. Stefan Schimanski 61cde63622 Switch to typeless generated deepcopy functions for less reflection 2016-07-12 18:05:43 +02:00
Tim Hockin 51394e862d Make runtime opt in to deepcopy
This minimizes the number of functions generated.  It also breaks the chain of
symbol dependencies to pkg/conversion, so we can remove now-unreferenced
(previously unused but referenced) conversion deep-copies.
2016-07-07 16:49:46 -07:00
Tim Hockin dc10f10e48 Recreate the opt-in/opt-out logic for deepcopy
This is the last piece of Clayton's #26179 to be implemented with file tags.
All diffs are accounted for.  Followup will use this to streamline some
packages.

Also add some V(5) debugging - it was helpful in diagnosing various issues, it
may be helpful again.
2016-07-07 16:49:46 -07:00
Tim Hockin 28af54138d Use file tags to generate deep-copies
This drives most of the logic of deep-copy generation from tags like:
  // +deepcopy-gen=package
..rather than hardcoded lists of packages.  This will make it possible to
subsequently generate code ONLY for packages that need it *right now*, rather
than all of them always.

Also remove pkgs that really do not need deep-copies (no symbols used
anywhere).
2016-07-07 16:49:46 -07:00
Tim Hockin e18b2f3a2e Revert Clayton's #26179 so I can recreate it
His PR cam during the middle of this development cycle, and it was easier to
burn it down and recreate it than try to patch it into an existing series and
re-test every assumption.  This behavior will be re-introduced in subsequent
commits.
2016-07-07 16:49:46 -07:00
David McMahon ef0c9f0c5b Remove "All rights reserved" from all the headers. 2016-06-29 17:47:36 -07:00
Clayton Coleman 36a5ffbe2f
Remove EncodeToStream(..., []unversioned.GroupVersion)
Was not being used.
2016-06-10 18:43:12 -04:00
Clayton Coleman e1dc3ef933
Remove unused deep_copies 2016-06-06 17:18:22 -04:00
Clayton Coleman 0181ac61da
DeepCopy should only generate types in k8s.io/kubernetes
Also make generation more selective (require opt in) to prevent lots of
unnecessary generated deep copies.
2016-06-06 17:18:22 -04:00
k8s-merge-robot cf234ab67d Merge pull request #26251 from caesarxuchao/add-serializer
Automatic merge from submit-queue

Add direct serializer

Fix #25589. Implemented a direct codec that doesn't do conversion, but sets the group, version and kind before serialization as Clayton suggested [here](https://github.com/kubernetes/kubernetes/issues/25589#issuecomment-219168009).

First commit is cherry-picked from #24826.

@kubernetes/sig-api-machinery
2016-06-01 23:31:47 -07:00
gmarek 778b1df717 Add Controller to api/meta 2016-05-31 20:21:05 +02:00
Chao Xu f32f3966d6 add DirectCodec; use it in release_1_3 clientset 2016-05-31 10:14:24 -07:00
k8s-merge-robot 14a6fb7d0f Merge pull request #26018 from gyuho/slice_append
Automatic merge from submit-queue

pkg/runtime: preallocate slice in unstructured.go
2016-05-29 07:20:50 -07:00
k8s-merge-robot e543bd6452 Merge pull request #26007 from smarterclayton/watch_opt
Automatic merge from submit-queue

Additional optimizations to the encode/decode paths

Builds on top of #25983 with a number of other optimizations.
2016-05-28 06:27:00 -07:00
Gyu-Ho Lee c3fc714ec2 pkg/runtime: preallocate slice in unstructured.go
To avoid slice growth when appending.
2016-05-27 14:54:25 -07:00
Chao Xu 1665546d2d add finalizer logics to the API server and the garbage collector; handling DeleteOptions.OrphanDependents in the API server 2016-05-24 13:07:28 -07:00
Clayton Coleman c6961d6fd6
Remove runtime.Typer, reduce to ObjectKinds(1) (3)
Remove the unnecessary variants, which avoids allocations in several
core paths.
2016-05-21 23:55:42 -04:00
Clayton Coleman a9c3edc613
Avoid allocating an array for EncodeToVersion 2016-05-21 23:55:41 -04:00
k8s-merge-robot c05c1d24ae Merge pull request #25540 from krousey/discovery_mapper
Automatic merge from submit-queue

Adding support objects for integrating dynamic client the kubectl builder

Kubectl will try to decode into `runtime.VersionedObjects`, so the `UnstructuredJSONScheme` needs to handle that intelligently.

Kubectl's builder also needs a `meta.RESTMapper` and `runtime.Typer`. The `meta.RESTMapper` requires a `runtime.ObjectConvertor` (spelling?) that works with `runtime.Unstructured`. The mapper and typer required discovery info, so I just put that in the kubectl util package since it didn't really seem to fit anywhere else. 

Subsequent PRs will be using these in kubectl.

cc @kubernetes/sig-api-machinery @smarterclayton @liggitt @lavalamp
2016-05-21 07:13:49 -07:00
Kris db515f47bd Provide a dumb ObjectConverter for Unstructured 2016-05-16 12:43:39 -07:00
Chao Xu c73406bcfe the garbage collector controller 2016-05-15 16:04:19 -07:00
Kris 6cd2fa6b42 Make unstructured scheme aware of VersionedObjects
UnstructuredJSONScheme now handles decoding into VersionedObjects
properly by decoding into Unstructured and putting it in the object list.
2016-05-13 14:04:39 -07:00
Jeff Lowdermilk 1616239b4a Merge pull request #25436 from smarterclayton/defend_proto
Add a defensive sanity check to protobuf marshal
2016-05-13 10:45:58 -07:00
Clayton Coleman ea7e7a18cb
Create a new method UnsafeConvertToVersion for faster convert
Only encode/decode will call this path, to allow us to optimize for
unsafe operations.
2016-05-12 10:10:35 -04:00
Clayton Coleman 51b624103f
Change ConvertToVersion to use GroupVersion
Long delayed refactor, avoids a few more allocations.
2016-05-12 10:10:35 -04:00
Clayton Coleman a84e62d9e6
Change ObjectKind signature to avoid allocations
We don't need to pass a pointer into SetGroupKindVersion() - a
struct works just as well.
2016-05-12 10:10:35 -04:00
Clayton Coleman bffbc112f0
Remove src and dest version - they are not used (now)
We will probably readd these as an opaque object passed down to
conversions that lets the caller get access to more info (like
a negotiated serializer).
2016-05-12 10:10:35 -04:00
Ed Robinson afdbad078a
Corrects some misspellings in comments
This should help to make
https://goreportcard.com/report/k8s.io/kubernetes#misspell
look a little nicer.
2016-05-11 08:16:13 +01:00
Clayton Coleman eea748b14f
Add a defensive sanity check to protobuf marshal
This prevents programmer error from resulting in objects serialized to
the wire that are incorrectly designed. The normal path guards against
this, but the runtime.Unknown NestedMarshalTo fast path (which avoids an
allocation) doesn't have the same defensive guard.
2016-05-10 18:58:59 -04:00
k8s-merge-robot c0b788bf49 Merge pull request #24727 from smarterclayton/fast_path_lookup
Automatic merge from submit-queue

Avoid allocations and a reflect.Call in conversion

reflect.Call is fairly expensive, performing 8 allocations and having to
set up a call stack. Using a fairly straightforward to generate switch
statement, we can bypass that early in conversion (as long as the
function takes responsibility for invocation). We may also be able to
avoid an allocation for the conversion scope, but not positive yet.

```
benchmark                    old ns/op     new ns/op     delta
BenchmarkPodConversion-8     14713         12173         -17.26%

benchmark                    old allocs     new allocs     delta
BenchmarkPodConversion-8     80             72             -10.00%

benchmark                    old bytes     new bytes     delta
BenchmarkPodConversion-8     9133          8712          -4.61%
```

@wojtek-t related to #20309
2016-05-06 07:10:18 -07:00
Clayton Coleman e0ebcf4216
Split the storage and negotiation parts of Codecs
The codec factory should support two distinct interfaces - negotiating
for a serializer with a client, vs reading or writing data to a storage
form (etcd, disk, etc). Make the EncodeForVersion and DecodeToVersion
methods only take Encoder and Decoder, and slight refactoring elsewhere.

In the storage factory, use a content type to control what serializer to
pick, and use the universal deserializer. This ensures that storage can
read JSON (which might be from older objects) while only writing
protobuf. Add exceptions for those resources that may not be able to
write to protobuf (specifically third party resources, but potentially
others in the future).
2016-05-05 12:08:23 -04:00
Clayton Coleman 4ad5565c41
RecognizingDecoder didn't handle ambiguous input
YAML is not guaranteed to be recognizable, so we need to bump JSON and
protobuf above it in the decoding order. Add a unit test.
2016-05-05 12:08:22 -04:00
k8s-merge-robot 93e3df8e55 Merge pull request #24789 from wojtek-t/use_proper_codec_in_client
Automatic merge from submit-queue

Use proper codec in client
2016-05-04 11:00:04 -07:00
k8s-merge-robot bc010d76cc Merge pull request #24751 from krousey/meta_unstructured
Automatic merge from submit-queue

Redo Unstructured to have accessor methods

Add accessor methods that implement pkg/api/unversioned.ObjectKind,
pkg/api/meta.Object, pkg/api/meta.Type and pkg/api/meta.List.

Removed the convenience fields since writing to them was not reflected
in serialized JSON.
2016-05-04 04:22:34 -07:00
Wojciech Tyczynski 303742ce12 Merge pull request #24723 from smarterclayton/strip_noop_imports
Protobuf generation should strip side-effect imports
2016-05-04 11:16:45 +02:00
Wojciech Tyczynski 3aadafd411 Use NegotiatedSerializer in client 2016-05-04 10:57:36 +02:00
Kris 28132be07e Redo Unstructured to have accessor methods
Add accessor methods that implement pkg/api/unversioned.ObjectKind,
pkg/api/meta.Object, pkg/api/meta.Type and pkg/api/meta.List.

Removed the convenience fields since writing to them was not reflected
in serialized JSON.
2016-05-03 14:07:28 -07:00
Clayton Coleman 99430cf5de
Strip side-effect imports from generated protobuf 2016-05-02 18:12:20 -04:00
Clayton Coleman 84dee0d9cc
Frame decoder was checking cap(), not len()
Resulted in bytes being missing from the streaming decoder. Update both
parts.
2016-04-30 17:57:17 -04:00
Wojciech Tyczynski 3175d18b14 Support Close() in streaming decoder 2016-04-28 09:46:33 +02:00
Clayton Coleman 236925be87
Avoid allocations and a reflect.Call in conversion
reflect.Call is fairly expensive, performing 8 allocations and having to
set up a call stack. Using a fairly straightforward to generate switch
statement, we can bypass that early in conversion (as long as the
function takes responsibility for invocation). We may also be able to
avoid an allocation for the conversion scope, but not positive yet.

```
benchmark                    old ns/op     new ns/op     delta
BenchmarkPodConversion-8     14713         12173         -17.26%

benchmark                    old allocs     new allocs     delta
BenchmarkPodConversion-8     80             72             -10.00%

benchmark                    old bytes     new bytes     delta
BenchmarkPodConversion-8     9133          8712          -4.61%
```
2016-04-26 16:42:12 -04:00
Wojciech Tyczynski c0020aff59 Merge pull request #24539 from smarterclayton/unify_stream_and_serial
Unify Streaming and normal Serializers
2016-04-25 11:25:16 +02:00
Clayton Coleman 668fae253f Generated spec and docs 2016-04-22 11:07:33 -04:00
Clayton Coleman 3111985564 Handle streaming serializers more consistently
Add tests to watch behavior in both protocols (http and websocket)
against all 3 media types. Adopt the
`application/vnd.kubernetes.protobuf;stream=watch` media type for the
content that comes back from a watch call so that it can be
distinguished from a Status result.
2016-04-22 11:07:24 -04:00
goltermann dddc6cb6c8 Fix a few spellings. 2016-04-21 15:16:42 -07:00
Clayton Coleman e16a7f2421 Initial protobuf generated files 2016-04-20 12:13:05 -04:00
Clayton Coleman cea4c010a6 Strip the proto build guard 2016-04-20 12:12:29 -04:00
Wojciech Tyczynski 89e860e622 Remove old conversion generator 2016-04-15 12:07:57 +02:00
k8s-merge-robot f5e8e7453b Merge pull request #23806 from smarterclayton/streaming_watch
Automatic merge from submit-queue

Implement a streaming serializer for watch

Changeover watch to use streaming serialization. Properly version the
watch objects. Implement simple framing for JSON and Protobuf (but not
YAML).

@wojtek-t @lavalamp
2016-04-13 05:18:17 -07:00
k8s-merge-robot fcddb9cba5 Merge pull request #16964 from liggitt/json_precision
Automatic merge from submit-queue

Preserve int data when unmarshaling

There are several places we use `json.Unmarshal` into an unstructured map (StrategicMergePatch, UnstructuredJSONScheme, many others).

In this scenario, the json package converts all numbers to float64. This exposes many of the int64 fields in our API types to corruption when the unstructured map is marshalled back to json.

A simple example is a pod with an `"activeDeadlineSeconds": 1000000`. Trying to use `kubectl label`, `annotate`, `patch`, etc results in that int64 being converted to a float64, submitted to the server, and the server rejecting it with an error about "cannot unmarshal number 1e+6 into Go value of type int64"

The json package provides a way to defer conversion of numbers (`json.Decoder#UseNumber`), but does not actually do conversions to int or float. This PR makes use of that feature, and post-processes the unmarshalled map to convert json.Number objects to either int64 or float64 values
2016-04-12 07:09:32 -07:00
k8s-merge-robot acf9492cb1 Merge pull request #23660 from goltermann/vetclean
Automatic merge from submit-queue

Additional go vet fixes

Mostly:
- pass lock by value
- bad syntax for struct tag value
- example functions not formatted properly
2016-04-12 06:22:16 -07:00
Jordan Liggitt 37c86041ca Preserve int64 data when patching 2016-04-11 16:23:28 -04:00
Clayton Coleman 3474911736 Implement a streaming serializer for watch
Changeover watch to use streaming serialization. Properly version the
watch objects. Implement simple framing for JSON and Protobuf (but not
YAML).
2016-04-11 11:22:05 -04:00
Clayton Coleman 87146c4255 Fix compilation errors in protobuf and add decode test 2016-04-11 11:22:04 -04:00
Clayton Coleman bfc991646b Implement correct and memory safe framing and add tests 2016-04-11 11:22:04 -04:00
goltermann 696423e044 Vet fixes, mostly pass lock by value errors. 2016-04-06 11:27:40 -07:00
Wojciech Tyczynski 49d3c3962c Small improvements in conversion generator 2016-04-05 02:10:23 +02:00
k8s-merge-robot d807690c39 Merge pull request #23387 from hongchaodeng/e
Automatic merge from submit-queue

storage.Interface KV impl. of etcd v3

This is the initial implementation of #22448.

The PR consists of two parts:
- add godep of "clientv3" and "integration" (for testing)
- create new package "etcd3" under "pkg/storage/"
- implement KV methods of storage.Interface using etcd v3 APIs
  - Create, Set, Get, Delete, GetToList, List, GuaranteedUpdate
2016-03-31 11:46:43 -07:00
Clayton Coleman f2139b186c Add an experimental protobuf serializer
Provide a core protobuf serializer that can either write objects with
an envelope (a 4 byte prefix and a runtime.Object) or raw to a byte
array.
2016-03-31 10:41:11 -04:00
Hongchao Deng 00ddf0671d etcd (v3) store: implements KV methods of storage.Interface
This implements Get(), Create(), Delete(), GetToList(),
List(), GuaranteedUpdate().
2016-03-30 10:20:39 -07:00
k8s-merge-robot 1ad3049ed6 Merge pull request #23288 from smarterclayton/refactor_codec
Auto commit by PR queue bot
2016-03-26 10:47:58 -07:00
goltermann 32d569d6c7 Fixing all the "composite literal uses unkeyed fields" Vet errors. 2016-03-25 15:25:09 -07:00
k8s-merge-robot 4e4ad61260 Merge pull request #23366 from goltermann/vet
Auto commit by PR queue bot
2016-03-24 21:50:56 -07:00
k8s-merge-robot 8355cefb7b Merge pull request #23373 from wojtek-t/conversions_with_framework_3
Auto commit by PR queue bot
2016-03-24 01:39:23 -07:00
Wojciech Tyczynski 42e7ecda5a Fix bunch of issues with conversion generator. 2016-03-24 08:26:51 +01:00
Clayton Coleman 54eaa56b92 Add a streaming and "raw" abstraction to codec factory 2016-03-23 17:25:20 -04:00
k8s-merge-robot 4a6e6b3fbf Merge pull request #23213 from pweil-/generator-besteffort
Auto commit by PR queue bot
2016-03-23 07:50:09 -07:00
goltermann 34d4eaea08 Fixing several (but not all) go vet errors. Most are around string formatting, or unreachable code. 2016-03-22 17:26:50 -07:00
Paul Weil dd4ff1690d provide best effort generation even if types are asymmetrical 2016-03-22 11:44:07 -04:00
harry b0900bf0d4 Refactor diff into sub pkg 2016-03-21 20:21:39 +08:00
k8s-merge-robot 8fb0bfb0d3 Merge pull request #23179 from wojtek-t/remove_old_deep_copy_generator
Auto commit by PR queue bot
2016-03-18 19:35:54 -07:00
Wojciech Tyczynski 89585237cd Rename RawJSON to Raw in runtime.RawExtension and add ContentType & ContentEncoding. 2016-03-18 12:35:27 +01:00
Wojciech Tyczynski ce9b2ab3e3 Remove old deep-copy generator. 2016-03-18 09:42:15 +01:00
Wojciech Tyczynski 7e2fdeae7b Regenerate autogenerate files 2016-03-17 15:22:19 +01:00
k8s-merge-robot 53c6b35b71 Merge pull request #23038 from wojtek-t/rename_raw_json_to_raw
Auto commit by PR queue bot
2016-03-17 04:05:43 -07:00
Wojciech Tyczynski e610c137c0 Regenerate auto-generated files 2016-03-17 09:30:02 +01:00
Wojciech Tyczynski 218d3e5923 Rename RawJSON to Raw in runtime.Unknown and add ContentType & ContentEncoding. 2016-03-16 16:43:58 +01:00
Wojciech Tyczynski b264805796 JSON serializer implements serializer interface 2016-03-10 13:26:05 +01:00
Clayton Coleman f5c7f297b3 Set runtime OWNERS 2016-03-04 23:59:34 -05:00
k8s-merge-robot c3a962bff5 Merge pull request #20351 from krousey/dynamic_client
Auto commit by PR queue bot
2016-02-19 10:00:54 -08:00