...

Source file src/k8s.io/cli-runtime/pkg/resource/client.go

Documentation: k8s.io/cli-runtime/pkg/resource

     1  /*
     2  Copyright 2018 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 resource
    18  
    19  import (
    20  	"k8s.io/apimachinery/pkg/runtime"
    21  	"k8s.io/apimachinery/pkg/runtime/schema"
    22  	"k8s.io/client-go/rest"
    23  )
    24  
    25  // TODO require negotiatedSerializer.  leaving it optional lets us plumb current behavior and deal with the difference after major plumbing is complete
    26  func (clientConfigFn ClientConfigFunc) clientForGroupVersion(gv schema.GroupVersion, negotiatedSerializer runtime.NegotiatedSerializer) (RESTClient, error) {
    27  	cfg, err := clientConfigFn()
    28  	if err != nil {
    29  		return nil, err
    30  	}
    31  	if negotiatedSerializer != nil {
    32  		cfg.ContentConfig.NegotiatedSerializer = negotiatedSerializer
    33  	}
    34  	cfg.GroupVersion = &gv
    35  	if len(gv.Group) == 0 {
    36  		cfg.APIPath = "/api"
    37  	} else {
    38  		cfg.APIPath = "/apis"
    39  	}
    40  
    41  	return rest.RESTClientFor(cfg)
    42  }
    43  
    44  func (clientConfigFn ClientConfigFunc) unstructuredClientForGroupVersion(gv schema.GroupVersion) (RESTClient, error) {
    45  	cfg, err := clientConfigFn()
    46  	if err != nil {
    47  		return nil, err
    48  	}
    49  	cfg.ContentConfig = UnstructuredPlusDefaultContentConfig()
    50  	cfg.GroupVersion = &gv
    51  	if len(gv.Group) == 0 {
    52  		cfg.APIPath = "/api"
    53  	} else {
    54  		cfg.APIPath = "/apis"
    55  	}
    56  
    57  	return rest.RESTClientFor(cfg)
    58  }
    59  
    60  func (clientConfigFn ClientConfigFunc) withStdinUnavailable(stdinUnavailable bool) ClientConfigFunc {
    61  	return func() (*rest.Config, error) {
    62  		cfg, err := clientConfigFn()
    63  		if stdinUnavailable && cfg != nil && cfg.ExecProvider != nil {
    64  			cfg.ExecProvider.StdinUnavailable = stdinUnavailable
    65  			cfg.ExecProvider.StdinUnavailableMessage = "used by stdin resource manifest reader"
    66  		}
    67  		return cfg, err
    68  	}
    69  }
    70  

View as plain text