[WIP] Add support for applying a Config with set of resources via kubecfg

Discussion: https://github.com/GoogleCloudPlatform/kubernetes/issues/1905


----- Original Message -----
> > +
> > +type ApplyResult struct {
> > +	Error   error
> > +	Message string
> > +}
> > +
> > +// Apply creates and manages resources defined in the Config. The create
> > process wont
> > +// stop on error, but it will finish the job and then return error and for
> > each item
> > +// in the config a error and status message string.
> > +func Apply(data []byte, storage ClientMappings) (result []ApplyResult, err
> > error) {
> > +	// Unmarshal the Config JSON manually instead of using runtime.Decode()
> > +	conf := struct {
> > +		Items []json.RawMessage `json:"items" yaml:"items"`
> > +	}{}
> > +
> > +	if err := json.Unmarshal(data, &conf); err != nil {
> 
> data is the raw file? Given that we're going to want to collect objects from
> whole directories, etc., it seems like we should break this down into
> multiple passes:

Agree

> 1. Find and read files (perhaps traversing directories, applying file
> selection filters, etc.)
> 2. Parse and validate JSON objects (we shouldn't be validating on the fly
> while creating)

Our validations today are dependent on client code having the same validations on the client as on the server.  If the client version drifts, the server having to validate is inevitable.  Also, what if the server has relaxed a validation that the client still enforces (maybe you can argue you should force an upgrade)?  Seems like client is informative, server is authoritative.

> 3. Perform final JSON transformations, if necessary (e.g., name/label
> munging)
> 4. Perform desired operation (see #1702 for more details), such as:
>     1. Dump JSON objects
>     2. Get JSON objects and diff
>     3. Create objects
>     4. Update objects
> 
> ---
> Reply to this email directly or view it on GitHub:
> https://github.com/GoogleCloudPlatform/kubernetes/pull/1958/files#r19258407