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
1d5e5532
Commit
1d5e5532
authored
Sep 06, 2016
by
deads2k
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add ClientSet to factory to remove non-generated client
parent
dc529a03
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
48 additions
and
12 deletions
+48
-12
attach.go
pkg/kubectl/cmd/attach.go
+11
-7
attach_test.go
pkg/kubectl/cmd/attach_test.go
+3
-3
cmd_test.go
pkg/kubectl/cmd/cmd_test.go
+9
-0
run.go
pkg/kubectl/cmd/run.go
+13
-2
factory.go
pkg/kubectl/cmd/util/factory.go
+12
-0
No files found.
pkg/kubectl/cmd/attach.go
View file @
1d5e5532
...
...
@@ -26,8 +26,8 @@ import (
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/api"
coreclient
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/unversioned"
"k8s.io/kubernetes/pkg/client/restclient"
client
"k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/remotecommand"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
remotecommandserver
"k8s.io/kubernetes/pkg/kubelet/server/remotecommand"
...
...
@@ -108,7 +108,7 @@ type AttachOptions struct {
Pod
*
api
.
Pod
Attach
RemoteAttach
Client
*
client
.
Client
PodClient
coreclient
.
PodsGetter
Config
*
restclient
.
Config
}
...
...
@@ -134,11 +134,11 @@ func (p *AttachOptions) Complete(f *cmdutil.Factory, cmd *cobra.Command, argsIn
}
p
.
Config
=
config
client
,
err
:=
f
.
Clien
t
()
client
set
,
err
:=
f
.
ClientSe
t
()
if
err
!=
nil
{
return
err
}
p
.
Client
=
client
p
.
PodClient
=
clientset
.
Core
()
if
p
.
CommandName
==
""
{
p
.
CommandName
=
cmd
.
CommandPath
()
...
...
@@ -156,7 +156,7 @@ func (p *AttachOptions) Validate() error {
if
p
.
Out
==
nil
||
p
.
Err
==
nil
{
allErrs
=
append
(
allErrs
,
fmt
.
Errorf
(
"both output and error output must be provided"
))
}
if
p
.
Attach
==
nil
||
p
.
Client
==
nil
||
p
.
Config
==
nil
{
if
p
.
Attach
==
nil
||
p
.
Pod
Client
==
nil
||
p
.
Config
==
nil
{
allErrs
=
append
(
allErrs
,
fmt
.
Errorf
(
"client, client config, and attach must be provided"
))
}
return
utilerrors
.
NewAggregate
(
allErrs
)
...
...
@@ -165,7 +165,7 @@ func (p *AttachOptions) Validate() error {
// Run executes a validated remote execution against a pod.
func
(
p
*
AttachOptions
)
Run
()
error
{
if
p
.
Pod
==
nil
{
pod
,
err
:=
p
.
Client
.
Pods
(
p
.
Namespace
)
.
Get
(
p
.
PodName
)
pod
,
err
:=
p
.
Pod
Client
.
Pods
(
p
.
Namespace
)
.
Get
(
p
.
PodName
)
if
err
!=
nil
{
return
err
}
...
...
@@ -225,8 +225,12 @@ func (p *AttachOptions) Run() error {
fmt
.
Fprintln
(
stderr
,
"If you don't see a command prompt, try pressing enter."
)
}
restClient
,
err
:=
restclient
.
RESTClientFor
(
p
.
Config
)
if
err
!=
nil
{
return
err
}
// TODO: consider abstracting into a client invocation or client helper
req
:=
p
.
Client
.
REST
Client
.
Post
()
.
req
:=
rest
Client
.
Post
()
.
Resource
(
"pods"
)
.
Name
(
pod
.
Name
)
.
Namespace
(
pod
.
Namespace
)
.
...
...
pkg/kubectl/cmd/attach_test.go
View file @
1d5e5532
...
...
@@ -178,7 +178,7 @@ func TestAttach(t *testing.T) {
}),
}
tf
.
Namespace
=
"test"
tf
.
ClientConfig
=
&
restclient
.
Config
{
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
&
unversioned
.
GroupVersion
{
Version
:
test
.
version
}}}
tf
.
ClientConfig
=
&
restclient
.
Config
{
APIPath
:
"/api"
,
ContentConfig
:
restclient
.
ContentConfig
{
NegotiatedSerializer
:
api
.
Codecs
,
GroupVersion
:
&
unversioned
.
GroupVersion
{
Version
:
test
.
version
}}}
bufOut
:=
bytes
.
NewBuffer
([]
byte
{})
bufErr
:=
bytes
.
NewBuffer
([]
byte
{})
bufIn
:=
bytes
.
NewBuffer
([]
byte
{})
...
...
@@ -212,7 +212,7 @@ func TestAttach(t *testing.T) {
continue
}
if
remoteAttach
.
url
.
Path
!=
test
.
attachPath
{
t
.
Errorf
(
"%s: Did not get expected path for exec request
"
,
test
.
name
)
t
.
Errorf
(
"%s: Did not get expected path for exec request
: %q %q"
,
test
.
name
,
test
.
attachPath
,
remoteAttach
.
url
.
Path
)
continue
}
if
remoteAttach
.
method
!=
"POST"
{
...
...
@@ -257,7 +257,7 @@ func TestAttachWarnings(t *testing.T) {
}),
}
tf
.
Namespace
=
"test"
tf
.
ClientConfig
=
&
restclient
.
Config
{
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
&
unversioned
.
GroupVersion
{
Version
:
test
.
version
}}}
tf
.
ClientConfig
=
&
restclient
.
Config
{
APIPath
:
"/api"
,
ContentConfig
:
restclient
.
ContentConfig
{
NegotiatedSerializer
:
api
.
Codecs
,
GroupVersion
:
&
unversioned
.
GroupVersion
{
Version
:
test
.
version
}}}
bufOut
:=
bytes
.
NewBuffer
([]
byte
{})
bufErr
:=
bytes
.
NewBuffer
([]
byte
{})
bufIn
:=
bytes
.
NewBuffer
([]
byte
{})
...
...
pkg/kubectl/cmd/cmd_test.go
View file @
1d5e5532
...
...
@@ -33,9 +33,11 @@ import (
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/validation"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
"k8s.io/kubernetes/pkg/client/restclient"
"k8s.io/kubernetes/pkg/client/typed/discovery"
client
"k8s.io/kubernetes/pkg/client/unversioned"
clientset
"k8s.io/kubernetes/pkg/client/unversioned/adapters/internalclientset"
"k8s.io/kubernetes/pkg/client/unversioned/fake"
"k8s.io/kubernetes/pkg/kubectl"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
...
...
@@ -295,6 +297,13 @@ func NewAPIFactory() (*cmdutil.Factory, *testFactory, runtime.Codec, runtime.Neg
c
.
ExtensionsClient
.
Client
=
fakeClient
.
Client
return
c
,
t
.
Err
},
ClientSet
:
func
()
(
*
internalclientset
.
Clientset
,
error
)
{
fakeClient
:=
t
.
Client
.
(
*
fake
.
RESTClient
)
c
:=
client
.
NewOrDie
(
t
.
ClientConfig
)
c
.
Client
=
fakeClient
.
Client
c
.
ExtensionsClient
.
Client
=
fakeClient
.
Client
return
clientset
.
FromUnversionedClient
(
c
),
nil
},
ClientForMapping
:
func
(
*
meta
.
RESTMapping
)
(
resource
.
RESTClient
,
error
)
{
return
t
.
Client
,
t
.
Err
},
...
...
pkg/kubectl/cmd/run.go
View file @
1d5e5532
...
...
@@ -274,7 +274,12 @@ func Run(f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *cob
if
err
!=
nil
{
return
err
}
opts
.
Client
=
client
clientset
,
err
:=
f
.
ClientSet
()
if
err
!=
nil
{
return
err
}
opts
.
PodClient
=
clientset
.
Core
()
attachablePod
,
err
:=
f
.
AttachablePodForObject
(
obj
)
if
err
!=
nil
{
...
...
@@ -475,7 +480,13 @@ func handleAttachPod(f *cmdutil.Factory, c *client.Client, ns, name string, opts
_
,
err
=
io
.
Copy
(
opts
.
Out
,
readCloser
)
return
err
}
opts
.
Client
=
c
clientset
,
err
:=
f
.
ClientSet
()
if
err
!=
nil
{
return
nil
}
opts
.
PodClient
=
clientset
.
Core
()
opts
.
PodName
=
name
opts
.
Namespace
=
ns
if
err
:=
opts
.
Run
();
err
!=
nil
{
...
...
pkg/kubectl/cmd/util/factory.go
View file @
1d5e5532
...
...
@@ -54,6 +54,7 @@ import (
"k8s.io/kubernetes/pkg/apis/policy"
"k8s.io/kubernetes/pkg/apis/rbac"
"k8s.io/kubernetes/pkg/apis/storage"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
"k8s.io/kubernetes/pkg/client/restclient"
"k8s.io/kubernetes/pkg/client/typed/discovery"
"k8s.io/kubernetes/pkg/client/typed/dynamic"
...
...
@@ -98,6 +99,8 @@ type Factory struct {
JSONEncoder
func
()
runtime
.
Encoder
// Returns a client for accessing Kubernetes resources or an error.
Client
func
()
(
*
client
.
Client
,
error
)
// ClientSet gives you back an internal, generated clientset
ClientSet
func
()
(
*
internalclientset
.
Clientset
,
error
)
// Returns a client.Config for accessing the Kubernetes server.
ClientConfig
func
()
(
*
restclient
.
Config
,
error
)
// Returns a RESTClient for working with the specified RESTMapping or an error. This is intended
...
...
@@ -406,6 +409,15 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
Client
:
func
()
(
*
client
.
Client
,
error
)
{
return
clients
.
ClientForVersion
(
nil
)
},
ClientSet
:
func
()
(
*
internalclientset
.
Clientset
,
error
)
{
cfg
,
err
:=
clients
.
ClientConfigForVersion
(
nil
)
if
err
!=
nil
{
return
nil
,
err
}
return
internalclientset
.
NewForConfig
(
cfg
)
},
ClientConfig
:
func
()
(
*
restclient
.
Config
,
error
)
{
return
clients
.
ClientConfigForVersion
(
nil
)
},
...
...
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