本文整理汇总了Golang中github.com/GoogleCloudPlatform/kubernetes/pkg/client.Config.Version方法的典型用法代码示例。如果您正苦于以下问题:Golang Config.Version方法的具体用法?Golang Config.Version怎么用?Golang Config.Version使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/GoogleCloudPlatform/kubernetes/pkg/client.Config
的用法示例。
在下文中一共展示了Config.Version方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SetOpenShiftDefaults
// SetOpenShiftDefaults sets the default settings on the passed
// client configuration
func SetOpenShiftDefaults(config *kclient.Config) error {
if len(config.UserAgent) == 0 {
config.UserAgent = DefaultOpenShiftUserAgent()
}
if config.Version == "" {
// Clients default to the preferred code API version
// TODO: implement version negotiation (highest version supported by server)
config.Version = latest.Version
}
if config.Prefix == "" {
switch config.Version {
case "v1beta3":
config.Prefix = "/osapi"
default:
config.Prefix = "/oapi"
}
}
version := config.Version
versionInterfaces, err := latest.InterfacesFor(version)
if err != nil {
return fmt.Errorf("API version '%s' is not recognized (valid values: %s)", version, strings.Join(latest.Versions, ", "))
}
if config.Codec == nil {
config.Codec = versionInterfaces.Codec
}
return nil
}
示例2: CreateKubeSources
func CreateKubeSources(uri *url.URL, c cache.Cache) ([]api.Source, error) {
var (
kubeConfig *kube_client.Config
err error
)
opts := uri.Query()
configOverrides, err := getConfigOverrides(uri)
if err != nil {
return nil, err
}
inClusterConfig := defaultInClusterConfig
if len(opts["inClusterConfig"]) > 0 {
inClusterConfig, err = strconv.ParseBool(opts["inClusterConfig"][0])
if err != nil {
return nil, err
}
}
if inClusterConfig {
kubeConfig, err = kube_client.InClusterConfig()
if err != nil {
return nil, err
}
if configOverrides.ClusterInfo.Server != "" {
kubeConfig.Host = configOverrides.ClusterInfo.Server
}
kubeConfig.Version = configOverrides.ClusterInfo.APIVersion
} else {
authFile := ""
if len(opts["auth"]) > 0 {
authFile = opts["auth"][0]
}
if authFile != "" {
if kubeConfig, err = kubeClientCmd.NewNonInteractiveDeferredLoadingClientConfig(
&kubeClientCmd.ClientConfigLoadingRules{ExplicitPath: authFile},
configOverrides).ClientConfig(); err != nil {
return nil, err
}
} else {
kubeConfig = &kube_client.Config{
Host: configOverrides.ClusterInfo.Server,
Version: configOverrides.ClusterInfo.APIVersion,
Insecure: configOverrides.ClusterInfo.InsecureSkipTLSVerify,
}
}
}
if len(kubeConfig.Host) == 0 {
return nil, fmt.Errorf("invalid kubernetes master url specified")
}
if len(kubeConfig.Version) == 0 {
return nil, fmt.Errorf("invalid kubernetes API version specified")
}
useServiceAccount := defaultUseServiceAccount
if len(opts["useServiceAccount"]) >= 1 {
useServiceAccount, err = strconv.ParseBool(opts["useServiceAccount"][0])
if err != nil {
return nil, err
}
}
if useServiceAccount {
// If a readable service account token exists, then use it
if contents, err := ioutil.ReadFile(defaultServiceAccountFile); err == nil {
kubeConfig.BearerToken = string(contents)
}
}
kubeClient := kube_client.NewOrDie(kubeConfig)
nodesApi, err := nodes.NewKubeNodes(kubeClient)
if err != nil {
return nil, err
}
kubeletPort := defaultKubeletPort
if len(opts["kubeletPort"]) >= 1 {
kubeletPort, err = strconv.Atoi(opts["kubeletPort"][0])
if err != nil {
return nil, err
}
}
kubeletHttps := defaultKubeletHttps
if len(opts["kubeletHttps"]) >= 1 {
kubeletHttps, err = strconv.ParseBool(opts["kubeletHttps"][0])
if err != nil {
return nil, err
}
}
glog.Infof("Using Kubernetes client with master %q and version %q\n", kubeConfig.Host, kubeConfig.Version)
glog.Infof("Using kubelet port %d", kubeletPort)
kubeletConfig := &kube_client.KubeletConfig{
Port: uint(kubeletPort),
EnableHttps: kubeletHttps,
TLSClientConfig: kubeConfig.TLSClientConfig,
//.........这里部分代码省略.........