From abaa46c1159299782c5c72b7e14c9e05edfa209c Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Wed, 28 Nov 2018 23:50:12 -0500 Subject: [PATCH] Support Table and PartialObjectMetadata on watch Clean up the code paths that lead to objects being transformed and output with negotiation. Remove some duplicate code that was not consistent. Now, watch will respond correctly to Table and PartialObjectMetadata requests. Add unit and integration tests. When transforming responses to Tables, only the first watch event for a given type will include the columns. Columns will not change unless the watch is restarted. Add a volume attachment printer and tighten up table validation error cases. Disable protobuf from table conversion because Tables don't have protobuf because they use `interface{}` Kubernetes-commit: 3230a0b4fd14a6166f8362d4732e199e8779c426 --- dynamic/simple.go | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/dynamic/simple.go b/dynamic/simple.go index 852f0c51..65c96dcc 100644 --- a/dynamic/simple.go +++ b/dynamic/simple.go @@ -36,6 +36,19 @@ type dynamicClient struct { var _ Interface = &dynamicClient{} +// ConfigFor returns a copy of the provided config with the +// appropriate dynamic client defaults set. +func ConfigFor(inConfig *rest.Config) *rest.Config { + config := rest.CopyConfig(inConfig) + config.AcceptContentTypes = "application/json" + config.ContentType = "application/json" + config.NegotiatedSerializer = basicNegotiatedSerializer{} // this gets used for discovery and error handling types + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } + return config +} + // NewForConfigOrDie creates a new Interface for the given config and // panics if there is an error in the config. func NewForConfigOrDie(c *rest.Config) Interface { @@ -46,17 +59,12 @@ func NewForConfigOrDie(c *rest.Config) Interface { return ret } +// NewForConfig creates a new dynamic client or returns an error. func NewForConfig(inConfig *rest.Config) (Interface, error) { - config := rest.CopyConfig(inConfig) + config := ConfigFor(inConfig) // for serializing the options config.GroupVersion = &schema.GroupVersion{} config.APIPath = "/if-you-see-this-search-for-the-break" - config.AcceptContentTypes = "application/json" - config.ContentType = "application/json" - config.NegotiatedSerializer = basicNegotiatedSerializer{} // this gets used for discovery and error handling types - if config.UserAgent == "" { - config.UserAgent = rest.DefaultKubernetesUserAgent() - } restClient, err := rest.RESTClientFor(config) if err != nil {