Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
ab7e4d56
Commit
ab7e4d56
authored
Feb 02, 2017
by
deads2k
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove unnecessarily duplication since types collapsed
parent
0e5cda98
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
4 additions
and
142 deletions
+4
-142
BUILD
cmd/kubelet/app/BUILD
+0
-1
clientgo.go
cmd/kubelet/app/clientgo.go
+0
-120
server.go
cmd/kubelet/app/server.go
+4
-21
No files found.
cmd/kubelet/app/BUILD
View file @
ab7e4d56
...
...
@@ -29,7 +29,6 @@ go_library(
srcs = [
"auth.go",
"bootstrap.go",
"clientgo.go",
"plugins.go",
"server.go",
"server_linux.go",
...
...
cmd/kubelet/app/clientgo.go
deleted
100644 → 0
View file @
0e5cda98
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// this file contains parallel methods for getting a client-go clientconfig
// The types are not reasonably compatibly between the client-go and kubernetes restclient.Interface,
// restclient.Config, or typed clients, so this is the simplest solution during the transition
package
app
import
(
"fmt"
"net/http"
"github.com/golang/glog"
"k8s.io/client-go/rest"
clientauth
"k8s.io/client-go/tools/auth"
"k8s.io/client-go/tools/clientcmd"
clientcmdapi
"k8s.io/client-go/tools/clientcmd/api"
"k8s.io/kubernetes/cmd/kubelet/app/options"
"k8s.io/kubernetes/pkg/client/chaosclient"
)
func
kubeconfigClientGoConfig
(
s
*
options
.
KubeletServer
)
(
*
rest
.
Config
,
error
)
{
if
s
.
RequireKubeConfig
{
// Ignores the values of s.APIServerList
return
clientcmd
.
NewNonInteractiveDeferredLoadingClientConfig
(
&
clientcmd
.
ClientConfigLoadingRules
{
ExplicitPath
:
s
.
KubeConfig
.
Value
()},
&
clientcmd
.
ConfigOverrides
{},
)
.
ClientConfig
()
}
return
clientcmd
.
NewNonInteractiveDeferredLoadingClientConfig
(
&
clientcmd
.
ClientConfigLoadingRules
{
ExplicitPath
:
s
.
KubeConfig
.
Value
()},
&
clientcmd
.
ConfigOverrides
{
ClusterInfo
:
clientcmdapi
.
Cluster
{
Server
:
s
.
APIServerList
[
0
]}},
)
.
ClientConfig
()
}
// createClientConfig creates a client configuration from the command line
// arguments. If --kubeconfig is explicitly set, it will be used. If it is
// not set, we attempt to load the default kubeconfig file, and if we cannot,
// we fall back to the default client with no auth - this fallback does not, in
// and of itself, constitute an error.
func
createClientGoConfig
(
s
*
options
.
KubeletServer
)
(
*
rest
.
Config
,
error
)
{
if
s
.
RequireKubeConfig
{
return
kubeconfigClientGoConfig
(
s
)
}
// TODO: handle a new --standalone flag that bypasses kubeconfig loading and returns no error.
// DEPRECATED: all subsequent code is deprecated
if
len
(
s
.
APIServerList
)
==
0
{
return
nil
,
fmt
.
Errorf
(
"no api servers specified"
)
}
// TODO: adapt Kube client to support LB over several servers
if
len
(
s
.
APIServerList
)
>
1
{
glog
.
Infof
(
"Multiple api servers specified. Picking first one"
)
}
if
s
.
KubeConfig
.
Provided
()
{
return
kubeconfigClientGoConfig
(
s
)
}
// If KubeConfig was not provided, try to load the default file, then fall back
// to a default auth config.
clientConfig
,
err
:=
kubeconfigClientGoConfig
(
s
)
if
err
!=
nil
{
glog
.
Warningf
(
"Could not load kubeconfig file %s: %v. Using default client config instead."
,
s
.
KubeConfig
,
err
)
authInfo
:=
&
clientauth
.
Info
{}
authConfig
,
err
:=
authInfo
.
MergeWithConfig
(
rest
.
Config
{})
if
err
!=
nil
{
return
nil
,
err
}
authConfig
.
Host
=
s
.
APIServerList
[
0
]
clientConfig
=
&
authConfig
}
return
clientConfig
,
nil
}
// createAPIServerClientGoConfig generates a client.Config from command line flags,
// including api-server-list, via createClientConfig and then injects chaos into
// the configuration via addChaosToClientConfig. This func is exported to support
// integration with third party kubelet extensions (e.g. kubernetes-mesos).
func
createAPIServerClientGoConfig
(
s
*
options
.
KubeletServer
)
(
*
rest
.
Config
,
error
)
{
clientConfig
,
err
:=
createClientGoConfig
(
s
)
if
err
!=
nil
{
return
nil
,
err
}
clientConfig
.
ContentType
=
s
.
ContentType
// Override kubeconfig qps/burst settings from flags
clientConfig
.
QPS
=
float32
(
s
.
KubeAPIQPS
)
clientConfig
.
Burst
=
int
(
s
.
KubeAPIBurst
)
addChaosToClientGoConfig
(
s
,
clientConfig
)
return
clientConfig
,
nil
}
// addChaosToClientConfig injects random errors into client connections if configured.
func
addChaosToClientGoConfig
(
s
*
options
.
KubeletServer
,
config
*
rest
.
Config
)
{
if
s
.
ChaosChance
!=
0.0
{
config
.
WrapTransport
=
func
(
rt
http
.
RoundTripper
)
http
.
RoundTripper
{
seed
:=
chaosclient
.
NewSeed
(
1
)
// TODO: introduce a standard chaos package with more tunables - this is just a proof of concept
// TODO: introduce random latency and stalls
return
chaosclient
.
NewChaosRoundTripper
(
rt
,
chaosclient
.
LogChaos
,
seed
.
P
(
s
.
ChaosChance
,
chaosclient
.
ErrSimulatedConnectionResetByPeer
))
}
}
}
cmd/kubelet/app/server.go
View file @
ab7e4d56
...
...
@@ -396,6 +396,10 @@ func run(s *options.KubeletServer, kubeDeps *kubelet.KubeletDeps) (err error) {
if
err
!=
nil
{
glog
.
Warningf
(
"New kubeClient from clientConfig error: %v"
,
err
)
}
externalKubeClient
,
err
=
clientgoclientset
.
NewForConfig
(
clientConfig
)
if
err
!=
nil
{
glog
.
Warningf
(
"New kubeClient from clientConfig error: %v"
,
err
)
}
// make a separate client for events
eventClientConfig
:=
*
clientConfig
eventClientConfig
.
QPS
=
float32
(
s
.
EventRecordQPS
)
...
...
@@ -413,27 +417,6 @@ func run(s *options.KubeletServer, kubeDeps *kubelet.KubeletDeps) (err error) {
}
}
// client-go and kuberenetes generated clients are incompatible because the runtime
// and runtime/serializer types have been duplicated in client-go. This means that
// you can't reasonably convert from one to the other and its impossible for a single
// type to fulfill both interfaces. Because of that, we have to build the clients
// up from scratch twice.
// TODO eventually the kubelet should only use the client-go library
clientGoConfig
,
err
:=
createAPIServerClientGoConfig
(
s
)
if
err
==
nil
{
externalKubeClient
,
err
=
clientgoclientset
.
NewForConfig
(
clientGoConfig
)
if
err
!=
nil
{
glog
.
Warningf
(
"New kubeClient from clientConfig error: %v"
,
err
)
}
}
else
{
if
s
.
RequireKubeConfig
{
return
fmt
.
Errorf
(
"invalid kubeconfig: %v"
,
err
)
}
if
standaloneMode
{
glog
.
Warningf
(
"No API client: %v"
,
err
)
}
}
kubeDeps
,
err
=
UnsecuredKubeletDeps
(
s
)
if
err
!=
nil
{
return
err
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment