2015-04-07 18:21:25 +00:00
|
|
|
/*
|
2016-06-03 00:25:58 +00:00
|
|
|
Copyright 2014 The Kubernetes Authors.
|
2015-04-07 18:21:25 +00:00
|
|
|
|
|
|
|
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 util
|
|
|
|
|
|
|
|
import (
|
2017-01-11 14:09:48 +00:00
|
|
|
"k8s.io/apimachinery/pkg/api/meta"
|
2018-04-27 15:38:34 +00:00
|
|
|
"k8s.io/client-go/dynamic"
|
2017-08-13 17:53:55 +00:00
|
|
|
"k8s.io/client-go/kubernetes"
|
2017-01-19 18:27:59 +00:00
|
|
|
restclient "k8s.io/client-go/rest"
|
2017-09-06 18:34:28 +00:00
|
|
|
"k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi"
|
2018-05-16 14:47:29 +00:00
|
|
|
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
|
2018-05-10 12:20:27 +00:00
|
|
|
"k8s.io/kubernetes/pkg/kubectl/genericclioptions/resource"
|
2017-05-23 17:29:19 +00:00
|
|
|
"k8s.io/kubernetes/pkg/kubectl/validation"
|
2015-04-07 18:21:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Factory provides abstractions that allow the Kubectl command to be extended across multiple types
|
|
|
|
// of resources and different API sets.
|
2017-09-12 03:17:50 +00:00
|
|
|
// The rings are here for a reason. In order for composers to be able to provide alternative factory implementations
|
2016-12-15 18:10:33 +00:00
|
|
|
// they need to provide low level pieces of *certain* functions so that when the factory calls back into itself
|
2017-09-12 03:17:50 +00:00
|
|
|
// it uses the custom version of the function. Rather than try to enumerate everything that someone would want to override
|
|
|
|
// we split the factory into rings, where each ring can depend on methods in an earlier ring, but cannot depend
|
2016-12-15 18:10:33 +00:00
|
|
|
// upon peer methods in its own ring.
|
2015-04-07 18:21:25 +00:00
|
|
|
// TODO: make the functions interfaces
|
|
|
|
// TODO: pass the various interfaces on the factory directly into the command constructors (so the
|
|
|
|
// commands are decoupled from the factory).
|
2016-10-13 00:09:26 +00:00
|
|
|
type Factory interface {
|
2018-05-16 14:47:29 +00:00
|
|
|
genericclioptions.RESTClientGetter
|
2016-12-15 18:10:33 +00:00
|
|
|
|
2018-04-27 15:38:34 +00:00
|
|
|
// DynamicClient returns a dynamic client ready for use
|
2018-05-09 16:58:12 +00:00
|
|
|
DynamicClient() (dynamic.Interface, error)
|
2018-04-27 15:38:34 +00:00
|
|
|
|
2017-08-17 18:48:18 +00:00
|
|
|
// KubernetesClientSet gives you back an external clientset
|
2017-08-13 17:53:55 +00:00
|
|
|
KubernetesClientSet() (*kubernetes.Clientset, error)
|
|
|
|
|
2016-09-07 20:29:57 +00:00
|
|
|
// Returns a RESTClient for accessing Kubernetes resources or an error.
|
2016-10-13 00:09:26 +00:00
|
|
|
RESTClient() (*restclient.RESTClient, error)
|
2016-12-15 18:10:33 +00:00
|
|
|
|
2018-05-09 17:53:07 +00:00
|
|
|
// NewBuilder returns an object that assists in loading objects from both disk and the server
|
|
|
|
// and which implements the common patterns for CLI interactions with generic resources.
|
|
|
|
NewBuilder() *resource.Builder
|
|
|
|
|
2016-12-15 18:10:33 +00:00
|
|
|
// Returns a RESTClient for working with the specified RESTMapping or an error. This is intended
|
|
|
|
// for working with arbitrary resources and is not guaranteed to point to a Kubernetes APIServer.
|
|
|
|
ClientForMapping(mapping *meta.RESTMapping) (resource.RESTClient, error)
|
|
|
|
// Returns a RESTClient for working with Unstructured objects.
|
|
|
|
UnstructuredClientForMapping(mapping *meta.RESTMapping) (resource.RESTClient, error)
|
2016-10-13 00:09:26 +00:00
|
|
|
|
2016-12-15 18:10:33 +00:00
|
|
|
// Returns a schema that can validate objects stored on disk.
|
2017-09-28 22:39:17 +00:00
|
|
|
Validator(validate bool) (validation.Schema, error)
|
2018-02-09 06:53:53 +00:00
|
|
|
// OpenAPISchema returns the schema openapi schema definition
|
2017-08-08 22:00:23 +00:00
|
|
|
OpenAPISchema() (openapi.Resources, error)
|
2015-10-21 14:41:42 +00:00
|
|
|
}
|