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
994d7fc9
Commit
994d7fc9
authored
Mar 07, 2019
by
obitech
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix golint issues in pkg/kubectl/cmd/apply
parent
b5336132
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
26 additions
and
6 deletions
+26
-6
.golint_failures
hack/.golint_failures
+0
-1
apply.go
pkg/kubectl/cmd/apply/apply.go
+12
-5
apply_edit_last_applied.go
pkg/kubectl/cmd/apply/apply_edit_last_applied.go
+1
-0
apply_set_last_applied.go
pkg/kubectl/cmd/apply/apply_set_last_applied.go
+7
-0
apply_view_last_applied.go
pkg/kubectl/cmd/apply/apply_view_last_applied.go
+6
-0
No files found.
hack/.golint_failures
View file @
994d7fc9
...
@@ -108,7 +108,6 @@ pkg/kubeapiserver
...
@@ -108,7 +108,6 @@ pkg/kubeapiserver
pkg/kubeapiserver/options
pkg/kubeapiserver/options
pkg/kubectl
pkg/kubectl
pkg/kubectl/cmd/annotate
pkg/kubectl/cmd/annotate
pkg/kubectl/cmd/apply
pkg/kubectl/cmd/attach
pkg/kubectl/cmd/attach
pkg/kubectl/cmd/autoscale
pkg/kubectl/cmd/autoscale
pkg/kubectl/cmd/certificates
pkg/kubectl/cmd/certificates
...
...
pkg/kubectl/cmd/apply/apply.go
View file @
994d7fc9
...
@@ -56,7 +56,8 @@ import (
...
@@ -56,7 +56,8 @@ import (
"k8s.io/kubernetes/pkg/kubectl/validation"
"k8s.io/kubernetes/pkg/kubectl/validation"
)
)
type
ApplyOptions
struct
{
// Options defines flags and other configuration parameters for the `apply` command
type
Options
struct
{
RecordFlags
*
genericclioptions
.
RecordFlags
RecordFlags
*
genericclioptions
.
RecordFlags
Recorder
genericclioptions
.
Recorder
Recorder
genericclioptions
.
Recorder
...
@@ -132,8 +133,9 @@ var (
...
@@ -132,8 +133,9 @@ var (
warningNoLastAppliedConfigAnnotation
=
"Warning: %[1]s apply should be used on resource created by either %[1]s create --save-config or %[1]s apply
\n
"
warningNoLastAppliedConfigAnnotation
=
"Warning: %[1]s apply should be used on resource created by either %[1]s create --save-config or %[1]s apply
\n
"
)
)
func
NewApplyOptions
(
ioStreams
genericclioptions
.
IOStreams
)
*
ApplyOptions
{
// NewApplyOptions creates new Options for the `apply` command
return
&
ApplyOptions
{
func
NewApplyOptions
(
ioStreams
genericclioptions
.
IOStreams
)
*
Options
{
return
&
Options
{
RecordFlags
:
genericclioptions
.
NewRecordFlags
(),
RecordFlags
:
genericclioptions
.
NewRecordFlags
(),
DeleteFlags
:
delete
.
NewDeleteFlags
(
"that contains the configuration to apply"
),
DeleteFlags
:
delete
.
NewDeleteFlags
(
"that contains the configuration to apply"
),
PrintFlags
:
genericclioptions
.
NewPrintFlags
(
"created"
)
.
WithTypeSetter
(
scheme
.
Scheme
),
PrintFlags
:
genericclioptions
.
NewPrintFlags
(
"created"
)
.
WithTypeSetter
(
scheme
.
Scheme
),
...
@@ -194,7 +196,8 @@ func NewCmdApply(baseName string, f cmdutil.Factory, ioStreams genericclioptions
...
@@ -194,7 +196,8 @@ func NewCmdApply(baseName string, f cmdutil.Factory, ioStreams genericclioptions
return
cmd
return
cmd
}
}
func
(
o
*
ApplyOptions
)
Complete
(
f
cmdutil
.
Factory
,
cmd
*
cobra
.
Command
)
error
{
// Complete verifies if Options are valid and without conflicts.
func
(
o
*
Options
)
Complete
(
f
cmdutil
.
Factory
,
cmd
*
cobra
.
Command
)
error
{
o
.
ServerSideApply
=
cmdutil
.
GetServerSideApplyFlag
(
cmd
)
o
.
ServerSideApply
=
cmdutil
.
GetServerSideApplyFlag
(
cmd
)
o
.
ForceConflicts
=
cmdutil
.
GetForceConflictsFlag
(
cmd
)
o
.
ForceConflicts
=
cmdutil
.
GetForceConflictsFlag
(
cmd
)
o
.
FieldManager
=
cmdutil
.
GetFieldManagerFlag
(
cmd
)
o
.
FieldManager
=
cmdutil
.
GetFieldManagerFlag
(
cmd
)
...
@@ -325,7 +328,8 @@ func isIncompatibleServerError(err error) bool {
...
@@ -325,7 +328,8 @@ func isIncompatibleServerError(err error) bool {
return
err
.
(
*
errors
.
StatusError
)
.
Status
()
.
Code
==
http
.
StatusUnsupportedMediaType
return
err
.
(
*
errors
.
StatusError
)
.
Status
()
.
Code
==
http
.
StatusUnsupportedMediaType
}
}
func
(
o
*
ApplyOptions
)
Run
()
error
{
// Run executes the `apply` command.
func
(
o
*
Options
)
Run
()
error
{
var
openapiSchema
openapi
.
Resources
var
openapiSchema
openapi
.
Resources
if
o
.
OpenAPIPatch
{
if
o
.
OpenAPIPatch
{
openapiSchema
=
o
.
OpenAPISchema
openapiSchema
=
o
.
OpenAPISchema
...
@@ -761,6 +765,7 @@ func (p *Patcher) delete(namespace, name string) error {
...
@@ -761,6 +765,7 @@ func (p *Patcher) delete(namespace, name string) error {
return
runDelete
(
namespace
,
name
,
p
.
Mapping
,
p
.
DynamicClient
,
p
.
Cascade
,
p
.
GracePeriod
,
p
.
ServerDryRun
)
return
runDelete
(
namespace
,
name
,
p
.
Mapping
,
p
.
DynamicClient
,
p
.
Cascade
,
p
.
GracePeriod
,
p
.
ServerDryRun
)
}
}
// Patcher defines options to patch OpenAPI objects.
type
Patcher
struct
{
type
Patcher
struct
{
Mapping
*
meta
.
RESTMapping
Mapping
*
meta
.
RESTMapping
Helper
*
resource
.
Helper
Helper
*
resource
.
Helper
...
@@ -926,6 +931,8 @@ func (p *Patcher) patchSimple(obj runtime.Object, modified []byte, source, names
...
@@ -926,6 +931,8 @@ func (p *Patcher) patchSimple(obj runtime.Object, modified []byte, source, names
return
patch
,
patchedObj
,
err
return
patch
,
patchedObj
,
err
}
}
// Patch tries to patch an OpenAPI resource. On success, returns the merge patch as well
// the final patched object. On failure, returns an error.
func
(
p
*
Patcher
)
Patch
(
current
runtime
.
Object
,
modified
[]
byte
,
source
,
namespace
,
name
string
,
errOut
io
.
Writer
)
([]
byte
,
runtime
.
Object
,
error
)
{
func
(
p
*
Patcher
)
Patch
(
current
runtime
.
Object
,
modified
[]
byte
,
source
,
namespace
,
name
string
,
errOut
io
.
Writer
)
([]
byte
,
runtime
.
Object
,
error
)
{
var
getErr
error
var
getErr
error
patchBytes
,
patchObject
,
err
:=
p
.
patchSimple
(
current
,
modified
,
source
,
namespace
,
name
,
errOut
)
patchBytes
,
patchObject
,
err
:=
p
.
patchSimple
(
current
,
modified
,
source
,
namespace
,
name
,
errOut
)
...
...
pkg/kubectl/cmd/apply/apply_edit_last_applied.go
View file @
994d7fc9
...
@@ -55,6 +55,7 @@ var (
...
@@ -55,6 +55,7 @@ var (
kubectl apply edit-last-applied -f deploy.yaml -o json`
)
kubectl apply edit-last-applied -f deploy.yaml -o json`
)
)
)
// NewCmdApplyEditLastApplied created the cobra CLI command for the `apply edit-last-applied` command.
func
NewCmdApplyEditLastApplied
(
f
cmdutil
.
Factory
,
ioStreams
genericclioptions
.
IOStreams
)
*
cobra
.
Command
{
func
NewCmdApplyEditLastApplied
(
f
cmdutil
.
Factory
,
ioStreams
genericclioptions
.
IOStreams
)
*
cobra
.
Command
{
o
:=
editor
.
NewEditOptions
(
editor
.
ApplyEditMode
,
ioStreams
)
o
:=
editor
.
NewEditOptions
(
editor
.
ApplyEditMode
,
ioStreams
)
...
...
pkg/kubectl/cmd/apply/apply_set_last_applied.go
View file @
994d7fc9
...
@@ -37,6 +37,7 @@ import (
...
@@ -37,6 +37,7 @@ import (
"k8s.io/kubernetes/pkg/kubectl/util/templates"
"k8s.io/kubernetes/pkg/kubectl/util/templates"
)
)
// SetLastAppliedOptions defines options for the `apply set-last-applied` command.`
type
SetLastAppliedOptions
struct
{
type
SetLastAppliedOptions
struct
{
CreateAnnotation
bool
CreateAnnotation
bool
...
@@ -58,6 +59,7 @@ type SetLastAppliedOptions struct {
...
@@ -58,6 +59,7 @@ type SetLastAppliedOptions struct {
genericclioptions
.
IOStreams
genericclioptions
.
IOStreams
}
}
// PatchBuffer caches changes that are to be applied.
type
PatchBuffer
struct
{
type
PatchBuffer
struct
{
Patch
[]
byte
Patch
[]
byte
PatchType
types
.
PatchType
PatchType
types
.
PatchType
...
@@ -81,6 +83,7 @@ var (
...
@@ -81,6 +83,7 @@ var (
`
))
`
))
)
)
// NewSetLastAppliedOptions takes option arguments from a CLI stream and returns it at SetLastAppliedOptions type.
func
NewSetLastAppliedOptions
(
ioStreams
genericclioptions
.
IOStreams
)
*
SetLastAppliedOptions
{
func
NewSetLastAppliedOptions
(
ioStreams
genericclioptions
.
IOStreams
)
*
SetLastAppliedOptions
{
return
&
SetLastAppliedOptions
{
return
&
SetLastAppliedOptions
{
PrintFlags
:
genericclioptions
.
NewPrintFlags
(
"configured"
)
.
WithTypeSetter
(
scheme
.
Scheme
),
PrintFlags
:
genericclioptions
.
NewPrintFlags
(
"configured"
)
.
WithTypeSetter
(
scheme
.
Scheme
),
...
@@ -88,6 +91,7 @@ func NewSetLastAppliedOptions(ioStreams genericclioptions.IOStreams) *SetLastApp
...
@@ -88,6 +91,7 @@ func NewSetLastAppliedOptions(ioStreams genericclioptions.IOStreams) *SetLastApp
}
}
}
}
// NewCmdApplySetLastApplied creates the cobra CLI `apply` subcommand `set-last-applied`.`
func
NewCmdApplySetLastApplied
(
f
cmdutil
.
Factory
,
ioStreams
genericclioptions
.
IOStreams
)
*
cobra
.
Command
{
func
NewCmdApplySetLastApplied
(
f
cmdutil
.
Factory
,
ioStreams
genericclioptions
.
IOStreams
)
*
cobra
.
Command
{
o
:=
NewSetLastAppliedOptions
(
ioStreams
)
o
:=
NewSetLastAppliedOptions
(
ioStreams
)
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
...
@@ -112,6 +116,7 @@ func NewCmdApplySetLastApplied(f cmdutil.Factory, ioStreams genericclioptions.IO
...
@@ -112,6 +116,7 @@ func NewCmdApplySetLastApplied(f cmdutil.Factory, ioStreams genericclioptions.IO
return
cmd
return
cmd
}
}
// Complete populates dry-run and output flag options.
func
(
o
*
SetLastAppliedOptions
)
Complete
(
f
cmdutil
.
Factory
,
cmd
*
cobra
.
Command
)
error
{
func
(
o
*
SetLastAppliedOptions
)
Complete
(
f
cmdutil
.
Factory
,
cmd
*
cobra
.
Command
)
error
{
o
.
dryRun
=
cmdutil
.
GetDryRunFlag
(
cmd
)
o
.
dryRun
=
cmdutil
.
GetDryRunFlag
(
cmd
)
o
.
output
=
cmdutil
.
GetFlagString
(
cmd
,
"output"
)
o
.
output
=
cmdutil
.
GetFlagString
(
cmd
,
"output"
)
...
@@ -141,6 +146,7 @@ func (o *SetLastAppliedOptions) Complete(f cmdutil.Factory, cmd *cobra.Command)
...
@@ -141,6 +146,7 @@ func (o *SetLastAppliedOptions) Complete(f cmdutil.Factory, cmd *cobra.Command)
return
nil
return
nil
}
}
// Validate checks SetLastAppliedOptions for validity.
func
(
o
*
SetLastAppliedOptions
)
Validate
()
error
{
func
(
o
*
SetLastAppliedOptions
)
Validate
()
error
{
r
:=
o
.
builder
.
r
:=
o
.
builder
.
Unstructured
()
.
Unstructured
()
.
...
@@ -187,6 +193,7 @@ func (o *SetLastAppliedOptions) Validate() error {
...
@@ -187,6 +193,7 @@ func (o *SetLastAppliedOptions) Validate() error {
return
err
return
err
}
}
// RunSetLastApplied executes the `set-last-applied` command according to SetLastAppliedOptions.
func
(
o
*
SetLastAppliedOptions
)
RunSetLastApplied
()
error
{
func
(
o
*
SetLastAppliedOptions
)
RunSetLastApplied
()
error
{
for
i
,
patch
:=
range
o
.
patchBufferList
{
for
i
,
patch
:=
range
o
.
patchBufferList
{
info
:=
o
.
infoList
[
i
]
info
:=
o
.
infoList
[
i
]
...
...
pkg/kubectl/cmd/apply/apply_view_last_applied.go
View file @
994d7fc9
...
@@ -31,6 +31,7 @@ import (
...
@@ -31,6 +31,7 @@ import (
"sigs.k8s.io/yaml"
"sigs.k8s.io/yaml"
)
)
// ViewLastAppliedOptions defines options for the `apply view-last-applied` command.`
type
ViewLastAppliedOptions
struct
{
type
ViewLastAppliedOptions
struct
{
FilenameOptions
resource
.
FilenameOptions
FilenameOptions
resource
.
FilenameOptions
Selector
string
Selector
string
...
@@ -57,6 +58,7 @@ var (
...
@@ -57,6 +58,7 @@ var (
kubectl apply view-last-applied -f deploy.yaml -o json`
))
kubectl apply view-last-applied -f deploy.yaml -o json`
))
)
)
// NewViewLastAppliedOptions takes option arguments from a CLI stream and returns it at ViewLastAppliedOptions type.
func
NewViewLastAppliedOptions
(
ioStreams
genericclioptions
.
IOStreams
)
*
ViewLastAppliedOptions
{
func
NewViewLastAppliedOptions
(
ioStreams
genericclioptions
.
IOStreams
)
*
ViewLastAppliedOptions
{
return
&
ViewLastAppliedOptions
{
return
&
ViewLastAppliedOptions
{
OutputFormat
:
"yaml"
,
OutputFormat
:
"yaml"
,
...
@@ -65,6 +67,7 @@ func NewViewLastAppliedOptions(ioStreams genericclioptions.IOStreams) *ViewLastA
...
@@ -65,6 +67,7 @@ func NewViewLastAppliedOptions(ioStreams genericclioptions.IOStreams) *ViewLastA
}
}
}
}
// NewCmdApplyViewLastApplied creates the cobra CLI `apply` subcommand `view-last-applied`.`
func
NewCmdApplyViewLastApplied
(
f
cmdutil
.
Factory
,
ioStreams
genericclioptions
.
IOStreams
)
*
cobra
.
Command
{
func
NewCmdApplyViewLastApplied
(
f
cmdutil
.
Factory
,
ioStreams
genericclioptions
.
IOStreams
)
*
cobra
.
Command
{
options
:=
NewViewLastAppliedOptions
(
ioStreams
)
options
:=
NewViewLastAppliedOptions
(
ioStreams
)
...
@@ -90,6 +93,7 @@ func NewCmdApplyViewLastApplied(f cmdutil.Factory, ioStreams genericclioptions.I
...
@@ -90,6 +93,7 @@ func NewCmdApplyViewLastApplied(f cmdutil.Factory, ioStreams genericclioptions.I
return
cmd
return
cmd
}
}
// Complete checks an object for last-applied-configuration annotations.
func
(
o
*
ViewLastAppliedOptions
)
Complete
(
cmd
*
cobra
.
Command
,
f
cmdutil
.
Factory
,
args
[]
string
)
error
{
func
(
o
*
ViewLastAppliedOptions
)
Complete
(
cmd
*
cobra
.
Command
,
f
cmdutil
.
Factory
,
args
[]
string
)
error
{
cmdNamespace
,
enforceNamespace
,
err
:=
f
.
ToRawKubeConfigLoader
()
.
Namespace
()
cmdNamespace
,
enforceNamespace
,
err
:=
f
.
ToRawKubeConfigLoader
()
.
Namespace
()
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -134,10 +138,12 @@ func (o *ViewLastAppliedOptions) Complete(cmd *cobra.Command, f cmdutil.Factory,
...
@@ -134,10 +138,12 @@ func (o *ViewLastAppliedOptions) Complete(cmd *cobra.Command, f cmdutil.Factory,
return
nil
return
nil
}
}
// Validate checks ViewLastAppliedOptions for validity.
func
(
o
*
ViewLastAppliedOptions
)
Validate
(
cmd
*
cobra
.
Command
)
error
{
func
(
o
*
ViewLastAppliedOptions
)
Validate
(
cmd
*
cobra
.
Command
)
error
{
return
nil
return
nil
}
}
// RunApplyViewLastApplied executes the `view-last-applied` command according to ViewLastAppliedOptions.
func
(
o
*
ViewLastAppliedOptions
)
RunApplyViewLastApplied
(
cmd
*
cobra
.
Command
)
error
{
func
(
o
*
ViewLastAppliedOptions
)
RunApplyViewLastApplied
(
cmd
*
cobra
.
Command
)
error
{
for
_
,
str
:=
range
o
.
LastAppliedConfigurationList
{
for
_
,
str
:=
range
o
.
LastAppliedConfigurationList
{
switch
o
.
OutputFormat
{
switch
o
.
OutputFormat
{
...
...
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