istio.io/istio@v0.0.0-20240520182934-d79c90f27776/istioctl/pkg/cli/kubectl_factory.go (about)

     1  // Copyright Istio Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package cli
    16  
    17  import (
    18  	"k8s.io/apimachinery/pkg/api/meta"
    19  	"k8s.io/cli-runtime/pkg/resource"
    20  	openapiclient "k8s.io/client-go/openapi"
    21  	"k8s.io/kubectl/pkg/cmd/util"
    22  	"k8s.io/kubectl/pkg/util/openapi"
    23  	"k8s.io/kubectl/pkg/validation"
    24  
    25  	"istio.io/istio/pkg/kube"
    26  )
    27  
    28  type Factory struct {
    29  	kube.PartialFactory
    30  	full util.Factory
    31  }
    32  
    33  func (f Factory) NewBuilder() *resource.Builder {
    34  	return f.full.NewBuilder()
    35  }
    36  
    37  func (f Factory) ClientForMapping(mapping *meta.RESTMapping) (resource.RESTClient, error) {
    38  	return f.full.ClientForMapping(mapping)
    39  }
    40  
    41  func (f Factory) UnstructuredClientForMapping(mapping *meta.RESTMapping) (resource.RESTClient, error) {
    42  	return f.full.UnstructuredClientForMapping(mapping)
    43  }
    44  
    45  func (f Factory) Validator(validationDirective string) (validation.Schema, error) {
    46  	return f.full.Validator(validationDirective)
    47  }
    48  
    49  func (f Factory) OpenAPISchema() (openapi.Resources, error) {
    50  	return f.full.OpenAPISchema()
    51  }
    52  
    53  func (f Factory) OpenAPIV3Client() (openapiclient.Client, error) {
    54  	return f.full.OpenAPIV3Client()
    55  }
    56  
    57  var _ util.Factory = Factory{}
    58  
    59  // MakeKubeFactory turns a partial kubetl factory from CLIClient into a full util.Factory
    60  // This is done under istioctl/ to avoid excessive binary bloat in other packages; this pulls in around 10mb of
    61  // dependencies.
    62  var MakeKubeFactory = func(k kube.CLIClient) util.Factory {
    63  	kf := k.UtilFactory()
    64  	return Factory{
    65  		PartialFactory: kf,
    66  		full:           util.NewFactory(kf),
    67  	}
    68  }