github.com/telepresenceio/telepresence/v2@v2.20.0-pro.6.0.20240517030216-236ea954e789/pkg/dnet/borrowed_kubectl_cmdutil.go (about)

     1  /*
     2  MODIFIED: This file is a verbatim subset of kubectl v1.21.2 pkg/cmd/util/kubectl_match_version.go,
     3  MODIFIED: except for lines marked "MODIFIED".
     4  
     5  Copyright 2018 The Kubernetes Authors.
     6  
     7  Licensed under the Apache License, Version 2.0 (the "License");
     8  you may not use this file except in compliance with the License.
     9  You may obtain a copy of the License at
    10  
    11      http://www.apache.org/licenses/LICENSE-2.0
    12  
    13  Unless required by applicable law or agreed to in writing, software
    14  distributed under the License is distributed on an "AS IS" BASIS,
    15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    16  See the License for the specific language governing permissions and
    17  limitations under the License.
    18  */
    19  
    20  package dnet // MODIFIED
    21  
    22  import (
    23  	"k8s.io/apimachinery/pkg/runtime/schema"
    24  	"k8s.io/client-go/rest"
    25  	"k8s.io/kubectl/pkg/scheme"
    26  )
    27  
    28  // setKubernetesDefaults sets default values on the provided client config for accessing the
    29  // Kubernetes API or returns an error if any of the defaults are impossible or invalid.
    30  // TODO this isn't what we want.  Each clientset should be setting defaults as it sees fit.
    31  func setKubernetesDefaults(config *rest.Config) error {
    32  	// TODO remove this hack.  This is allowing the GetOptions to be serialized.
    33  	config.GroupVersion = &schema.GroupVersion{Group: "", Version: "v1"}
    34  
    35  	if config.APIPath == "" {
    36  		config.APIPath = "/api"
    37  	}
    38  	if config.NegotiatedSerializer == nil {
    39  		// This codec factory ensures the resources are not converted. Therefore, resources
    40  		// will not be round-tripped through internal versions. Defaulting does not happen
    41  		// on the client.
    42  		config.NegotiatedSerializer = scheme.Codecs.WithoutConversion()
    43  	}
    44  	return rest.SetKubernetesDefaults(config)
    45  }