github.com/wmuizelaar/kpt@v0.0.0-20221018115725-bd564717b2ed/internal/util/cfgflags/useragent.go (about) 1 // Copyright 2019 Google LLC 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 cfgflags 16 17 import ( 18 "k8s.io/apimachinery/pkg/api/meta" 19 "k8s.io/cli-runtime/pkg/genericclioptions" 20 "k8s.io/client-go/discovery" 21 "k8s.io/client-go/rest" 22 "k8s.io/client-go/tools/clientcmd" 23 ) 24 25 type UserAgentKubeConfigFlags struct { 26 Delegate genericclioptions.RESTClientGetter 27 UserAgent string 28 } 29 30 func (u *UserAgentKubeConfigFlags) ToRESTConfig() (*rest.Config, error) { 31 clientConfig, err := u.Delegate.ToRESTConfig() 32 if err != nil { 33 return nil, err 34 } 35 if u.UserAgent != "" { 36 clientConfig.UserAgent = u.UserAgent 37 } 38 return clientConfig, nil 39 } 40 41 func (u *UserAgentKubeConfigFlags) ToDiscoveryClient() (discovery.CachedDiscoveryInterface, error) { 42 return u.Delegate.ToDiscoveryClient() 43 } 44 45 func (u *UserAgentKubeConfigFlags) ToRESTMapper() (meta.RESTMapper, error) { 46 return u.Delegate.ToRESTMapper() 47 } 48 49 func (u *UserAgentKubeConfigFlags) ToRawKubeConfigLoader() clientcmd.ClientConfig { 50 return u.Delegate.ToRawKubeConfigLoader() 51 }