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
565f40ef
Commit
565f40ef
authored
Dec 07, 2022
by
Brad Davidson
Committed by
Brad Davidson
Feb 10, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add utility functions for getting kubernetes client
Signed-off-by:
Brad Davidson
<
brad.davidson@rancher.com
>
(cherry picked from commit
3c324335
)
parent
2b76d471
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
18 deletions
+31
-18
run.go
pkg/agent/run.go
+1
-12
tunnel.go
pkg/agent/tunnel/tunnel.go
+1
-6
client.go
pkg/util/client.go
+29
-0
No files found.
pkg/agent/run.go
View file @
565f40ef
...
@@ -39,10 +39,8 @@ import (
...
@@ -39,10 +39,8 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/kubernetes"
typedcorev1
"k8s.io/client-go/kubernetes/typed/core/v1"
typedcorev1
"k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/clientcmd"
toolswatch
"k8s.io/client-go/tools/watch"
toolswatch
"k8s.io/client-go/tools/watch"
app2
"k8s.io/kubernetes/cmd/kube-proxy/app"
app2
"k8s.io/kubernetes/cmd/kube-proxy/app"
kubeproxyconfig
"k8s.io/kubernetes/pkg/proxy/apis/config"
kubeproxyconfig
"k8s.io/kubernetes/pkg/proxy/apis/config"
...
@@ -132,7 +130,7 @@ func run(ctx context.Context, cfg cmds.Agent, proxy proxy.Proxy) error {
...
@@ -132,7 +130,7 @@ func run(ctx context.Context, cfg cmds.Agent, proxy proxy.Proxy) error {
return
errors
.
Wrap
(
err
,
"failed to wait for apiserver ready"
)
return
errors
.
Wrap
(
err
,
"failed to wait for apiserver ready"
)
}
}
coreClient
,
err
:=
coreClien
t
(
nodeConfig
.
AgentConfig
.
KubeConfigKubelet
)
coreClient
,
err
:=
util
.
GetClientSe
t
(
nodeConfig
.
AgentConfig
.
KubeConfigKubelet
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -208,15 +206,6 @@ func getConntrackConfig(nodeConfig *daemonconfig.Node) (*kubeproxyconfig.KubePro
...
@@ -208,15 +206,6 @@ func getConntrackConfig(nodeConfig *daemonconfig.Node) (*kubeproxyconfig.KubePro
return
ctConfig
,
nil
return
ctConfig
,
nil
}
}
func
coreClient
(
cfg
string
)
(
kubernetes
.
Interface
,
error
)
{
restConfig
,
err
:=
clientcmd
.
BuildConfigFromFlags
(
""
,
cfg
)
if
err
!=
nil
{
return
nil
,
err
}
return
kubernetes
.
NewForConfig
(
restConfig
)
}
// RunStandalone bootstraps the executor, but does not run the kubelet or containerd.
// RunStandalone bootstraps the executor, but does not run the kubelet or containerd.
// This allows other bits of code that expect the executor to be set up properly to function
// This allows other bits of code that expect the executor to be set up properly to function
// even when the agent is disabled. It will only return in case of error or context
// even when the agent is disabled. It will only return in case of error or context
...
...
pkg/agent/tunnel/tunnel.go
View file @
565f40ef
...
@@ -56,12 +56,7 @@ func (p *podEntry) Network() net.IPNet {
...
@@ -56,12 +56,7 @@ func (p *podEntry) Network() net.IPNet {
}
}
func
Setup
(
ctx
context
.
Context
,
config
*
daemonconfig
.
Node
,
proxy
proxy
.
Proxy
)
error
{
func
Setup
(
ctx
context
.
Context
,
config
*
daemonconfig
.
Node
,
proxy
proxy
.
Proxy
)
error
{
restConfig
,
err
:=
clientcmd
.
BuildConfigFromFlags
(
""
,
config
.
AgentConfig
.
KubeConfigK3sController
)
client
,
err
:=
util
.
GetClientSet
(
config
.
AgentConfig
.
KubeConfigK3sController
)
if
err
!=
nil
{
return
err
}
client
,
err
:=
kubernetes
.
NewForConfig
(
restConfig
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
pkg/util/client.go
0 → 100644
View file @
565f40ef
package
util
import
(
"github.com/k3s-io/k3s/pkg/datadir"
clientset
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
)
// GetKubeConfigPath can be used to search for a kubeconfig in standard
// locations if an empty string is passed. If a non-empty string is passed,
// that path is used.
func
GetKubeConfigPath
(
file
string
)
string
{
if
file
!=
""
{
return
file
}
rules
:=
clientcmd
.
NewDefaultClientConfigLoadingRules
()
rules
.
Precedence
=
append
([]
string
{
datadir
.
GlobalConfig
},
rules
.
Precedence
...
)
return
rules
.
GetDefaultFilename
()
}
// GetClientSet creates a Kubernetes client from the kubeconfig at the provided path.
func
GetClientSet
(
file
string
)
(
clientset
.
Interface
,
error
)
{
restConfig
,
err
:=
clientcmd
.
BuildConfigFromFlags
(
""
,
file
)
if
err
!=
nil
{
return
nil
,
err
}
return
clientset
.
NewForConfig
(
restConfig
)
}
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