// BuildConfigFromFlags is a helper function that builds configs from a master
// url or a kubeconfig filepath. These are passed in as command line flags for cluster
// components. Warnings should reflect this usage. If neither masterUrl or kubeconfigPath
// are passed in we fallback to inClusterConfig. If inClusterConfig fails, we fallback
// to the default config.
func BuildConfigFromFlags(masterUrl, kubeconfigPath string) (*restclient.Config, error) {
if kubeconfigPath == "" && masterUrl == "" {
glog.Warningf("Neither --kubeconfig nor --master was specified. Using the inClusterConfig. This might not work.")
kubeconfig, err := restclient.InClusterConfig()
if err == nil {
return kubeconfig, nil
}
glog.Warning("error creating inClusterConfig, falling back to default config: ", err)
}
return NewNonInteractiveDeferredLoadingClientConfig(
&ClientConfigLoadingRules{ExplicitPath: kubeconfigPath},
&ConfigOverrides{ClusterInfo: clientcmdapi.Cluster{Server: masterUrl}}).ClientConfig()
}
typeInterfaceinterface {Discovery() discovery.DiscoveryInterfaceAdmissionregistrationV1alpha1() admissionregistrationv1alpha1.AdmissionregistrationV1alpha1Interface// Deprecated: please explicitly pick a version if possible.Admissionregistration() admissionregistrationv1alpha1.AdmissionregistrationV1alpha1InterfaceAppsV1beta1() appsv1beta1.AppsV1beta1InterfaceAppsV1beta2() appsv1beta2.AppsV1beta2Interface// Deprecated: please explicitly pick a version if possible.Apps() appsv1beta2.AppsV1beta2InterfaceAuthenticationV1() authenticationv1.AuthenticationV1Interface// Deprecated: please explicitly pick a version if possible.Authentication() authenticationv1.AuthenticationV1InterfaceAuthenticationV1beta1() authenticationv1beta1.AuthenticationV1beta1InterfaceAuthorizationV1() authorizationv1.AuthorizationV1Interface// Deprecated: please explicitly pick a version if possible.Authorization() authorizationv1.AuthorizationV1InterfaceAuthorizationV1beta1() authorizationv1beta1.AuthorizationV1beta1InterfaceAutoscalingV1() autoscalingv1.AutoscalingV1Interface// Deprecated: please explicitly pick a version if possible.Autoscaling() autoscalingv1.AutoscalingV1InterfaceAutoscalingV2beta1() autoscalingv2beta1.AutoscalingV2beta1InterfaceBatchV1() batchv1.BatchV1Interface// Deprecated: please explicitly pick a version if possible.Batch() batchv1.BatchV1InterfaceBatchV1beta1() batchv1beta1.BatchV1beta1InterfaceBatchV2alpha1() batchv2alpha1.BatchV2alpha1InterfaceCertificatesV1beta1() certificatesv1beta1.CertificatesV1beta1Interface// Deprecated: please explicitly pick a version if possible.Certificates() certificatesv1beta1.CertificatesV1beta1InterfaceCoreV1() corev1.CoreV1Interface// Deprecated: please explicitly pick a version if possible.Core() corev1.CoreV1InterfaceExtensionsV1beta1() extensionsv1beta1.ExtensionsV1beta1Interface// Deprecated: please explicitly pick a version if possible.Extensions() extensionsv1beta1.ExtensionsV1beta1InterfaceNetworkingV1() networkingv1.NetworkingV1Interface// Deprecated: please explicitly pick a version if possible.Networking() networkingv1.NetworkingV1InterfacePolicyV1beta1() policyv1beta1.PolicyV1beta1Interface// Deprecated: please explicitly pick a version if possible.Policy() policyv1beta1.PolicyV1beta1InterfaceRbacV1() rbacv1.RbacV1Interface// Deprecated: please explicitly pick a version if possible.Rbac() rbacv1.RbacV1InterfaceRbacV1beta1() rbacv1beta1.RbacV1beta1InterfaceRbacV1alpha1() rbacv1alpha1.RbacV1alpha1InterfaceSchedulingV1alpha1() schedulingv1alpha1.SchedulingV1alpha1Interface// Deprecated: please explicitly pick a version if possible.Scheduling() schedulingv1alpha1.SchedulingV1alpha1InterfaceSettingsV1alpha1() settingsv1alpha1.SettingsV1alpha1Interface// Deprecated: please explicitly pick a version if possible.Settings() settingsv1alpha1.SettingsV1alpha1InterfaceStorageV1beta1() storagev1beta1.StorageV1beta1InterfaceStorageV1() storagev1.StorageV1Interface// Deprecated: please explicitly pick a version if possible.Storage() storagev1.StorageV1Interface}
// PodsGetter has a method to return a PodInterface.// A group's client should implement this interface.typePodsGetterinterface {Pods(namespace string) PodInterface}
// List takes label and field selectors, and returns the list of Pods that match those selectors.func (c *pods) List(opts meta_v1.ListOptions) (result *v1.PodList, err error) { result =&v1.PodList{} err = c.client.Get().Namespace(c.ns).Resource("pods").VersionedParams(&opts, scheme.ParameterCodec).Do().Into(result)return}
// RESTClientFor returns a RESTClient that satisfies the requested attributes on a client Config// object. Note that a RESTClient may require fields that are optional when initializing a Client.// A RESTClient created by this method is generic - it expects to operate on an API that follows// the Kubernetes conventions, but may not be the Kubernetes API.funcRESTClientFor(config *Config) (*RESTClient, error) {... qps := config.QPS... burst := config.Burst... baseURL, versionedAPIPath, err :=defaultServerUrlFor(config)... transport, err :=TransportFor(config)...var httpClient *http.Clientif transport != http.DefaultTransport { httpClient =&http.Client{Transport: transport}if config.Timeout >0 { httpClient.Timeout = config.Timeout } }returnNewRESTClient(baseURL, versionedAPIPath, config.ContentConfig, qps, burst, config.RateLimiter, httpClient)}
// RESTClient imposes common Kubernetes API conventions on a set of resource paths.// The baseURL is expected to point to an HTTP or HTTPS path that is the parent// of one or more resources. The server should return a decodable API resource// object, or an api.Status object which contains information about the reason for// any failure.//// Most consumers should use client.New() to get a Kubernetes API client.typeRESTClientstruct {// base is the root URL for all invocations of the client base *url.URL// versionedAPIPath is a path segment connecting the base URL to the resource root versionedAPIPath string// contentConfig is the information used to communicate with the server. contentConfig ContentConfig// serializers contain all serializers for underlying content type. serializers Serializers// creates BackoffManager that is passed to requests. createBackoffMgr func() BackoffManager// TODO extract this into a wrapper interface via the RESTClient interface in kubectl. Throttle flowcontrol.RateLimiter// Set specific behavior of the client. If not set http.DefaultClient will be used. Client *http.Client}
// Interface captures the set of operations for generically interacting with Kubernetes REST apis.typeInterfaceinterface {GetRateLimiter() flowcontrol.RateLimiterVerb(verb string) *RequestPost() *RequestPut() *RequestPatch(pt types.PatchType) *RequestGet() *RequestDelete() *RequestAPIVersion() schema.GroupVersion}