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
8c1b6873
Commit
8c1b6873
authored
Apr 25, 2018
by
David Eads
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update more commands for iostreams
parent
3fb88a23
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
24 changed files
with
241 additions
and
262 deletions
+241
-262
cmd.go
pkg/kubectl/cmd/cmd.go
+6
-6
cmd_test.go
pkg/kubectl/cmd/cmd_test.go
+2
-1
explain.go
pkg/kubectl/cmd/explain.go
+18
-6
expose.go
pkg/kubectl/cmd/expose.go
+12
-11
expose_test.go
pkg/kubectl/cmd/expose_test.go
+3
-3
BUILD
pkg/kubectl/cmd/resource/BUILD
+2
-0
get.go
pkg/kubectl/cmd/resource/get.go
+8
-7
get_test.go
pkg/kubectl/cmd/resource/get_test.go
+47
-71
run.go
pkg/kubectl/cmd/run.go
+5
-9
run_test.go
pkg/kubectl/cmd/run_test.go
+8
-13
BUILD
pkg/kubectl/cmd/set/BUILD
+1
-0
set.go
pkg/kubectl/cmd/set/set.go
+9
-10
set_env.go
pkg/kubectl/cmd/set/set_env.go
+10
-13
set_env_test.go
pkg/kubectl/cmd/set/set_env_test.go
+14
-15
set_image.go
pkg/kubectl/cmd/set/set_image.go
+6
-8
set_image_test.go
pkg/kubectl/cmd/set/set_image_test.go
+16
-14
set_resources.go
pkg/kubectl/cmd/set/set_resources.go
+7
-8
set_resources_test.go
pkg/kubectl/cmd/set/set_resources_test.go
+16
-14
set_selector.go
pkg/kubectl/cmd/set/set_selector.go
+8
-8
set_selector_test.go
pkg/kubectl/cmd/set/set_selector_test.go
+3
-4
set_serviceaccount.go
pkg/kubectl/cmd/set/set_serviceaccount.go
+8
-10
set_serviceaccount_test.go
pkg/kubectl/cmd/set/set_serviceaccount_test.go
+20
-19
set_subject.go
pkg/kubectl/cmd/set/set_subject.go
+10
-7
set_test.go
pkg/kubectl/cmd/set/set_test.go
+2
-5
No files found.
pkg/kubectl/cmd/cmd.go
View file @
8c1b6873
...
@@ -255,17 +255,17 @@ func NewKubectlCommand(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cob
...
@@ -255,17 +255,17 @@ func NewKubectlCommand(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cob
Message
:
"Basic Commands (Beginner):"
,
Message
:
"Basic Commands (Beginner):"
,
Commands
:
[]
*
cobra
.
Command
{
Commands
:
[]
*
cobra
.
Command
{
create
.
NewCmdCreate
(
f
,
ioStreams
),
create
.
NewCmdCreate
(
f
,
ioStreams
),
NewCmdExposeService
(
f
,
out
),
NewCmdExposeService
(
f
,
ioStreams
),
NewCmdRun
(
f
,
i
n
,
out
,
err
),
NewCmdRun
(
f
,
i
oStreams
),
set
.
NewCmdSet
(
f
,
i
n
,
out
,
err
),
set
.
NewCmdSet
(
f
,
i
oStreams
),
deprecatedAlias
(
"run-container"
,
NewCmdRun
(
f
,
i
n
,
out
,
err
)),
deprecatedAlias
(
"run-container"
,
NewCmdRun
(
f
,
i
oStreams
)),
},
},
},
},
{
{
Message
:
"Basic Commands (Intermediate):"
,
Message
:
"Basic Commands (Intermediate):"
,
Commands
:
[]
*
cobra
.
Command
{
Commands
:
[]
*
cobra
.
Command
{
resource
.
NewCmdGet
(
f
,
out
,
err
),
resource
.
NewCmdGet
(
f
,
ioStreams
),
NewCmdExplain
(
f
,
out
,
err
),
NewCmdExplain
(
f
,
ioStreams
),
NewCmdEdit
(
f
,
ioStreams
),
NewCmdEdit
(
f
,
ioStreams
),
NewCmdDelete
(
f
,
out
,
err
),
NewCmdDelete
(
f
,
out
,
err
),
},
},
...
...
pkg/kubectl/cmd/cmd_test.go
View file @
8c1b6873
...
@@ -43,6 +43,7 @@ import (
...
@@ -43,6 +43,7 @@ import (
"k8s.io/kubernetes/pkg/kubectl/cmd/resource"
"k8s.io/kubernetes/pkg/kubectl/cmd/resource"
cmdtesting
"k8s.io/kubernetes/pkg/kubectl/cmd/testing"
cmdtesting
"k8s.io/kubernetes/pkg/kubectl/cmd/testing"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
"k8s.io/kubernetes/pkg/kubectl/scheme"
"k8s.io/kubernetes/pkg/kubectl/scheme"
"k8s.io/kubernetes/pkg/printers"
"k8s.io/kubernetes/pkg/printers"
"k8s.io/kubernetes/pkg/util/strings"
"k8s.io/kubernetes/pkg/util/strings"
...
@@ -253,7 +254,7 @@ func Example_printServiceWithLabels() {
...
@@ -253,7 +254,7 @@ func Example_printServiceWithLabels() {
NegotiatedSerializer
:
ns
,
NegotiatedSerializer
:
ns
,
Client
:
nil
,
Client
:
nil
,
}
}
cmd
:=
resource
.
NewCmdGet
(
tf
,
os
.
Stdout
,
os
.
Stderr
)
cmd
:=
resource
.
NewCmdGet
(
tf
,
genericclioptions
.
NewTestIOStreamsDiscard
()
)
svc
:=
&
api
.
ServiceList
{
svc
:=
&
api
.
ServiceList
{
Items
:
[]
api
.
Service
{
Items
:
[]
api
.
Service
{
{
{
...
...
pkg/kubectl/cmd/explain.go
View file @
8c1b6873
...
@@ -18,7 +18,6 @@ package cmd
...
@@ -18,7 +18,6 @@ package cmd
import
(
import
(
"fmt"
"fmt"
"io"
"github.com/spf13/cobra"
"github.com/spf13/cobra"
...
@@ -26,6 +25,7 @@ import (
...
@@ -26,6 +25,7 @@ import (
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/explain"
"k8s.io/kubernetes/pkg/kubectl/explain"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
"k8s.io/kubernetes/pkg/kubectl/util/i18n"
"k8s.io/kubernetes/pkg/kubectl/util/i18n"
)
)
...
@@ -49,8 +49,20 @@ var (
...
@@ -49,8 +49,20 @@ var (
kubectl explain pods.spec.containers`
))
kubectl explain pods.spec.containers`
))
)
)
type
ExplainOptions
struct
{
genericclioptions
.
IOStreams
}
func
NewExplainOptions
(
streams
genericclioptions
.
IOStreams
)
*
ExplainOptions
{
return
&
ExplainOptions
{
IOStreams
:
streams
,
}
}
// NewCmdExplain returns a cobra command for swagger docs
// NewCmdExplain returns a cobra command for swagger docs
func
NewCmdExplain
(
f
cmdutil
.
Factory
,
out
,
cmdErr
io
.
Writer
)
*
cobra
.
Command
{
func
NewCmdExplain
(
f
cmdutil
.
Factory
,
streams
genericclioptions
.
IOStreams
)
*
cobra
.
Command
{
o
:=
NewExplainOptions
(
streams
)
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"explain RESOURCE"
,
Use
:
"explain RESOURCE"
,
DisableFlagsInUseLine
:
true
,
DisableFlagsInUseLine
:
true
,
...
@@ -58,7 +70,7 @@ func NewCmdExplain(f cmdutil.Factory, out, cmdErr io.Writer) *cobra.Command {
...
@@ -58,7 +70,7 @@ func NewCmdExplain(f cmdutil.Factory, out, cmdErr io.Writer) *cobra.Command {
Long
:
explainLong
+
"
\n\n
"
+
cmdutil
.
ValidResourceTypeList
(
f
),
Long
:
explainLong
+
"
\n\n
"
+
cmdutil
.
ValidResourceTypeList
(
f
),
Example
:
explainExamples
,
Example
:
explainExamples
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
err
:=
RunExplain
(
f
,
out
,
cmdErr
,
cmd
,
args
)
err
:=
o
.
RunExplain
(
f
,
cmd
,
args
)
cmdutil
.
CheckErr
(
err
)
cmdutil
.
CheckErr
(
err
)
},
},
}
}
...
@@ -68,9 +80,9 @@ func NewCmdExplain(f cmdutil.Factory, out, cmdErr io.Writer) *cobra.Command {
...
@@ -68,9 +80,9 @@ func NewCmdExplain(f cmdutil.Factory, out, cmdErr io.Writer) *cobra.Command {
}
}
// RunExplain executes the appropriate steps to print a model's documentation
// RunExplain executes the appropriate steps to print a model's documentation
func
RunExplain
(
f
cmdutil
.
Factory
,
out
,
cmdErr
io
.
Writer
,
cmd
*
cobra
.
Command
,
args
[]
string
)
error
{
func
(
o
*
ExplainOptions
)
RunExplain
(
f
cmdutil
.
Factory
,
cmd
*
cobra
.
Command
,
args
[]
string
)
error
{
if
len
(
args
)
==
0
{
if
len
(
args
)
==
0
{
fmt
.
Fprintf
(
cmdErr
,
"You must specify the type of resource to explain. %s
\n\n
"
,
cmdutil
.
ValidResourceTypeList
(
f
))
fmt
.
Fprintf
(
o
.
ErrOut
,
"You must specify the type of resource to explain. %s
\n\n
"
,
cmdutil
.
ValidResourceTypeList
(
f
))
return
cmdutil
.
UsageErrorf
(
cmd
,
"Required resource not specified."
)
return
cmdutil
.
UsageErrorf
(
cmd
,
"Required resource not specified."
)
}
}
if
len
(
args
)
>
1
{
if
len
(
args
)
>
1
{
...
@@ -120,5 +132,5 @@ func RunExplain(f cmdutil.Factory, out, cmdErr io.Writer, cmd *cobra.Command, ar
...
@@ -120,5 +132,5 @@ func RunExplain(f cmdutil.Factory, out, cmdErr io.Writer, cmd *cobra.Command, ar
return
fmt
.
Errorf
(
"Couldn't find resource for %q"
,
gvk
)
return
fmt
.
Errorf
(
"Couldn't find resource for %q"
,
gvk
)
}
}
return
explain
.
PrintModelDescription
(
fieldsPath
,
out
,
schema
,
gvk
,
recursive
)
return
explain
.
PrintModelDescription
(
fieldsPath
,
o
.
O
ut
,
schema
,
gvk
,
recursive
)
}
}
pkg/kubectl/cmd/expose.go
View file @
8c1b6873
...
@@ -17,7 +17,6 @@ limitations under the License.
...
@@ -17,7 +17,6 @@ limitations under the License.
package
cmd
package
cmd
import
(
import
(
"io"
"regexp"
"regexp"
"strings"
"strings"
...
@@ -79,18 +78,20 @@ type ExposeServiceOptions struct {
...
@@ -79,18 +78,20 @@ type ExposeServiceOptions struct {
RecordFlags
*
genericclioptions
.
RecordFlags
RecordFlags
*
genericclioptions
.
RecordFlags
Recorder
genericclioptions
.
Recorder
Recorder
genericclioptions
.
Recorder
genericclioptions
.
IOStreams
}
}
func
NewExposeServiceOptions
()
*
ExposeServiceOptions
{
func
NewExposeServiceOptions
(
streams
genericclioptions
.
IOStreams
)
*
ExposeServiceOptions
{
return
&
ExposeServiceOptions
{
return
&
ExposeServiceOptions
{
RecordFlags
:
genericclioptions
.
NewRecordFlags
(),
RecordFlags
:
genericclioptions
.
NewRecordFlags
(),
Recorder
:
genericclioptions
.
NoopRecorder
{},
Recorder
:
genericclioptions
.
NoopRecorder
{},
IOStreams
:
streams
,
}
}
}
}
func
NewCmdExposeService
(
f
cmdutil
.
Factory
,
out
io
.
Writer
)
*
cobra
.
Command
{
func
NewCmdExposeService
(
f
cmdutil
.
Factory
,
streams
genericclioptions
.
IOStreams
)
*
cobra
.
Command
{
o
:=
NewExposeServiceOptions
()
o
:=
NewExposeServiceOptions
(
streams
)
validArgs
:=
[]
string
{}
validArgs
:=
[]
string
{}
resources
:=
regexp
.
MustCompile
(
`\s*,`
)
.
Split
(
exposeResources
,
-
1
)
resources
:=
regexp
.
MustCompile
(
`\s*,`
)
.
Split
(
exposeResources
,
-
1
)
...
@@ -106,7 +107,7 @@ func NewCmdExposeService(f cmdutil.Factory, out io.Writer) *cobra.Command {
...
@@ -106,7 +107,7 @@ func NewCmdExposeService(f cmdutil.Factory, out io.Writer) *cobra.Command {
Example
:
exposeExample
,
Example
:
exposeExample
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
cmdutil
.
CheckErr
(
o
.
Complete
(
f
,
cmd
))
cmdutil
.
CheckErr
(
o
.
Complete
(
f
,
cmd
))
cmdutil
.
CheckErr
(
o
.
RunExpose
(
f
,
out
,
cmd
,
args
))
cmdutil
.
CheckErr
(
o
.
RunExpose
(
f
,
cmd
,
args
))
},
},
ValidArgs
:
validArgs
,
ValidArgs
:
validArgs
,
ArgAliases
:
kubectl
.
ResourceAliases
(
validArgs
),
ArgAliases
:
kubectl
.
ResourceAliases
(
validArgs
),
...
@@ -150,7 +151,7 @@ func (o *ExposeServiceOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) e
...
@@ -150,7 +151,7 @@ func (o *ExposeServiceOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) e
return
err
return
err
}
}
func
(
o
*
ExposeServiceOptions
)
RunExpose
(
f
cmdutil
.
Factory
,
out
io
.
Writer
,
cmd
*
cobra
.
Command
,
args
[]
string
)
error
{
func
(
o
*
ExposeServiceOptions
)
RunExpose
(
f
cmdutil
.
Factory
,
cmd
*
cobra
.
Command
,
args
[]
string
)
error
{
namespace
,
enforceNamespace
,
err
:=
f
.
DefaultNamespace
()
namespace
,
enforceNamespace
,
err
:=
f
.
DefaultNamespace
()
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -284,9 +285,9 @@ func (o *ExposeServiceOptions) RunExpose(f cmdutil.Factory, out io.Writer, cmd *
...
@@ -284,9 +285,9 @@ func (o *ExposeServiceOptions) RunExpose(f cmdutil.Factory, out io.Writer, cmd *
info
.
Refresh
(
object
,
true
)
info
.
Refresh
(
object
,
true
)
if
cmdutil
.
GetDryRunFlag
(
cmd
)
{
if
cmdutil
.
GetDryRunFlag
(
cmd
)
{
if
len
(
cmdutil
.
GetFlagString
(
cmd
,
"output"
))
>
0
{
if
len
(
cmdutil
.
GetFlagString
(
cmd
,
"output"
))
>
0
{
return
cmdutil
.
PrintObject
(
cmd
,
object
,
out
)
return
cmdutil
.
PrintObject
(
cmd
,
object
,
o
.
O
ut
)
}
}
cmdutil
.
PrintSuccess
(
false
,
out
,
info
.
Object
,
true
,
"exposed"
)
cmdutil
.
PrintSuccess
(
false
,
o
.
O
ut
,
info
.
Object
,
true
,
"exposed"
)
return
nil
return
nil
}
}
if
err
:=
kubectl
.
CreateOrUpdateAnnotation
(
cmdutil
.
GetFlagBool
(
cmd
,
cmdutil
.
ApplyAnnotationsFlag
),
info
.
Object
,
cmdutil
.
InternalVersionJSONEncoder
());
err
!=
nil
{
if
err
:=
kubectl
.
CreateOrUpdateAnnotation
(
cmdutil
.
GetFlagBool
(
cmd
,
cmdutil
.
ApplyAnnotationsFlag
),
info
.
Object
,
cmdutil
.
InternalVersionJSONEncoder
());
err
!=
nil
{
...
@@ -300,10 +301,10 @@ func (o *ExposeServiceOptions) RunExpose(f cmdutil.Factory, out io.Writer, cmd *
...
@@ -300,10 +301,10 @@ func (o *ExposeServiceOptions) RunExpose(f cmdutil.Factory, out io.Writer, cmd *
}
}
if
len
(
cmdutil
.
GetFlagString
(
cmd
,
"output"
))
>
0
{
if
len
(
cmdutil
.
GetFlagString
(
cmd
,
"output"
))
>
0
{
return
cmdutil
.
PrintObject
(
cmd
,
object
,
out
)
return
cmdutil
.
PrintObject
(
cmd
,
object
,
o
.
O
ut
)
}
}
cmdutil
.
PrintSuccess
(
false
,
out
,
info
.
Object
,
false
,
"exposed"
)
cmdutil
.
PrintSuccess
(
false
,
o
.
O
ut
,
info
.
Object
,
false
,
"exposed"
)
return
nil
return
nil
})
})
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/kubectl/cmd/expose_test.go
View file @
8c1b6873
...
@@ -17,7 +17,6 @@ limitations under the License.
...
@@ -17,7 +17,6 @@ limitations under the License.
package
cmd
package
cmd
import
(
import
(
"bytes"
"fmt"
"fmt"
"net/http"
"net/http"
"strings"
"strings"
...
@@ -31,6 +30,7 @@ import (
...
@@ -31,6 +30,7 @@ import (
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/api/legacyscheme"
api
"k8s.io/kubernetes/pkg/apis/core"
api
"k8s.io/kubernetes/pkg/apis/core"
cmdtesting
"k8s.io/kubernetes/pkg/kubectl/cmd/testing"
cmdtesting
"k8s.io/kubernetes/pkg/kubectl/cmd/testing"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
"k8s.io/kubernetes/pkg/kubectl/scheme"
"k8s.io/kubernetes/pkg/kubectl/scheme"
)
)
...
@@ -489,9 +489,9 @@ func TestRunExposeService(t *testing.T) {
...
@@ -489,9 +489,9 @@ func TestRunExposeService(t *testing.T) {
}),
}),
}
}
tf
.
Namespace
=
test
.
ns
tf
.
Namespace
=
test
.
ns
buf
:=
bytes
.
NewBuffer
([]
byte
{})
cmd
:=
NewCmdExposeService
(
tf
,
buf
)
ioStreams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdExposeService
(
tf
,
ioStreams
)
cmd
.
SetOutput
(
buf
)
cmd
.
SetOutput
(
buf
)
for
flag
,
value
:=
range
test
.
flags
{
for
flag
,
value
:=
range
test
.
flags
{
cmd
.
Flags
()
.
Set
(
flag
,
value
)
cmd
.
Flags
()
.
Set
(
flag
,
value
)
...
...
pkg/kubectl/cmd/resource/BUILD
View file @
8c1b6873
...
@@ -11,6 +11,7 @@ go_library(
...
@@ -11,6 +11,7 @@ go_library(
"//pkg/kubectl/cmd/templates:go_default_library",
"//pkg/kubectl/cmd/templates:go_default_library",
"//pkg/kubectl/cmd/util:go_default_library",
"//pkg/kubectl/cmd/util:go_default_library",
"//pkg/kubectl/cmd/util/openapi:go_default_library",
"//pkg/kubectl/cmd/util/openapi:go_default_library",
"//pkg/kubectl/genericclioptions:go_default_library",
"//pkg/kubectl/resource:go_default_library",
"//pkg/kubectl/resource:go_default_library",
"//pkg/kubectl/util/i18n:go_default_library",
"//pkg/kubectl/util/i18n:go_default_library",
"//pkg/printers:go_default_library",
"//pkg/printers:go_default_library",
...
@@ -50,6 +51,7 @@ go_test(
...
@@ -50,6 +51,7 @@ go_test(
"//pkg/kubectl/cmd/util:go_default_library",
"//pkg/kubectl/cmd/util:go_default_library",
"//pkg/kubectl/cmd/util/openapi:go_default_library",
"//pkg/kubectl/cmd/util/openapi:go_default_library",
"//pkg/kubectl/cmd/util/openapi/testing:go_default_library",
"//pkg/kubectl/cmd/util/openapi/testing:go_default_library",
"//pkg/kubectl/genericclioptions:go_default_library",
"//pkg/kubectl/scheme:go_default_library",
"//pkg/kubectl/scheme:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured:go_default_library",
...
...
pkg/kubectl/cmd/resource/get.go
View file @
8c1b6873
...
@@ -43,6 +43,7 @@ import (
...
@@ -43,6 +43,7 @@ import (
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi"
"k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/kubectl/util/i18n"
"k8s.io/kubernetes/pkg/kubectl/util/i18n"
"k8s.io/kubernetes/pkg/printers"
"k8s.io/kubernetes/pkg/printers"
...
@@ -51,8 +52,6 @@ import (
...
@@ -51,8 +52,6 @@ import (
// GetOptions contains the input to the get command.
// GetOptions contains the input to the get command.
type
GetOptions
struct
{
type
GetOptions
struct
{
Out
,
ErrOut
io
.
Writer
resource
.
FilenameOptions
resource
.
FilenameOptions
Raw
string
Raw
string
...
@@ -75,6 +74,8 @@ type GetOptions struct {
...
@@ -75,6 +74,8 @@ type GetOptions struct {
Export
bool
Export
bool
IncludeUninitialized
bool
IncludeUninitialized
bool
genericclioptions
.
IOStreams
}
}
var
(
var
(
...
@@ -126,18 +127,18 @@ const (
...
@@ -126,18 +127,18 @@ const (
)
)
// NewGetOptions returns a GetOptions with default chunk size 500.
// NewGetOptions returns a GetOptions with default chunk size 500.
func
NewGetOptions
(
out
io
.
Writer
,
errOut
io
.
Writer
)
*
GetOptions
{
func
NewGetOptions
(
streams
genericclioptions
.
IOStreams
)
*
GetOptions
{
return
&
GetOptions
{
return
&
GetOptions
{
Out
:
out
,
ErrOut
:
errOut
,
ChunkSize
:
500
,
ChunkSize
:
500
,
IOStreams
:
streams
,
}
}
}
}
// NewCmdGet creates a command object for the generic "get" action, which
// NewCmdGet creates a command object for the generic "get" action, which
// retrieves one or more resources from a server.
// retrieves one or more resources from a server.
func
NewCmdGet
(
f
cmdutil
.
Factory
,
out
io
.
Writer
,
errOut
io
.
Writer
)
*
cobra
.
Command
{
func
NewCmdGet
(
f
cmdutil
.
Factory
,
streams
genericclioptions
.
IOStreams
)
*
cobra
.
Command
{
options
:=
NewGetOptions
(
out
,
errOut
)
options
:=
NewGetOptions
(
streams
)
validArgs
:=
cmdutil
.
ValidArgList
(
f
)
validArgs
:=
cmdutil
.
ValidArgList
(
f
)
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
...
...
pkg/kubectl/cmd/resource/get_test.go
View file @
8c1b6873
This diff is collapsed.
Click to expand it.
pkg/kubectl/cmd/run.go
View file @
8c1b6873
...
@@ -118,12 +118,10 @@ type RunOptions struct {
...
@@ -118,12 +118,10 @@ type RunOptions struct {
Schedule
string
Schedule
string
TTY
bool
TTY
bool
In
io
.
Reader
genericclioptions
.
IOStreams
Out
io
.
Writer
ErrOut
io
.
Writer
}
}
func
NewRunOptions
(
in
io
.
Reader
,
out
,
errOut
io
.
Writer
)
*
RunOptions
{
func
NewRunOptions
(
streams
genericclioptions
.
IOStreams
)
*
RunOptions
{
return
&
RunOptions
{
return
&
RunOptions
{
PrintFlags
:
printers
.
NewPrintFlags
(
"created"
),
PrintFlags
:
printers
.
NewPrintFlags
(
"created"
),
DeleteFlags
:
NewDeleteFlags
(
"to use to replace the resource."
),
DeleteFlags
:
NewDeleteFlags
(
"to use to replace the resource."
),
...
@@ -131,14 +129,12 @@ func NewRunOptions(in io.Reader, out, errOut io.Writer) *RunOptions {
...
@@ -131,14 +129,12 @@ func NewRunOptions(in io.Reader, out, errOut io.Writer) *RunOptions {
Recorder
:
genericclioptions
.
NoopRecorder
{},
Recorder
:
genericclioptions
.
NoopRecorder
{},
In
:
in
,
IOStreams
:
streams
,
Out
:
out
,
ErrOut
:
errOut
,
}
}
}
}
func
NewCmdRun
(
f
cmdutil
.
Factory
,
in
io
.
Reader
,
out
,
errOut
io
.
Writer
)
*
cobra
.
Command
{
func
NewCmdRun
(
f
cmdutil
.
Factory
,
streams
genericclioptions
.
IOStreams
)
*
cobra
.
Command
{
o
:=
NewRunOptions
(
in
,
out
,
errOut
)
o
:=
NewRunOptions
(
streams
)
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"run NAME --image=image [--env=
\"
key=value
\"
] [--port=port] [--replicas=replicas] [--dry-run=bool] [--overrides=inline-json] [--command] -- [COMMAND] [args...]"
,
Use
:
"run NAME --image=image [--env=
\"
key=value
\"
] [--port=port] [--replicas=replicas] [--dry-run=bool] [--overrides=inline-json] [--command] -- [COMMAND] [args...]"
,
...
...
pkg/kubectl/cmd/run_test.go
View file @
8c1b6873
...
@@ -194,7 +194,7 @@ func TestRunArgsFollowDashRules(t *testing.T) {
...
@@ -194,7 +194,7 @@ func TestRunArgsFollowDashRules(t *testing.T) {
tf
.
Namespace
=
"test"
tf
.
Namespace
=
"test"
tf
.
ClientConfigVal
=
&
restclient
.
Config
{}
tf
.
ClientConfigVal
=
&
restclient
.
Config
{}
cmd
:=
NewCmdRun
(
tf
,
os
.
Stdin
,
os
.
Stdout
,
os
.
Stderr
)
cmd
:=
NewCmdRun
(
tf
,
genericclioptions
.
NewTestIOStreamsDiscard
()
)
cmd
.
Flags
()
.
Set
(
"image"
,
"nginx"
)
cmd
.
Flags
()
.
Set
(
"image"
,
"nginx"
)
cmd
.
Flags
()
.
Set
(
"generator"
,
"run/v1"
)
cmd
.
Flags
()
.
Set
(
"generator"
,
"run/v1"
)
...
@@ -210,9 +210,7 @@ func TestRunArgsFollowDashRules(t *testing.T) {
...
@@ -210,9 +210,7 @@ func TestRunArgsFollowDashRules(t *testing.T) {
PrintFlags
:
printFlags
,
PrintFlags
:
printFlags
,
DeleteOptions
:
deleteFlags
.
ToOptions
(
os
.
Stdout
,
os
.
Stderr
),
DeleteOptions
:
deleteFlags
.
ToOptions
(
os
.
Stdout
,
os
.
Stderr
),
In
:
os
.
Stdin
,
IOStreams
:
genericclioptions
.
NewTestIOStreamsDiscard
(),
Out
:
os
.
Stdout
,
ErrOut
:
os
.
Stderr
,
Image
:
"nginx"
,
Image
:
"nginx"
,
Generator
:
"run/v1"
,
Generator
:
"run/v1"
,
...
@@ -375,14 +373,13 @@ func TestGenerateService(t *testing.T) {
...
@@ -375,14 +373,13 @@ func TestGenerateService(t *testing.T) {
return
return
}
}
ioStreams
,
_
,
buff
,
_
:=
genericclioptions
.
NewTestIOStreams
()
deleteFlags
:=
NewDeleteFlags
(
"to use to replace the resource."
)
deleteFlags
:=
NewDeleteFlags
(
"to use to replace the resource."
)
buff
:=
&
bytes
.
Buffer
{}
opts
:=
&
RunOptions
{
opts
:=
&
RunOptions
{
PrintFlags
:
printFlags
,
PrintFlags
:
printFlags
,
DeleteOptions
:
deleteFlags
.
ToOptions
(
os
.
Stdout
,
os
.
Stderr
),
DeleteOptions
:
deleteFlags
.
ToOptions
(
os
.
Stdout
,
os
.
Stderr
),
Out
:
buff
,
IOStreams
:
ioStreams
,
ErrOut
:
buff
,
Port
:
test
.
port
,
Port
:
test
.
port
,
Recorder
:
genericclioptions
.
NoopRecorder
{},
Recorder
:
genericclioptions
.
NoopRecorder
{},
...
@@ -519,19 +516,17 @@ func TestRunValidations(t *testing.T) {
...
@@ -519,19 +516,17 @@ func TestRunValidations(t *testing.T) {
}
}
tf
.
Namespace
=
"test"
tf
.
Namespace
=
"test"
tf
.
ClientConfigVal
=
defaultClientConfig
()
tf
.
ClientConfigVal
=
defaultClientConfig
()
inBuf
:=
bytes
.
NewReader
([]
byte
{})
outBuf
:=
bytes
.
NewBuffer
([]
byte
{})
errBuf
:=
bytes
.
NewBuffer
([]
byte
{})
cmd
:=
NewCmdRun
(
tf
,
inBuf
,
outBuf
,
errBuf
)
streams
,
_
,
_
,
bufErr
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdRun
(
tf
,
streams
)
for
flagName
,
flagValue
:=
range
test
.
flags
{
for
flagName
,
flagValue
:=
range
test
.
flags
{
cmd
.
Flags
()
.
Set
(
flagName
,
flagValue
)
cmd
.
Flags
()
.
Set
(
flagName
,
flagValue
)
}
}
cmd
.
Run
(
cmd
,
test
.
args
)
cmd
.
Run
(
cmd
,
test
.
args
)
var
err
error
var
err
error
if
errBuf
.
Len
()
>
0
{
if
bufErr
.
Len
()
>
0
{
err
=
fmt
.
Errorf
(
"%v"
,
errBuf
.
String
())
err
=
fmt
.
Errorf
(
"%v"
,
bufErr
.
String
())
}
}
if
err
!=
nil
&&
len
(
test
.
expectedErr
)
>
0
{
if
err
!=
nil
&&
len
(
test
.
expectedErr
)
>
0
{
if
!
strings
.
Contains
(
err
.
Error
(),
test
.
expectedErr
)
{
if
!
strings
.
Contains
(
err
.
Error
(),
test
.
expectedErr
)
{
...
...
pkg/kubectl/cmd/set/BUILD
View file @
8c1b6873
...
@@ -66,6 +66,7 @@ go_test(
...
@@ -66,6 +66,7 @@ go_test(
"//pkg/apis/rbac:go_default_library",
"//pkg/apis/rbac:go_default_library",
"//pkg/kubectl/cmd/testing:go_default_library",
"//pkg/kubectl/cmd/testing:go_default_library",
"//pkg/kubectl/cmd/util:go_default_library",
"//pkg/kubectl/cmd/util:go_default_library",
"//pkg/kubectl/genericclioptions:go_default_library",
"//pkg/kubectl/resource:go_default_library",
"//pkg/kubectl/resource:go_default_library",
"//pkg/kubectl/scheme:go_default_library",
"//pkg/kubectl/scheme:go_default_library",
"//pkg/printers:go_default_library",
"//pkg/printers:go_default_library",
...
...
pkg/kubectl/cmd/set/set.go
View file @
8c1b6873
...
@@ -17,11 +17,10 @@ limitations under the License.
...
@@ -17,11 +17,10 @@ limitations under the License.
package
set
package
set
import
(
import
(
"io"
"github.com/spf13/cobra"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
"k8s.io/kubernetes/pkg/kubectl/util/i18n"
"k8s.io/kubernetes/pkg/kubectl/util/i18n"
)
)
...
@@ -32,22 +31,22 @@ var (
...
@@ -32,22 +31,22 @@ var (
These commands help you make changes to existing application resources.`
)
These commands help you make changes to existing application resources.`
)
)
)
func
NewCmdSet
(
f
cmdutil
.
Factory
,
in
io
.
Reader
,
out
,
err
io
.
Writer
)
*
cobra
.
Command
{
func
NewCmdSet
(
f
cmdutil
.
Factory
,
streams
genericclioptions
.
IOStreams
)
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"set SUBCOMMAND"
,
Use
:
"set SUBCOMMAND"
,
DisableFlagsInUseLine
:
true
,
DisableFlagsInUseLine
:
true
,
Short
:
i18n
.
T
(
"Set specific features on objects"
),
Short
:
i18n
.
T
(
"Set specific features on objects"
),
Long
:
set_long
,
Long
:
set_long
,
Run
:
cmdutil
.
DefaultSubCommandRun
(
err
),
Run
:
cmdutil
.
DefaultSubCommandRun
(
streams
.
ErrOut
),
}
}
// add subcommands
// add subcommands
cmd
.
AddCommand
(
NewCmdImage
(
f
,
out
,
err
))
cmd
.
AddCommand
(
NewCmdImage
(
f
,
streams
))
cmd
.
AddCommand
(
NewCmdResources
(
f
,
out
,
err
))
cmd
.
AddCommand
(
NewCmdResources
(
f
,
streams
))
cmd
.
AddCommand
(
NewCmdSelector
(
f
,
out
))
cmd
.
AddCommand
(
NewCmdSelector
(
f
,
streams
))
cmd
.
AddCommand
(
NewCmdSubject
(
f
,
out
,
err
))
cmd
.
AddCommand
(
NewCmdSubject
(
f
,
streams
))
cmd
.
AddCommand
(
NewCmdServiceAccount
(
f
,
out
,
err
))
cmd
.
AddCommand
(
NewCmdServiceAccount
(
f
,
streams
))
cmd
.
AddCommand
(
NewCmdEnv
(
f
,
in
,
out
,
err
))
cmd
.
AddCommand
(
NewCmdEnv
(
f
,
streams
))
return
cmd
return
cmd
}
}
pkg/kubectl/cmd/set/set_env.go
View file @
8c1b6873
...
@@ -19,7 +19,6 @@ package set
...
@@ -19,7 +19,6 @@ package set
import
(
import
(
"errors"
"errors"
"fmt"
"fmt"
"io"
"regexp"
"regexp"
"sort"
"sort"
"strings"
"strings"
...
@@ -36,6 +35,7 @@ import (
...
@@ -36,6 +35,7 @@ import (
"k8s.io/kubernetes/pkg/printers"
"k8s.io/kubernetes/pkg/printers"
utilerrors
"k8s.io/apimachinery/pkg/util/errors"
utilerrors
"k8s.io/apimachinery/pkg/util/errors"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
)
)
var
(
var
(
...
@@ -94,10 +94,6 @@ var (
...
@@ -94,10 +94,6 @@ var (
type
EnvOptions
struct
{
type
EnvOptions
struct
{
PrintFlags
*
printers
.
PrintFlags
PrintFlags
*
printers
.
PrintFlags
Out
io
.
Writer
Err
io
.
Writer
In
io
.
Reader
resource
.
FilenameOptions
resource
.
FilenameOptions
EnvParams
[]
string
EnvParams
[]
string
EnvArgs
[]
string
EnvArgs
[]
string
...
@@ -123,25 +119,26 @@ type EnvOptions struct {
...
@@ -123,25 +119,26 @@ type EnvOptions struct {
Infos
[]
*
resource
.
Info
Infos
[]
*
resource
.
Info
UpdatePodSpecForObject
func
(
obj
runtime
.
Object
,
fn
func
(
*
v1
.
PodSpec
)
error
)
(
bool
,
error
)
UpdatePodSpecForObject
func
(
obj
runtime
.
Object
,
fn
func
(
*
v1
.
PodSpec
)
error
)
(
bool
,
error
)
genericclioptions
.
IOStreams
}
}
// NewEnvOptions returns an EnvOptions indicating all containers in the selected
// NewEnvOptions returns an EnvOptions indicating all containers in the selected
// pod templates are selected by default and allowing environment to be overwritten
// pod templates are selected by default and allowing environment to be overwritten
func
NewEnvOptions
(
in
io
.
Reader
,
out
,
errout
io
.
Writer
)
*
EnvOptions
{
func
NewEnvOptions
(
streams
genericclioptions
.
IOStreams
)
*
EnvOptions
{
return
&
EnvOptions
{
return
&
EnvOptions
{
PrintFlags
:
printers
.
NewPrintFlags
(
"env updated"
),
PrintFlags
:
printers
.
NewPrintFlags
(
"env updated"
),
Out
:
out
,
Err
:
errout
,
In
:
in
,
ContainerSelector
:
"*"
,
ContainerSelector
:
"*"
,
Overwrite
:
true
,
Overwrite
:
true
,
IOStreams
:
streams
,
}
}
}
}
// NewCmdEnv implements the OpenShift cli env command
// NewCmdEnv implements the OpenShift cli env command
func
NewCmdEnv
(
f
cmdutil
.
Factory
,
in
io
.
Reader
,
out
,
errout
io
.
Writer
)
*
cobra
.
Command
{
func
NewCmdEnv
(
f
cmdutil
.
Factory
,
streams
genericclioptions
.
IOStreams
)
*
cobra
.
Command
{
options
:=
NewEnvOptions
(
in
,
out
,
errout
)
options
:=
NewEnvOptions
(
streams
)
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"env RESOURCE/NAME KEY_1=VAL_1 ... KEY_N=VAL_N"
,
Use
:
"env RESOURCE/NAME KEY_1=VAL_1 ... KEY_N=VAL_N"
,
DisableFlagsInUseLine
:
true
,
DisableFlagsInUseLine
:
true
,
...
@@ -346,7 +343,7 @@ func (o *EnvOptions) RunEnv(f cmdutil.Factory) error {
...
@@ -346,7 +343,7 @@ func (o *EnvOptions) RunEnv(f cmdutil.Factory) error {
resolutionErrorsEncountered
:=
false
resolutionErrorsEncountered
:=
false
containers
,
_
:=
selectContainers
(
spec
.
Containers
,
o
.
ContainerSelector
)
containers
,
_
:=
selectContainers
(
spec
.
Containers
,
o
.
ContainerSelector
)
if
len
(
containers
)
==
0
{
if
len
(
containers
)
==
0
{
fmt
.
Fprintf
(
o
.
Err
,
"warning: %s/%s does not have any containers matching %q
\n
"
,
info
.
Mapping
.
Resource
,
info
.
Name
,
o
.
ContainerSelector
)
fmt
.
Fprintf
(
o
.
Err
Out
,
"warning: %s/%s does not have any containers matching %q
\n
"
,
info
.
Mapping
.
Resource
,
info
.
Name
,
o
.
ContainerSelector
)
return
nil
return
nil
}
}
for
_
,
c
:=
range
containers
{
for
_
,
c
:=
range
containers
{
...
@@ -397,7 +394,7 @@ func (o *EnvOptions) RunEnv(f cmdutil.Factory) error {
...
@@ -397,7 +394,7 @@ func (o *EnvOptions) RunEnv(f cmdutil.Factory) error {
}
}
sort
.
Strings
(
errs
)
sort
.
Strings
(
errs
)
for
_
,
err
:=
range
errs
{
for
_
,
err
:=
range
errs
{
fmt
.
Fprintln
(
o
.
Err
,
err
)
fmt
.
Fprintln
(
o
.
Err
Out
,
err
)
}
}
}
}
}
}
...
...
pkg/kubectl/cmd/set/set_env_test.go
View file @
8c1b6873
...
@@ -17,11 +17,9 @@ limitations under the License.
...
@@ -17,11 +17,9 @@ limitations under the License.
package
set
package
set
import
(
import
(
"bytes"
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"net/http"
"net/http"
"os"
"path"
"path"
"strings"
"strings"
"testing"
"testing"
...
@@ -43,6 +41,7 @@ import (
...
@@ -43,6 +41,7 @@ import (
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/testapi"
cmdtesting
"k8s.io/kubernetes/pkg/kubectl/cmd/testing"
cmdtesting
"k8s.io/kubernetes/pkg/kubectl/cmd/testing"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/kubectl/scheme"
"k8s.io/kubernetes/pkg/kubectl/scheme"
)
)
...
@@ -65,8 +64,8 @@ func TestSetEnvLocal(t *testing.T) {
...
@@ -65,8 +64,8 @@ func TestSetEnvLocal(t *testing.T) {
outputFormat
:=
"name"
outputFormat
:=
"name"
buf
:=
bytes
.
NewBuffer
([]
byte
{}
)
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
(
)
cmd
:=
NewCmdEnv
(
tf
,
os
.
Stdin
,
buf
,
buf
)
cmd
:=
NewCmdEnv
(
tf
,
streams
)
cmd
.
SetOutput
(
buf
)
cmd
.
SetOutput
(
buf
)
cmd
.
Flags
()
.
Set
(
"output"
,
outputFormat
)
cmd
.
Flags
()
.
Set
(
"output"
,
outputFormat
)
cmd
.
Flags
()
.
Set
(
"local"
,
"true"
)
cmd
.
Flags
()
.
Set
(
"local"
,
"true"
)
...
@@ -80,8 +79,8 @@ func TestSetEnvLocal(t *testing.T) {
...
@@ -80,8 +79,8 @@ func TestSetEnvLocal(t *testing.T) {
},
},
FilenameOptions
:
resource
.
FilenameOptions
{
FilenameOptions
:
resource
.
FilenameOptions
{
Filenames
:
[]
string
{
"../../../../test/e2e/testing-manifests/statefulset/cassandra/controller.yaml"
}},
Filenames
:
[]
string
{
"../../../../test/e2e/testing-manifests/statefulset/cassandra/controller.yaml"
}},
Out
:
buf
,
Local
:
true
,
Local
:
true
,
IOStreams
:
streams
,
}
}
err
:=
opts
.
Complete
(
tf
,
cmd
,
[]
string
{
"env=prod"
})
err
:=
opts
.
Complete
(
tf
,
cmd
,
[]
string
{
"env=prod"
})
if
err
==
nil
{
if
err
==
nil
{
...
@@ -114,8 +113,8 @@ func TestSetMultiResourcesEnvLocal(t *testing.T) {
...
@@ -114,8 +113,8 @@ func TestSetMultiResourcesEnvLocal(t *testing.T) {
outputFormat
:=
"name"
outputFormat
:=
"name"
buf
:=
bytes
.
NewBuffer
([]
byte
{}
)
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
(
)
cmd
:=
NewCmdEnv
(
tf
,
os
.
Stdin
,
buf
,
buf
)
cmd
:=
NewCmdEnv
(
tf
,
streams
)
cmd
.
SetOutput
(
buf
)
cmd
.
SetOutput
(
buf
)
cmd
.
Flags
()
.
Set
(
"output"
,
outputFormat
)
cmd
.
Flags
()
.
Set
(
"output"
,
outputFormat
)
cmd
.
Flags
()
.
Set
(
"local"
,
"true"
)
cmd
.
Flags
()
.
Set
(
"local"
,
"true"
)
...
@@ -129,8 +128,8 @@ func TestSetMultiResourcesEnvLocal(t *testing.T) {
...
@@ -129,8 +128,8 @@ func TestSetMultiResourcesEnvLocal(t *testing.T) {
},
},
FilenameOptions
:
resource
.
FilenameOptions
{
FilenameOptions
:
resource
.
FilenameOptions
{
Filenames
:
[]
string
{
"../../../../test/fixtures/pkg/kubectl/cmd/set/multi-resource-yaml.yaml"
}},
Filenames
:
[]
string
{
"../../../../test/fixtures/pkg/kubectl/cmd/set/multi-resource-yaml.yaml"
}},
Out
:
buf
,
Local
:
true
,
Local
:
true
,
IOStreams
:
streams
,
}
}
err
:=
opts
.
Complete
(
tf
,
cmd
,
[]
string
{
"env=prod"
})
err
:=
opts
.
Complete
(
tf
,
cmd
,
[]
string
{
"env=prod"
})
if
err
==
nil
{
if
err
==
nil
{
...
@@ -507,9 +506,8 @@ func TestSetEnvRemote(t *testing.T) {
...
@@ -507,9 +506,8 @@ func TestSetEnvRemote(t *testing.T) {
outputFormat
:=
"yaml"
outputFormat
:=
"yaml"
out
:=
new
(
bytes
.
Buffer
)
streams
:=
genericclioptions
.
NewTestIOStreamsDiscard
()
cmd
:=
NewCmdEnv
(
tf
,
out
,
out
,
out
)
cmd
:=
NewCmdEnv
(
tf
,
streams
)
cmd
.
SetOutput
(
out
)
cmd
.
Flags
()
.
Set
(
"output"
,
outputFormat
)
cmd
.
Flags
()
.
Set
(
"output"
,
outputFormat
)
opts
:=
EnvOptions
{
opts
:=
EnvOptions
{
PrintFlags
:
&
printers
.
PrintFlags
{
PrintFlags
:
&
printers
.
PrintFlags
{
...
@@ -518,8 +516,9 @@ func TestSetEnvRemote(t *testing.T) {
...
@@ -518,8 +516,9 @@ func TestSetEnvRemote(t *testing.T) {
OutputFormat
:
&
outputFormat
,
OutputFormat
:
&
outputFormat
,
},
},
Out
:
out
,
Local
:
false
,
Local
:
false
}
IOStreams
:
streams
,
}
err
:=
opts
.
Complete
(
tf
,
cmd
,
input
.
args
)
err
:=
opts
.
Complete
(
tf
,
cmd
,
input
.
args
)
assert
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
err
=
opts
.
RunEnv
(
tf
)
err
=
opts
.
RunEnv
(
tf
)
...
...
pkg/kubectl/cmd/set/set_image.go
View file @
8c1b6873
...
@@ -18,7 +18,6 @@ package set
...
@@ -18,7 +18,6 @@ package set
import
(
import
(
"fmt"
"fmt"
"io"
"k8s.io/kubernetes/pkg/printers"
"k8s.io/kubernetes/pkg/printers"
...
@@ -45,8 +44,6 @@ type SetImageOptions struct {
...
@@ -45,8 +44,6 @@ type SetImageOptions struct {
Infos
[]
*
resource
.
Info
Infos
[]
*
resource
.
Info
Selector
string
Selector
string
Out
io
.
Writer
Err
io
.
Writer
DryRun
bool
DryRun
bool
All
bool
All
bool
Output
string
Output
string
...
@@ -59,6 +56,8 @@ type SetImageOptions struct {
...
@@ -59,6 +56,8 @@ type SetImageOptions struct {
UpdatePodSpecForObject
func
(
obj
runtime
.
Object
,
fn
func
(
*
v1
.
PodSpec
)
error
)
(
bool
,
error
)
UpdatePodSpecForObject
func
(
obj
runtime
.
Object
,
fn
func
(
*
v1
.
PodSpec
)
error
)
(
bool
,
error
)
Resources
[]
string
Resources
[]
string
ContainerImages
map
[
string
]
string
ContainerImages
map
[
string
]
string
genericclioptions
.
IOStreams
}
}
var
(
var
(
...
@@ -85,20 +84,19 @@ var (
...
@@ -85,20 +84,19 @@ var (
kubectl set image -f path/to/file.yaml nginx=nginx:1.9.1 --local -o yaml`
)
kubectl set image -f path/to/file.yaml nginx=nginx:1.9.1 --local -o yaml`
)
)
)
func
NewImageOptions
(
out
,
errOut
io
.
Writer
)
*
SetImageOptions
{
func
NewImageOptions
(
streams
genericclioptions
.
IOStreams
)
*
SetImageOptions
{
return
&
SetImageOptions
{
return
&
SetImageOptions
{
PrintFlags
:
printers
.
NewPrintFlags
(
"image updated"
),
PrintFlags
:
printers
.
NewPrintFlags
(
"image updated"
),
RecordFlags
:
genericclioptions
.
NewRecordFlags
(),
RecordFlags
:
genericclioptions
.
NewRecordFlags
(),
Recorder
:
genericclioptions
.
NoopRecorder
{},
Recorder
:
genericclioptions
.
NoopRecorder
{},
Out
:
out
,
IOStreams
:
streams
,
Err
:
errOut
,
}
}
}
}
func
NewCmdImage
(
f
cmdutil
.
Factory
,
out
,
errOut
io
.
Writer
)
*
cobra
.
Command
{
func
NewCmdImage
(
f
cmdutil
.
Factory
,
streams
genericclioptions
.
IOStreams
)
*
cobra
.
Command
{
o
:=
NewImageOptions
(
out
,
errOut
)
o
:=
NewImageOptions
(
streams
)
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"image (-f FILENAME | TYPE NAME) CONTAINER_NAME_1=CONTAINER_IMAGE_1 ... CONTAINER_NAME_N=CONTAINER_IMAGE_N"
,
Use
:
"image (-f FILENAME | TYPE NAME) CONTAINER_NAME_1=CONTAINER_IMAGE_1 ... CONTAINER_NAME_N=CONTAINER_IMAGE_N"
,
...
...
pkg/kubectl/cmd/set/set_image_test.go
View file @
8c1b6873
...
@@ -17,7 +17,6 @@ limitations under the License.
...
@@ -17,7 +17,6 @@ limitations under the License.
package
set
package
set
import
(
import
(
"bytes"
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"net/http"
"net/http"
...
@@ -42,6 +41,7 @@ import (
...
@@ -42,6 +41,7 @@ import (
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/testapi"
cmdtesting
"k8s.io/kubernetes/pkg/kubectl/cmd/testing"
cmdtesting
"k8s.io/kubernetes/pkg/kubectl/cmd/testing"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/kubectl/scheme"
"k8s.io/kubernetes/pkg/kubectl/scheme"
)
)
...
@@ -65,8 +65,8 @@ func TestImageLocal(t *testing.T) {
...
@@ -65,8 +65,8 @@ func TestImageLocal(t *testing.T) {
outputFormat
:=
"name"
outputFormat
:=
"name"
buf
:=
bytes
.
NewBuffer
([]
byte
{}
)
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
(
)
cmd
:=
NewCmdImage
(
tf
,
buf
,
buf
)
cmd
:=
NewCmdImage
(
tf
,
streams
)
cmd
.
SetOutput
(
buf
)
cmd
.
SetOutput
(
buf
)
cmd
.
Flags
()
.
Set
(
"output"
,
outputFormat
)
cmd
.
Flags
()
.
Set
(
"output"
,
outputFormat
)
cmd
.
Flags
()
.
Set
(
"local"
,
"true"
)
cmd
.
Flags
()
.
Set
(
"local"
,
"true"
)
...
@@ -80,8 +80,9 @@ func TestImageLocal(t *testing.T) {
...
@@ -80,8 +80,9 @@ func TestImageLocal(t *testing.T) {
},
},
FilenameOptions
:
resource
.
FilenameOptions
{
FilenameOptions
:
resource
.
FilenameOptions
{
Filenames
:
[]
string
{
"../../../../test/e2e/testing-manifests/statefulset/cassandra/controller.yaml"
}},
Filenames
:
[]
string
{
"../../../../test/e2e/testing-manifests/statefulset/cassandra/controller.yaml"
}},
Out
:
buf
,
Local
:
true
,
Local
:
true
}
IOStreams
:
streams
,
}
err
:=
opts
.
Complete
(
tf
,
cmd
,
[]
string
{
"cassandra=thingy"
})
err
:=
opts
.
Complete
(
tf
,
cmd
,
[]
string
{
"cassandra=thingy"
})
if
err
==
nil
{
if
err
==
nil
{
err
=
opts
.
Validate
()
err
=
opts
.
Validate
()
...
@@ -187,8 +188,8 @@ func TestSetMultiResourcesImageLocal(t *testing.T) {
...
@@ -187,8 +188,8 @@ func TestSetMultiResourcesImageLocal(t *testing.T) {
outputFormat
:=
"name"
outputFormat
:=
"name"
buf
:=
bytes
.
NewBuffer
([]
byte
{}
)
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
(
)
cmd
:=
NewCmdImage
(
tf
,
buf
,
buf
)
cmd
:=
NewCmdImage
(
tf
,
streams
)
cmd
.
SetOutput
(
buf
)
cmd
.
SetOutput
(
buf
)
cmd
.
Flags
()
.
Set
(
"output"
,
outputFormat
)
cmd
.
Flags
()
.
Set
(
"output"
,
outputFormat
)
cmd
.
Flags
()
.
Set
(
"local"
,
"true"
)
cmd
.
Flags
()
.
Set
(
"local"
,
"true"
)
...
@@ -202,8 +203,9 @@ func TestSetMultiResourcesImageLocal(t *testing.T) {
...
@@ -202,8 +203,9 @@ func TestSetMultiResourcesImageLocal(t *testing.T) {
},
},
FilenameOptions
:
resource
.
FilenameOptions
{
FilenameOptions
:
resource
.
FilenameOptions
{
Filenames
:
[]
string
{
"../../../../test/fixtures/pkg/kubectl/cmd/set/multi-resource-yaml.yaml"
}},
Filenames
:
[]
string
{
"../../../../test/fixtures/pkg/kubectl/cmd/set/multi-resource-yaml.yaml"
}},
Out
:
buf
,
Local
:
true
,
Local
:
true
}
IOStreams
:
streams
,
}
err
:=
opts
.
Complete
(
tf
,
cmd
,
[]
string
{
"*=thingy"
})
err
:=
opts
.
Complete
(
tf
,
cmd
,
[]
string
{
"*=thingy"
})
if
err
==
nil
{
if
err
==
nil
{
err
=
opts
.
Validate
()
err
=
opts
.
Validate
()
...
@@ -583,9 +585,8 @@ func TestSetImageRemote(t *testing.T) {
...
@@ -583,9 +585,8 @@ func TestSetImageRemote(t *testing.T) {
outputFormat
:=
"yaml"
outputFormat
:=
"yaml"
out
:=
new
(
bytes
.
Buffer
)
streams
:=
genericclioptions
.
NewTestIOStreamsDiscard
()
cmd
:=
NewCmdImage
(
tf
,
out
,
out
)
cmd
:=
NewCmdImage
(
tf
,
streams
)
cmd
.
SetOutput
(
out
)
cmd
.
Flags
()
.
Set
(
"output"
,
outputFormat
)
cmd
.
Flags
()
.
Set
(
"output"
,
outputFormat
)
opts
:=
SetImageOptions
{
opts
:=
SetImageOptions
{
PrintFlags
:
&
printers
.
PrintFlags
{
PrintFlags
:
&
printers
.
PrintFlags
{
...
@@ -595,8 +596,9 @@ func TestSetImageRemote(t *testing.T) {
...
@@ -595,8 +596,9 @@ func TestSetImageRemote(t *testing.T) {
OutputFormat
:
&
outputFormat
,
OutputFormat
:
&
outputFormat
,
},
},
Out
:
out
,
Local
:
false
,
Local
:
false
}
IOStreams
:
streams
,
}
err
:=
opts
.
Complete
(
tf
,
cmd
,
input
.
args
)
err
:=
opts
.
Complete
(
tf
,
cmd
,
input
.
args
)
assert
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
err
=
opts
.
Run
()
err
=
opts
.
Run
()
...
...
pkg/kubectl/cmd/set/set_resources.go
View file @
8c1b6873
...
@@ -18,7 +18,6 @@ package set
...
@@ -18,7 +18,6 @@ package set
import
(
import
(
"fmt"
"fmt"
"io"
"strings"
"strings"
"k8s.io/kubernetes/pkg/printers"
"k8s.io/kubernetes/pkg/printers"
...
@@ -69,8 +68,6 @@ type SetResourcesOptions struct {
...
@@ -69,8 +68,6 @@ type SetResourcesOptions struct {
RecordFlags
*
genericclioptions
.
RecordFlags
RecordFlags
*
genericclioptions
.
RecordFlags
Infos
[]
*
resource
.
Info
Infos
[]
*
resource
.
Info
Out
io
.
Writer
Err
io
.
Writer
Selector
string
Selector
string
ContainerSelector
string
ContainerSelector
string
Output
string
Output
string
...
@@ -88,25 +85,27 @@ type SetResourcesOptions struct {
...
@@ -88,25 +85,27 @@ type SetResourcesOptions struct {
UpdatePodSpecForObject
func
(
obj
runtime
.
Object
,
fn
func
(
*
v1
.
PodSpec
)
error
)
(
bool
,
error
)
UpdatePodSpecForObject
func
(
obj
runtime
.
Object
,
fn
func
(
*
v1
.
PodSpec
)
error
)
(
bool
,
error
)
Resources
[]
string
Resources
[]
string
genericclioptions
.
IOStreams
}
}
// NewResourcesOptions returns a ResourcesOptions indicating all containers in the selected
// NewResourcesOptions returns a ResourcesOptions indicating all containers in the selected
// pod templates are selected by default.
// pod templates are selected by default.
func
NewResourcesOptions
(
out
io
.
Writer
,
errOut
io
.
Writer
)
*
SetResourcesOptions
{
func
NewResourcesOptions
(
streams
genericclioptions
.
IOStreams
)
*
SetResourcesOptions
{
return
&
SetResourcesOptions
{
return
&
SetResourcesOptions
{
PrintFlags
:
printers
.
NewPrintFlags
(
"resource requirements updated"
),
PrintFlags
:
printers
.
NewPrintFlags
(
"resource requirements updated"
),
RecordFlags
:
genericclioptions
.
NewRecordFlags
(),
RecordFlags
:
genericclioptions
.
NewRecordFlags
(),
Recorder
:
genericclioptions
.
NoopRecorder
{},
Recorder
:
genericclioptions
.
NoopRecorder
{},
Out
:
out
,
Err
:
errOut
,
ContainerSelector
:
"*"
,
ContainerSelector
:
"*"
,
IOStreams
:
streams
,
}
}
}
}
func
NewCmdResources
(
f
cmdutil
.
Factory
,
out
io
.
Writer
,
errOut
io
.
Writer
)
*
cobra
.
Command
{
func
NewCmdResources
(
f
cmdutil
.
Factory
,
streams
genericclioptions
.
IOStreams
)
*
cobra
.
Command
{
o
:=
NewResourcesOptions
(
out
,
errOut
)
o
:=
NewResourcesOptions
(
streams
)
resourceTypesWithPodTemplate
:=
[]
string
{}
resourceTypesWithPodTemplate
:=
[]
string
{}
for
_
,
resource
:=
range
f
.
SuggestedPodTemplateResources
()
{
for
_
,
resource
:=
range
f
.
SuggestedPodTemplateResources
()
{
...
...
pkg/kubectl/cmd/set/set_resources_test.go
View file @
8c1b6873
...
@@ -17,7 +17,6 @@ limitations under the License.
...
@@ -17,7 +17,6 @@ limitations under the License.
package
set
package
set
import
(
import
(
"bytes"
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"net/http"
"net/http"
...
@@ -42,6 +41,7 @@ import (
...
@@ -42,6 +41,7 @@ import (
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/testapi"
cmdtesting
"k8s.io/kubernetes/pkg/kubectl/cmd/testing"
cmdtesting
"k8s.io/kubernetes/pkg/kubectl/cmd/testing"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/kubectl/scheme"
"k8s.io/kubernetes/pkg/kubectl/scheme"
)
)
...
@@ -64,8 +64,8 @@ func TestResourcesLocal(t *testing.T) {
...
@@ -64,8 +64,8 @@ func TestResourcesLocal(t *testing.T) {
outputFormat
:=
"name"
outputFormat
:=
"name"
buf
:=
bytes
.
NewBuffer
([]
byte
{}
)
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
(
)
cmd
:=
NewCmdResources
(
tf
,
buf
,
buf
)
cmd
:=
NewCmdResources
(
tf
,
streams
)
cmd
.
SetOutput
(
buf
)
cmd
.
SetOutput
(
buf
)
cmd
.
Flags
()
.
Set
(
"output"
,
outputFormat
)
cmd
.
Flags
()
.
Set
(
"output"
,
outputFormat
)
cmd
.
Flags
()
.
Set
(
"local"
,
"true"
)
cmd
.
Flags
()
.
Set
(
"local"
,
"true"
)
...
@@ -79,11 +79,12 @@ func TestResourcesLocal(t *testing.T) {
...
@@ -79,11 +79,12 @@ func TestResourcesLocal(t *testing.T) {
},
},
FilenameOptions
:
resource
.
FilenameOptions
{
FilenameOptions
:
resource
.
FilenameOptions
{
Filenames
:
[]
string
{
"../../../../test/e2e/testing-manifests/statefulset/cassandra/controller.yaml"
}},
Filenames
:
[]
string
{
"../../../../test/e2e/testing-manifests/statefulset/cassandra/controller.yaml"
}},
Out
:
buf
,
Local
:
true
,
Local
:
true
,
Limits
:
"cpu=200m,memory=512Mi"
,
Limits
:
"cpu=200m,memory=512Mi"
,
Requests
:
"cpu=200m,memory=512Mi"
,
Requests
:
"cpu=200m,memory=512Mi"
,
ContainerSelector
:
"*"
}
ContainerSelector
:
"*"
,
IOStreams
:
streams
,
}
err
:=
opts
.
Complete
(
tf
,
cmd
,
[]
string
{})
err
:=
opts
.
Complete
(
tf
,
cmd
,
[]
string
{})
if
err
==
nil
{
if
err
==
nil
{
...
@@ -118,8 +119,8 @@ func TestSetMultiResourcesLimitsLocal(t *testing.T) {
...
@@ -118,8 +119,8 @@ func TestSetMultiResourcesLimitsLocal(t *testing.T) {
outputFormat
:=
"name"
outputFormat
:=
"name"
buf
:=
bytes
.
NewBuffer
([]
byte
{}
)
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
(
)
cmd
:=
NewCmdResources
(
tf
,
buf
,
buf
)
cmd
:=
NewCmdResources
(
tf
,
streams
)
cmd
.
SetOutput
(
buf
)
cmd
.
SetOutput
(
buf
)
cmd
.
Flags
()
.
Set
(
"output"
,
outputFormat
)
cmd
.
Flags
()
.
Set
(
"output"
,
outputFormat
)
cmd
.
Flags
()
.
Set
(
"local"
,
"true"
)
cmd
.
Flags
()
.
Set
(
"local"
,
"true"
)
...
@@ -133,11 +134,12 @@ func TestSetMultiResourcesLimitsLocal(t *testing.T) {
...
@@ -133,11 +134,12 @@ func TestSetMultiResourcesLimitsLocal(t *testing.T) {
},
},
FilenameOptions
:
resource
.
FilenameOptions
{
FilenameOptions
:
resource
.
FilenameOptions
{
Filenames
:
[]
string
{
"../../../../test/fixtures/pkg/kubectl/cmd/set/multi-resource-yaml.yaml"
}},
Filenames
:
[]
string
{
"../../../../test/fixtures/pkg/kubectl/cmd/set/multi-resource-yaml.yaml"
}},
Out
:
buf
,
Local
:
true
,
Local
:
true
,
Limits
:
"cpu=200m,memory=512Mi"
,
Limits
:
"cpu=200m,memory=512Mi"
,
Requests
:
"cpu=200m,memory=512Mi"
,
Requests
:
"cpu=200m,memory=512Mi"
,
ContainerSelector
:
"*"
}
ContainerSelector
:
"*"
,
IOStreams
:
streams
,
}
err
:=
opts
.
Complete
(
tf
,
cmd
,
[]
string
{})
err
:=
opts
.
Complete
(
tf
,
cmd
,
[]
string
{})
if
err
==
nil
{
if
err
==
nil
{
...
@@ -501,9 +503,8 @@ func TestSetResourcesRemote(t *testing.T) {
...
@@ -501,9 +503,8 @@ func TestSetResourcesRemote(t *testing.T) {
outputFormat
:=
"yaml"
outputFormat
:=
"yaml"
buf
:=
new
(
bytes
.
Buffer
)
streams
:=
genericclioptions
.
NewTestIOStreamsDiscard
()
cmd
:=
NewCmdResources
(
tf
,
buf
,
buf
)
cmd
:=
NewCmdResources
(
tf
,
streams
)
cmd
.
SetOutput
(
buf
)
cmd
.
Flags
()
.
Set
(
"output"
,
outputFormat
)
cmd
.
Flags
()
.
Set
(
"output"
,
outputFormat
)
opts
:=
SetResourcesOptions
{
opts
:=
SetResourcesOptions
{
PrintFlags
:
&
printers
.
PrintFlags
{
PrintFlags
:
&
printers
.
PrintFlags
{
...
@@ -513,9 +514,10 @@ func TestSetResourcesRemote(t *testing.T) {
...
@@ -513,9 +514,10 @@ func TestSetResourcesRemote(t *testing.T) {
OutputFormat
:
&
outputFormat
,
OutputFormat
:
&
outputFormat
,
},
},
Out
:
buf
,
Limits
:
"cpu=200m,memory=512Mi"
,
Limits
:
"cpu=200m,memory=512Mi"
,
ContainerSelector
:
"*"
}
ContainerSelector
:
"*"
,
IOStreams
:
streams
,
}
err
:=
opts
.
Complete
(
tf
,
cmd
,
input
.
args
)
err
:=
opts
.
Complete
(
tf
,
cmd
,
input
.
args
)
if
err
==
nil
{
if
err
==
nil
{
err
=
opts
.
Validate
()
err
=
opts
.
Validate
()
...
...
pkg/kubectl/cmd/set/set_selector.go
View file @
8c1b6873
...
@@ -18,7 +18,6 @@ package set
...
@@ -18,7 +18,6 @@ package set
import
(
import
(
"fmt"
"fmt"
"io"
"k8s.io/kubernetes/pkg/printers"
"k8s.io/kubernetes/pkg/printers"
...
@@ -53,7 +52,6 @@ type SetSelectorOptions struct {
...
@@ -53,7 +52,6 @@ type SetSelectorOptions struct {
resources
[]
string
resources
[]
string
selector
*
metav1
.
LabelSelector
selector
*
metav1
.
LabelSelector
out
io
.
Writer
ClientForMapping
func
(
mapping
*
meta
.
RESTMapping
)
(
resource
.
RESTClient
,
error
)
ClientForMapping
func
(
mapping
*
meta
.
RESTMapping
)
(
resource
.
RESTClient
,
error
)
PrintObj
printers
.
ResourcePrinterFunc
PrintObj
printers
.
ResourcePrinterFunc
...
@@ -61,6 +59,8 @@ type SetSelectorOptions struct {
...
@@ -61,6 +59,8 @@ type SetSelectorOptions struct {
builder
*
resource
.
Builder
builder
*
resource
.
Builder
mapper
meta
.
RESTMapper
mapper
meta
.
RESTMapper
genericclioptions
.
IOStreams
}
}
var
(
var
(
...
@@ -77,20 +77,20 @@ var (
...
@@ -77,20 +77,20 @@ var (
kubectl create deployment my-dep -o yaml --dry-run | kubectl label --local -f - environment=qa -o yaml | kubectl create -f -`
)
kubectl create deployment my-dep -o yaml --dry-run | kubectl label --local -f - environment=qa -o yaml | kubectl create -f -`
)
)
)
func
NewSelectorOptions
(
out
io
.
Writer
)
*
SetSelectorOptions
{
func
NewSelectorOptions
(
streams
genericclioptions
.
IOStreams
)
*
SetSelectorOptions
{
return
&
SetSelectorOptions
{
return
&
SetSelectorOptions
{
PrintFlags
:
printers
.
NewPrintFlags
(
"selector updated"
),
PrintFlags
:
printers
.
NewPrintFlags
(
"selector updated"
),
RecordFlags
:
genericclioptions
.
NewRecordFlags
(),
RecordFlags
:
genericclioptions
.
NewRecordFlags
(),
Recorder
:
genericclioptions
.
NoopRecorder
{},
Recorder
:
genericclioptions
.
NoopRecorder
{},
out
:
out
,
IOStreams
:
streams
,
}
}
}
}
// NewCmdSelector is the "set selector" command.
// NewCmdSelector is the "set selector" command.
func
NewCmdSelector
(
f
cmdutil
.
Factory
,
out
io
.
Writer
)
*
cobra
.
Command
{
func
NewCmdSelector
(
f
cmdutil
.
Factory
,
streams
genericclioptions
.
IOStreams
)
*
cobra
.
Command
{
o
:=
NewSelectorOptions
(
out
)
o
:=
NewSelectorOptions
(
streams
)
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"selector (-f FILENAME | TYPE NAME) EXPRESSIONS [--resource-version=version]"
,
Use
:
"selector (-f FILENAME | TYPE NAME) EXPRESSIONS [--resource-version=version]"
,
...
@@ -226,7 +226,7 @@ func (o *SetSelectorOptions) RunSelector() error {
...
@@ -226,7 +226,7 @@ func (o *SetSelectorOptions) RunSelector() error {
return
patch
.
Err
return
patch
.
Err
}
}
if
o
.
local
||
o
.
dryrun
{
if
o
.
local
||
o
.
dryrun
{
return
o
.
PrintObj
(
info
.
Object
,
o
.
o
ut
)
return
o
.
PrintObj
(
info
.
Object
,
o
.
O
ut
)
}
}
patched
,
err
:=
resource
.
NewHelper
(
info
.
Client
,
info
.
Mapping
)
.
Patch
(
info
.
Namespace
,
info
.
Name
,
types
.
StrategicMergePatchType
,
patch
.
Patch
)
patched
,
err
:=
resource
.
NewHelper
(
info
.
Client
,
info
.
Mapping
)
.
Patch
(
info
.
Namespace
,
info
.
Name
,
types
.
StrategicMergePatchType
,
patch
.
Patch
)
...
@@ -235,7 +235,7 @@ func (o *SetSelectorOptions) RunSelector() error {
...
@@ -235,7 +235,7 @@ func (o *SetSelectorOptions) RunSelector() error {
}
}
info
.
Refresh
(
patched
,
true
)
info
.
Refresh
(
patched
,
true
)
return
o
.
PrintObj
(
patch
.
Info
.
AsVersioned
(),
o
.
o
ut
)
return
o
.
PrintObj
(
patch
.
Info
.
AsVersioned
(),
o
.
O
ut
)
})
})
}
}
...
...
pkg/kubectl/cmd/set/set_selector_test.go
View file @
8c1b6873
...
@@ -17,7 +17,6 @@ limitations under the License.
...
@@ -17,7 +17,6 @@ limitations under the License.
package
set
package
set
import
(
import
(
"bytes"
"net/http"
"net/http"
"reflect"
"reflect"
"strings"
"strings"
...
@@ -34,6 +33,7 @@ import (
...
@@ -34,6 +33,7 @@ import (
"k8s.io/client-go/rest/fake"
"k8s.io/client-go/rest/fake"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/api/legacyscheme"
cmdtesting
"k8s.io/kubernetes/pkg/kubectl/cmd/testing"
cmdtesting
"k8s.io/kubernetes/pkg/kubectl/cmd/testing"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
)
)
func
TestUpdateSelectorForObjectTypes
(
t
*
testing
.
T
)
{
func
TestUpdateSelectorForObjectTypes
(
t
*
testing
.
T
)
{
...
@@ -331,9 +331,8 @@ func TestSelectorTest(t *testing.T) {
...
@@ -331,9 +331,8 @@ func TestSelectorTest(t *testing.T) {
tf
.
Namespace
=
"test"
tf
.
Namespace
=
"test"
tf
.
ClientConfigVal
=
&
restclient
.
Config
{
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
&
schema
.
GroupVersion
{
Version
:
""
}}}
tf
.
ClientConfigVal
=
&
restclient
.
Config
{
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
&
schema
.
GroupVersion
{
Version
:
""
}}}
buf
:=
bytes
.
NewBuffer
([]
byte
{})
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdSelector
(
tf
,
buf
)
cmd
:=
NewCmdSelector
(
tf
,
streams
)
cmd
.
SetOutput
(
buf
)
cmd
.
Flags
()
.
Set
(
"output"
,
"name"
)
cmd
.
Flags
()
.
Set
(
"output"
,
"name"
)
cmd
.
Flags
()
.
Set
(
"local"
,
"true"
)
cmd
.
Flags
()
.
Set
(
"local"
,
"true"
)
cmd
.
Flags
()
.
Set
(
"filename"
,
"../../../../test/e2e/testing-manifests/statefulset/cassandra/service.yaml"
)
cmd
.
Flags
()
.
Set
(
"filename"
,
"../../../../test/e2e/testing-manifests/statefulset/cassandra/service.yaml"
)
...
...
pkg/kubectl/cmd/set/set_serviceaccount.go
View file @
8c1b6873
...
@@ -19,7 +19,6 @@ package set
...
@@ -19,7 +19,6 @@ package set
import
(
import
(
"errors"
"errors"
"fmt"
"fmt"
"io"
"k8s.io/kubernetes/pkg/printers"
"k8s.io/kubernetes/pkg/printers"
...
@@ -62,8 +61,6 @@ type SetServiceAccountOptions struct {
...
@@ -62,8 +61,6 @@ type SetServiceAccountOptions struct {
RecordFlags
*
genericclioptions
.
RecordFlags
RecordFlags
*
genericclioptions
.
RecordFlags
fileNameOptions
resource
.
FilenameOptions
fileNameOptions
resource
.
FilenameOptions
out
io
.
Writer
err
io
.
Writer
dryRun
bool
dryRun
bool
shortOutput
bool
shortOutput
bool
all
bool
all
bool
...
@@ -75,23 +72,24 @@ type SetServiceAccountOptions struct {
...
@@ -75,23 +72,24 @@ type SetServiceAccountOptions struct {
PrintObj
printers
.
ResourcePrinterFunc
PrintObj
printers
.
ResourcePrinterFunc
Recorder
genericclioptions
.
Recorder
Recorder
genericclioptions
.
Recorder
genericclioptions
.
IOStreams
}
}
func
NewSetServiceAccountOptions
(
out
,
errOut
io
.
Writer
)
*
SetServiceAccountOptions
{
func
NewSetServiceAccountOptions
(
streams
genericclioptions
.
IOStreams
)
*
SetServiceAccountOptions
{
return
&
SetServiceAccountOptions
{
return
&
SetServiceAccountOptions
{
PrintFlags
:
printers
.
NewPrintFlags
(
"serviceaccount updated"
),
PrintFlags
:
printers
.
NewPrintFlags
(
"serviceaccount updated"
),
RecordFlags
:
genericclioptions
.
NewRecordFlags
(),
RecordFlags
:
genericclioptions
.
NewRecordFlags
(),
Recorder
:
genericclioptions
.
NoopRecorder
{},
Recorder
:
genericclioptions
.
NoopRecorder
{},
out
:
out
,
IOStreams
:
streams
,
err
:
errOut
,
}
}
}
}
// NewCmdServiceAccount returns the "set serviceaccount" command.
// NewCmdServiceAccount returns the "set serviceaccount" command.
func
NewCmdServiceAccount
(
f
cmdutil
.
Factory
,
out
,
errOut
io
.
Writer
)
*
cobra
.
Command
{
func
NewCmdServiceAccount
(
f
cmdutil
.
Factory
,
streams
genericclioptions
.
IOStreams
)
*
cobra
.
Command
{
o
:=
NewSetServiceAccountOptions
(
out
,
errOut
)
o
:=
NewSetServiceAccountOptions
(
streams
)
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"serviceaccount (-f FILENAME | TYPE NAME) SERVICE_ACCOUNT"
,
Use
:
"serviceaccount (-f FILENAME | TYPE NAME) SERVICE_ACCOUNT"
,
...
@@ -199,7 +197,7 @@ func (o *SetServiceAccountOptions) Run() error {
...
@@ -199,7 +197,7 @@ func (o *SetServiceAccountOptions) Run() error {
continue
continue
}
}
if
o
.
local
||
o
.
dryRun
{
if
o
.
local
||
o
.
dryRun
{
if
err
:=
o
.
PrintObj
(
patch
.
Info
.
AsVersioned
(),
o
.
o
ut
);
err
!=
nil
{
if
err
:=
o
.
PrintObj
(
patch
.
Info
.
AsVersioned
(),
o
.
O
ut
);
err
!=
nil
{
return
err
return
err
}
}
continue
continue
...
@@ -211,7 +209,7 @@ func (o *SetServiceAccountOptions) Run() error {
...
@@ -211,7 +209,7 @@ func (o *SetServiceAccountOptions) Run() error {
}
}
info
.
Refresh
(
patched
,
true
)
info
.
Refresh
(
patched
,
true
)
if
err
:=
o
.
PrintObj
(
info
.
AsVersioned
(),
o
.
o
ut
);
err
!=
nil
{
if
err
:=
o
.
PrintObj
(
info
.
AsVersioned
(),
o
.
O
ut
);
err
!=
nil
{
return
err
return
err
}
}
}
}
...
...
pkg/kubectl/cmd/set/set_serviceaccount_test.go
View file @
8c1b6873
...
@@ -42,6 +42,7 @@ import (
...
@@ -42,6 +42,7 @@ import (
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/testapi"
cmdtesting
"k8s.io/kubernetes/pkg/kubectl/cmd/testing"
cmdtesting
"k8s.io/kubernetes/pkg/kubectl/cmd/testing"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/kubectl/scheme"
"k8s.io/kubernetes/pkg/kubectl/scheme"
)
)
...
@@ -83,9 +84,8 @@ func TestSetServiceAccountLocal(t *testing.T) {
...
@@ -83,9 +84,8 @@ func TestSetServiceAccountLocal(t *testing.T) {
outputFormat
:=
"yaml"
outputFormat
:=
"yaml"
tf
.
Namespace
=
"test"
tf
.
Namespace
=
"test"
out
:=
new
(
bytes
.
Buffer
)
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdServiceAccount
(
tf
,
out
,
out
)
cmd
:=
NewCmdServiceAccount
(
tf
,
streams
)
cmd
.
SetOutput
(
out
)
cmd
.
Flags
()
.
Set
(
"output"
,
outputFormat
)
cmd
.
Flags
()
.
Set
(
"output"
,
outputFormat
)
cmd
.
Flags
()
.
Set
(
"local"
,
"true"
)
cmd
.
Flags
()
.
Set
(
"local"
,
"true"
)
testapi
.
Default
=
testapi
.
Groups
[
input
.
apiGroup
]
testapi
.
Default
=
testapi
.
Groups
[
input
.
apiGroup
]
...
@@ -98,13 +98,14 @@ func TestSetServiceAccountLocal(t *testing.T) {
...
@@ -98,13 +98,14 @@ func TestSetServiceAccountLocal(t *testing.T) {
},
},
fileNameOptions
:
resource
.
FilenameOptions
{
fileNameOptions
:
resource
.
FilenameOptions
{
Filenames
:
[]
string
{
input
.
yaml
}},
Filenames
:
[]
string
{
input
.
yaml
}},
out
:
out
,
local
:
true
,
local
:
true
}
IOStreams
:
streams
,
}
err
:=
saConfig
.
Complete
(
tf
,
cmd
,
[]
string
{
serviceAccount
})
err
:=
saConfig
.
Complete
(
tf
,
cmd
,
[]
string
{
serviceAccount
})
assert
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
err
=
saConfig
.
Run
()
err
=
saConfig
.
Run
()
assert
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
assert
.
Contains
(
t
,
out
.
String
(),
"serviceAccountName: "
+
serviceAccount
,
fmt
.
Sprintf
(
"serviceaccount not updated for %s"
,
input
.
yaml
))
assert
.
Contains
(
t
,
buf
.
String
(),
"serviceAccountName: "
+
serviceAccount
,
fmt
.
Sprintf
(
"serviceaccount not updated for %s"
,
input
.
yaml
))
})
})
}
}
}
}
...
@@ -128,9 +129,8 @@ func TestSetServiceAccountMultiLocal(t *testing.T) {
...
@@ -128,9 +129,8 @@ func TestSetServiceAccountMultiLocal(t *testing.T) {
outputFormat
:=
"name"
outputFormat
:=
"name"
buf
:=
bytes
.
NewBuffer
([]
byte
{})
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdServiceAccount
(
tf
,
buf
,
buf
)
cmd
:=
NewCmdServiceAccount
(
tf
,
streams
)
cmd
.
SetOutput
(
buf
)
cmd
.
Flags
()
.
Set
(
"output"
,
outputFormat
)
cmd
.
Flags
()
.
Set
(
"output"
,
outputFormat
)
cmd
.
Flags
()
.
Set
(
"local"
,
"true"
)
cmd
.
Flags
()
.
Set
(
"local"
,
"true"
)
opts
:=
SetServiceAccountOptions
{
opts
:=
SetServiceAccountOptions
{
...
@@ -142,8 +142,9 @@ func TestSetServiceAccountMultiLocal(t *testing.T) {
...
@@ -142,8 +142,9 @@ func TestSetServiceAccountMultiLocal(t *testing.T) {
},
},
fileNameOptions
:
resource
.
FilenameOptions
{
fileNameOptions
:
resource
.
FilenameOptions
{
Filenames
:
[]
string
{
"../../../../test/fixtures/pkg/kubectl/cmd/set/multi-resource-yaml.yaml"
}},
Filenames
:
[]
string
{
"../../../../test/fixtures/pkg/kubectl/cmd/set/multi-resource-yaml.yaml"
}},
out
:
buf
,
local
:
true
,
local
:
true
}
IOStreams
:
streams
,
}
err
:=
opts
.
Complete
(
tf
,
cmd
,
[]
string
{
serviceAccount
})
err
:=
opts
.
Complete
(
tf
,
cmd
,
[]
string
{
serviceAccount
})
if
err
==
nil
{
if
err
==
nil
{
...
@@ -373,9 +374,8 @@ func TestSetServiceAccountRemote(t *testing.T) {
...
@@ -373,9 +374,8 @@ func TestSetServiceAccountRemote(t *testing.T) {
outputFormat
:=
"yaml"
outputFormat
:=
"yaml"
out
:=
new
(
bytes
.
Buffer
)
streams
:=
genericclioptions
.
NewTestIOStreamsDiscard
()
cmd
:=
NewCmdServiceAccount
(
tf
,
out
,
out
)
cmd
:=
NewCmdServiceAccount
(
tf
,
streams
)
cmd
.
SetOutput
(
out
)
cmd
.
Flags
()
.
Set
(
"output"
,
outputFormat
)
cmd
.
Flags
()
.
Set
(
"output"
,
outputFormat
)
saConfig
:=
SetServiceAccountOptions
{
saConfig
:=
SetServiceAccountOptions
{
PrintFlags
:
&
printers
.
PrintFlags
{
PrintFlags
:
&
printers
.
PrintFlags
{
...
@@ -385,8 +385,9 @@ func TestSetServiceAccountRemote(t *testing.T) {
...
@@ -385,8 +385,9 @@ func TestSetServiceAccountRemote(t *testing.T) {
OutputFormat
:
&
outputFormat
,
OutputFormat
:
&
outputFormat
,
},
},
out
:
out
,
local
:
false
,
local
:
false
}
IOStreams
:
streams
,
}
err
:=
saConfig
.
Complete
(
tf
,
cmd
,
input
.
args
)
err
:=
saConfig
.
Complete
(
tf
,
cmd
,
input
.
args
)
assert
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
err
=
saConfig
.
Run
()
err
=
saConfig
.
Run
()
...
@@ -420,9 +421,8 @@ func TestServiceAccountValidation(t *testing.T) {
...
@@ -420,9 +421,8 @@ func TestServiceAccountValidation(t *testing.T) {
outputFormat
:=
""
outputFormat
:=
""
tf
.
Namespace
=
"test"
tf
.
Namespace
=
"test"
out
:=
bytes
.
NewBuffer
([]
byte
{})
streams
:=
genericclioptions
.
NewTestIOStreamsDiscard
()
cmd
:=
NewCmdServiceAccount
(
tf
,
out
,
out
)
cmd
:=
NewCmdServiceAccount
(
tf
,
streams
)
cmd
.
SetOutput
(
out
)
saConfig
:=
&
SetServiceAccountOptions
{
saConfig
:=
&
SetServiceAccountOptions
{
PrintFlags
:
&
printers
.
PrintFlags
{
PrintFlags
:
&
printers
.
PrintFlags
{
...
@@ -431,6 +431,7 @@ func TestServiceAccountValidation(t *testing.T) {
...
@@ -431,6 +431,7 @@ func TestServiceAccountValidation(t *testing.T) {
OutputFormat
:
&
outputFormat
,
OutputFormat
:
&
outputFormat
,
},
},
IOStreams
:
streams
,
}
}
err
:=
saConfig
.
Complete
(
tf
,
cmd
,
input
.
args
)
err
:=
saConfig
.
Complete
(
tf
,
cmd
,
input
.
args
)
assert
.
EqualError
(
t
,
err
,
input
.
errorString
)
assert
.
EqualError
(
t
,
err
,
input
.
errorString
)
...
...
pkg/kubectl/cmd/set/set_subject.go
View file @
8c1b6873
...
@@ -18,7 +18,6 @@ package set
...
@@ -18,7 +18,6 @@ package set
import
(
import
(
"fmt"
"fmt"
"io"
"strings"
"strings"
"k8s.io/kubernetes/pkg/printers"
"k8s.io/kubernetes/pkg/printers"
...
@@ -32,6 +31,7 @@ import (
...
@@ -32,6 +31,7 @@ import (
"k8s.io/kubernetes/pkg/apis/rbac"
"k8s.io/kubernetes/pkg/apis/rbac"
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/kubectl/util/i18n"
"k8s.io/kubernetes/pkg/kubectl/util/i18n"
)
)
...
@@ -61,8 +61,6 @@ type SubjectOptions struct {
...
@@ -61,8 +61,6 @@ type SubjectOptions struct {
resource
.
FilenameOptions
resource
.
FilenameOptions
Infos
[]
*
resource
.
Info
Infos
[]
*
resource
.
Info
Out
io
.
Writer
Err
io
.
Writer
Selector
string
Selector
string
ContainerSelector
string
ContainerSelector
string
Output
string
Output
string
...
@@ -75,15 +73,20 @@ type SubjectOptions struct {
...
@@ -75,15 +73,20 @@ type SubjectOptions struct {
ServiceAccounts
[]
string
ServiceAccounts
[]
string
PrintObj
printers
.
ResourcePrinterFunc
PrintObj
printers
.
ResourcePrinterFunc
genericclioptions
.
IOStreams
}
}
func
New
CmdSubject
(
f
cmdutil
.
Factory
,
out
io
.
Writer
,
errOut
io
.
Writer
)
*
cobra
.
Command
{
func
New
SubjectOptions
(
streams
genericclioptions
.
IOStreams
)
*
SubjectOptions
{
options
:=
&
SubjectOptions
{
return
&
SubjectOptions
{
PrintFlags
:
printers
.
NewPrintFlags
(
"subjects updated"
),
PrintFlags
:
printers
.
NewPrintFlags
(
"subjects updated"
),
Out
:
out
,
IOStreams
:
streams
,
Err
:
errOut
,
}
}
}
func
NewCmdSubject
(
f
cmdutil
.
Factory
,
streams
genericclioptions
.
IOStreams
)
*
cobra
.
Command
{
options
:=
NewSubjectOptions
(
streams
)
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"subject (-f FILENAME | TYPE NAME) [--user=username] [--group=groupname] [--serviceaccount=namespace:serviceaccountname] [--dry-run]"
,
Use
:
"subject (-f FILENAME | TYPE NAME) [--user=username] [--group=groupname] [--serviceaccount=namespace:serviceaccountname] [--dry-run]"
,
...
...
pkg/kubectl/cmd/set/set_test.go
View file @
8c1b6873
...
@@ -17,20 +17,17 @@ limitations under the License.
...
@@ -17,20 +17,17 @@ limitations under the License.
package
set
package
set
import
(
import
(
"bytes"
"testing"
"testing"
"github.com/spf13/cobra"
"github.com/spf13/cobra"
clientcmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
clientcmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
"
o
s"
"
k8s.io/kubernetes/pkg/kubectl/genericclioption
s"
)
)
func
TestLocalAndDryRunFlags
(
t
*
testing
.
T
)
{
func
TestLocalAndDryRunFlags
(
t
*
testing
.
T
)
{
out
:=
&
bytes
.
Buffer
{}
errout
:=
&
bytes
.
Buffer
{}
f
:=
clientcmdutil
.
NewFactory
(
nil
)
f
:=
clientcmdutil
.
NewFactory
(
nil
)
setCmd
:=
NewCmdSet
(
f
,
os
.
Stdin
,
out
,
errout
)
setCmd
:=
NewCmdSet
(
f
,
genericclioptions
.
NewTestIOStreamsDiscard
()
)
ensureLocalAndDryRunFlagsOnChildren
(
t
,
setCmd
,
""
)
ensureLocalAndDryRunFlagsOnChildren
(
t
,
setCmd
,
""
)
}
}
...
...
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