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
312d53d9
Commit
312d53d9
authored
Oct 22, 2015
by
Fabiano Franz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expose attachable pod discovery to factory
parent
ebf3ee3f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
27 deletions
+40
-27
run.go
pkg/kubectl/cmd/run.go
+6
-27
factory.go
pkg/kubectl/cmd/util/factory.go
+34
-0
No files found.
pkg/kubectl/cmd/run.go
View file @
312d53d9
...
@@ -26,11 +26,9 @@ import (
...
@@ -26,11 +26,9 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/api/meta"
client
"k8s.io/kubernetes/pkg/client/unversioned"
client
"k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/runtime"
)
)
...
@@ -170,7 +168,7 @@ func Run(f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *cob
...
@@ -170,7 +168,7 @@ func Run(f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *cob
}
}
}
}
obj
,
kind
,
mapper
,
mapping
,
err
:=
createGeneratedObject
(
f
,
cmd
,
generator
,
names
,
params
,
cmdutil
.
GetFlagString
(
cmd
,
"overrides"
),
namespace
)
obj
,
_
,
mapper
,
mapping
,
err
:=
createGeneratedObject
(
f
,
cmd
,
generator
,
names
,
params
,
cmdutil
.
GetFlagString
(
cmd
,
"overrides"
),
namespace
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -202,15 +200,12 @@ func Run(f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *cob
...
@@ -202,15 +200,12 @@ func Run(f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *cob
return
err
return
err
}
}
opts
.
Client
=
client
opts
.
Client
=
client
// TODO: this should be abstracted into Factory to support other types
switch
t
:=
obj
.
(
type
)
{
attachablePod
,
err
:=
f
.
AttachablePodForObject
(
obj
)
case
*
api
.
ReplicationController
:
if
err
!=
nil
{
return
handleAttachReplicationController
(
client
,
t
,
opts
)
return
err
case
*
api
.
Pod
:
return
handleAttachPod
(
client
,
t
,
opts
)
default
:
return
fmt
.
Errorf
(
"cannot attach to %s: not implemented"
,
kind
)
}
}
return
handleAttachPod
(
client
,
attachablePod
,
opts
)
}
}
outputFormat
:=
cmdutil
.
GetFlagString
(
cmd
,
"output"
)
outputFormat
:=
cmdutil
.
GetFlagString
(
cmd
,
"output"
)
...
@@ -249,22 +244,6 @@ func waitForPodRunning(c *client.Client, pod *api.Pod, out io.Writer) (status ap
...
@@ -249,22 +244,6 @@ func waitForPodRunning(c *client.Client, pod *api.Pod, out io.Writer) (status ap
}
}
}
}
func
handleAttachReplicationController
(
c
*
client
.
Client
,
controller
*
api
.
ReplicationController
,
opts
*
AttachOptions
)
error
{
var
pods
*
api
.
PodList
for
pods
==
nil
||
len
(
pods
.
Items
)
==
0
{
var
err
error
if
pods
,
err
=
c
.
Pods
(
controller
.
Namespace
)
.
List
(
labels
.
SelectorFromSet
(
controller
.
Spec
.
Selector
),
fields
.
Everything
());
err
!=
nil
{
return
err
}
if
len
(
pods
.
Items
)
==
0
{
fmt
.
Fprint
(
opts
.
Out
,
"Waiting for pod to be scheduled
\n
"
)
time
.
Sleep
(
2
*
time
.
Second
)
}
}
pod
:=
&
pods
.
Items
[
0
]
return
handleAttachPod
(
c
,
pod
,
opts
)
}
func
handleAttachPod
(
c
*
client
.
Client
,
pod
*
api
.
Pod
,
opts
*
AttachOptions
)
error
{
func
handleAttachPod
(
c
*
client
.
Client
,
pod
*
api
.
Pod
,
opts
*
AttachOptions
)
error
{
status
,
err
:=
waitForPodRunning
(
c
,
pod
,
opts
.
Out
)
status
,
err
:=
waitForPodRunning
(
c
,
pod
,
opts
.
Out
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/kubectl/cmd/util/factory.go
View file @
312d53d9
...
@@ -27,6 +27,7 @@ import (
...
@@ -27,6 +27,7 @@ import (
"os/user"
"os/user"
"path"
"path"
"strconv"
"strconv"
"time"
"github.com/spf13/cobra"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/pflag"
...
@@ -37,8 +38,10 @@ import (
...
@@ -37,8 +38,10 @@ import (
"k8s.io/kubernetes/pkg/api/validation"
"k8s.io/kubernetes/pkg/api/validation"
client
"k8s.io/kubernetes/pkg/client/unversioned"
client
"k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util"
)
)
...
@@ -92,6 +95,8 @@ type Factory struct {
...
@@ -92,6 +95,8 @@ type Factory struct {
CanBeExposed
func
(
kind
string
)
error
CanBeExposed
func
(
kind
string
)
error
// Check whether the kind of resources could be autoscaled
// Check whether the kind of resources could be autoscaled
CanBeAutoscaled
func
(
kind
string
)
error
CanBeAutoscaled
func
(
kind
string
)
error
// AttachablePodForObject returns the pod to which to attach given an object.
AttachablePodForObject
func
(
object
runtime
.
Object
)
(
*
api
.
Pod
,
error
)
}
}
// NewFactory creates a factory with the default Kubernetes resources defined
// NewFactory creates a factory with the default Kubernetes resources defined
...
@@ -268,6 +273,35 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -268,6 +273,35 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
}
}
return
nil
return
nil
},
},
AttachablePodForObject
:
func
(
object
runtime
.
Object
)
(
*
api
.
Pod
,
error
)
{
client
,
err
:=
clients
.
ClientForVersion
(
""
)
if
err
!=
nil
{
return
nil
,
err
}
switch
t
:=
object
.
(
type
)
{
case
*
api
.
ReplicationController
:
var
pods
*
api
.
PodList
for
pods
==
nil
||
len
(
pods
.
Items
)
==
0
{
var
err
error
if
pods
,
err
=
client
.
Pods
(
t
.
Namespace
)
.
List
(
labels
.
SelectorFromSet
(
t
.
Spec
.
Selector
),
fields
.
Everything
());
err
!=
nil
{
return
nil
,
err
}
if
len
(
pods
.
Items
)
==
0
{
time
.
Sleep
(
2
*
time
.
Second
)
}
}
pod
:=
&
pods
.
Items
[
0
]
return
pod
,
nil
case
*
api
.
Pod
:
return
t
,
nil
default
:
_
,
kind
,
err
:=
api
.
Scheme
.
ObjectVersionAndKind
(
object
)
if
err
!=
nil
{
return
nil
,
err
}
return
nil
,
fmt
.
Errorf
(
"cannot attach to %s: not implemented"
,
kind
)
}
},
}
}
}
}
...
...
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