...

Source file src/k8s.io/kubectl/pkg/cmd/util/factory.go

Documentation: k8s.io/kubectl/pkg/cmd/util

     1  /*
     2  Copyright 2014 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package util
    18  
    19  import (
    20  	"k8s.io/apimachinery/pkg/api/meta"
    21  	"k8s.io/cli-runtime/pkg/genericclioptions"
    22  	"k8s.io/cli-runtime/pkg/resource"
    23  	"k8s.io/client-go/dynamic"
    24  	"k8s.io/client-go/kubernetes"
    25  	openapiclient "k8s.io/client-go/openapi"
    26  	restclient "k8s.io/client-go/rest"
    27  	"k8s.io/kubectl/pkg/util/openapi"
    28  	"k8s.io/kubectl/pkg/validation"
    29  )
    30  
    31  // Factory provides abstractions that allow the Kubectl command to be extended across multiple types
    32  // of resources and different API sets.
    33  // The rings are here for a reason. In order for composers to be able to provide alternative factory implementations
    34  // they need to provide low level pieces of *certain* functions so that when the factory calls back into itself
    35  // it uses the custom version of the function. Rather than try to enumerate everything that someone would want to override
    36  // we split the factory into rings, where each ring can depend on methods in an earlier ring, but cannot depend
    37  // upon peer methods in its own ring.
    38  // TODO: make the functions interfaces
    39  // TODO: pass the various interfaces on the factory directly into the command constructors (so the
    40  // commands are decoupled from the factory).
    41  type Factory interface {
    42  	genericclioptions.RESTClientGetter
    43  
    44  	// DynamicClient returns a dynamic client ready for use
    45  	DynamicClient() (dynamic.Interface, error)
    46  
    47  	// KubernetesClientSet gives you back an external clientset
    48  	KubernetesClientSet() (*kubernetes.Clientset, error)
    49  
    50  	// Returns a RESTClient for accessing Kubernetes resources or an error.
    51  	RESTClient() (*restclient.RESTClient, error)
    52  
    53  	// NewBuilder returns an object that assists in loading objects from both disk and the server
    54  	// and which implements the common patterns for CLI interactions with generic resources.
    55  	NewBuilder() *resource.Builder
    56  
    57  	// Returns a RESTClient for working with the specified RESTMapping or an error. This is intended
    58  	// for working with arbitrary resources and is not guaranteed to point to a Kubernetes APIServer.
    59  	ClientForMapping(mapping *meta.RESTMapping) (resource.RESTClient, error)
    60  	// Returns a RESTClient for working with Unstructured objects.
    61  	UnstructuredClientForMapping(mapping *meta.RESTMapping) (resource.RESTClient, error)
    62  
    63  	// Returns a schema that can validate objects stored on disk.
    64  	Validator(validationDirective string) (validation.Schema, error)
    65  
    66  	// Used for retrieving openapi v2 resources.
    67  	openapi.OpenAPIResourcesGetter
    68  
    69  	// OpenAPIV3Schema returns a client for fetching parsed schemas for
    70  	// any group version
    71  	OpenAPIV3Client() (openapiclient.Client, error)
    72  }
    73  

View as plain text