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
ef9ae612
Commit
ef9ae612
authored
May 25, 2017
by
Alexander Campbell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kubectl: simplify code with help of linter
parent
01ae6edc
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
34 additions
and
71 deletions
+34
-71
apply.go
pkg/kubectl/apply.go
+1
-5
apply_set_last_applied.go
pkg/kubectl/cmd/apply_set_last_applied.go
+2
-9
convert.go
pkg/kubectl/cmd/convert.go
+1
-5
cp.go
pkg/kubectl/cmd/cp.go
+2
-3
create.go
pkg/kubectl/cmd/create.go
+4
-4
delete.go
pkg/kubectl/cmd/delete.go
+1
-1
edit_test.go
pkg/kubectl/cmd/edit_test.go
+2
-2
expose.go
pkg/kubectl/cmd/expose.go
+7
-7
get.go
pkg/kubectl/cmd/get.go
+1
-2
get_test.go
pkg/kubectl/cmd/get_test.go
+1
-3
label.go
pkg/kubectl/cmd/label.go
+1
-1
taint.go
pkg/kubectl/cmd/taint.go
+2
-2
version.go
pkg/kubectl/cmd/version.go
+1
-5
rolling_updater.go
pkg/kubectl/rolling_updater.go
+8
-11
run.go
pkg/kubectl/run.go
+0
-6
stop.go
pkg/kubectl/stop.go
+0
-5
No files found.
pkg/kubectl/apply.go
View file @
ef9ae612
...
...
@@ -61,11 +61,7 @@ func SetOriginalConfiguration(info *resource.Info, original []byte) error {
}
annots
[
api
.
LastAppliedConfigAnnotation
]
=
string
(
original
)
if
err
:=
info
.
Mapping
.
MetadataAccessor
.
SetAnnotations
(
info
.
Object
,
annots
);
err
!=
nil
{
return
err
}
return
nil
return
info
.
Mapping
.
MetadataAccessor
.
SetAnnotations
(
info
.
Object
,
annots
)
}
// GetModifiedConfiguration retrieves the modified configuration of the object.
...
...
pkg/kubectl/cmd/apply_set_last_applied.go
View file @
ef9ae612
...
...
@@ -118,11 +118,7 @@ func (o *SetLastAppliedOptions) Complete(f cmdutil.Factory, cmd *cobra.Command)
}
o
.
Namespace
,
o
.
EnforceNamespace
,
err
=
f
.
DefaultNamespace
()
if
err
!=
nil
{
return
err
}
return
nil
return
err
}
func
(
o
*
SetLastAppliedOptions
)
Validate
(
f
cmdutil
.
Factory
,
cmd
*
cobra
.
Command
)
error
{
...
...
@@ -179,10 +175,7 @@ func (o *SetLastAppliedOptions) Validate(f cmdutil.Factory, cmd *cobra.Command)
return
nil
})
if
err
!=
nil
{
return
err
}
return
nil
return
err
}
func
(
o
*
SetLastAppliedOptions
)
RunSetLastApplied
(
f
cmdutil
.
Factory
,
cmd
*
cobra
.
Command
)
error
{
...
...
pkg/kubectl/cmd/convert.go
View file @
ef9ae612
...
...
@@ -158,11 +158,7 @@ func (o *ConvertOptions) Complete(f cmdutil.Factory, out io.Writer, cmd *cobra.C
}
o
.
encoder
=
f
.
JSONEncoder
()
o
.
printer
,
err
=
f
.
PrinterForCommand
(
cmd
,
o
.
local
,
nil
,
printers
.
PrintOptions
{})
if
err
!=
nil
{
return
err
}
return
nil
return
err
}
// RunConvert implements the generic Convert command
...
...
pkg/kubectl/cmd/cp.go
View file @
ef9ae612
...
...
@@ -34,12 +34,11 @@ import (
)
var
(
cp
_e
xample
=
templates
.
Examples
(
i18n
.
T
(
`
cp
E
xample
=
templates
.
Examples
(
i18n
.
T
(
`
# !!!Important Note!!!
# Requires that the 'tar' binary is present in your container
# image. If 'tar' is not present, 'kubectl cp' will fail.
# Copy /tmp/foo_dir local directory to /tmp/bar_dir in a remote pod in the default namespace
kubectl cp /tmp/foo_dir <some-pod>:/tmp/bar_dir
...
...
@@ -65,7 +64,7 @@ func NewCmdCp(f cmdutil.Factory, cmdOut, cmdErr io.Writer) *cobra.Command {
Use
:
"cp <file-spec-src> <file-spec-dest>"
,
Short
:
i18n
.
T
(
"Copy files and directories to and from containers."
),
Long
:
"Copy files and directories to and from containers."
,
Example
:
cp
_e
xample
,
Example
:
cp
E
xample
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
cmdutil
.
CheckErr
(
runCopy
(
f
,
cmd
,
cmdOut
,
cmdErr
,
args
))
},
...
...
pkg/kubectl/cmd/create.go
View file @
ef9ae612
...
...
@@ -39,12 +39,12 @@ type CreateOptions struct {
}
var
(
create
_l
ong
=
templates
.
LongDesc
(
i18n
.
T
(
`
create
L
ong
=
templates
.
LongDesc
(
i18n
.
T
(
`
Create a resource from a file or from stdin.
JSON and YAML formats are accepted.`
))
create
_e
xample
=
templates
.
Examples
(
i18n
.
T
(
`
create
E
xample
=
templates
.
Examples
(
i18n
.
T
(
`
# Create a pod using the data in pod.json.
kubectl create -f ./pod.json
...
...
@@ -61,8 +61,8 @@ func NewCmdCreate(f cmdutil.Factory, out, errOut io.Writer) *cobra.Command {
cmd
:=
&
cobra
.
Command
{
Use
:
"create -f FILENAME"
,
Short
:
i18n
.
T
(
"Create a resource from a file or from stdin."
),
Long
:
create
_l
ong
,
Example
:
create
_e
xample
,
Long
:
create
L
ong
,
Example
:
create
E
xample
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
if
cmdutil
.
IsFilenameEmpty
(
options
.
FilenameOptions
.
Filenames
)
{
defaultRunFunc
:=
cmdutil
.
DefaultSubCommandRun
(
errOut
)
...
...
pkg/kubectl/cmd/delete.go
View file @
ef9ae612
...
...
@@ -327,7 +327,7 @@ func deleteResource(info *resource.Info, out io.Writer, shortOutput bool, mapper
return
nil
}
// objectDeletionWaitInterval is the interval to wait between checks for deletion.
Exposed for testing.
// objectDeletionWaitInterval is the interval to wait between checks for deletion.
var
objectDeletionWaitInterval
=
time
.
Second
// waitForObjectDeletion refreshes the object, waiting until it is deleted, a timeout is reached, or
...
...
pkg/kubectl/cmd/edit_test.go
View file @
ef9ae612
...
...
@@ -116,7 +116,7 @@ func TestEdit(t *testing.T) {
if
step
.
StepType
!=
"edit"
{
t
.
Fatalf
(
"%s, step %d: expected edit step, got %s %s"
,
name
,
i
,
req
.
Method
,
req
.
URL
.
Path
)
}
if
bytes
.
Compare
(
body
,
expectedInput
)
!=
0
{
if
!
bytes
.
Equal
(
body
,
expectedInput
)
{
if
updateInputFixtures
{
// Convenience to allow recapturing the input and persisting it here
ioutil
.
WriteFile
(
inputFile
,
body
,
os
.
FileMode
(
0644
))
...
...
@@ -139,7 +139,7 @@ func TestEdit(t *testing.T) {
req
.
Method
,
req
.
URL
.
Path
,
req
.
Header
.
Get
(
"Content-Type"
),
)
}
if
bytes
.
Compare
(
body
,
expectedInput
)
!=
0
{
if
!
bytes
.
Equal
(
body
,
expectedInput
)
{
if
updateInputFixtures
{
// Convenience to allow recapturing the input and persisting it here
ioutil
.
WriteFile
(
inputFile
,
body
,
os
.
FileMode
(
0644
))
...
...
pkg/kubectl/cmd/expose.go
View file @
ef9ae612
...
...
@@ -34,9 +34,9 @@ import (
)
var
(
expose
_r
esources
=
`pod (po), service (svc), replicationcontroller (rc), deployment (deploy), replicaset (rs)`
expose
R
esources
=
`pod (po), service (svc), replicationcontroller (rc), deployment (deploy), replicaset (rs)`
expose
_l
ong
=
templates
.
LongDesc
(
`
expose
L
ong
=
templates
.
LongDesc
(
`
Expose a resource as a new Kubernetes service.
Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector
...
...
@@ -48,9 +48,9 @@ var (
Possible resources include (case insensitive):
`
+
expose
_r
esources
)
`
+
expose
R
esources
)
expose
_e
xample
=
templates
.
Examples
(
i18n
.
T
(
`
expose
E
xample
=
templates
.
Examples
(
i18n
.
T
(
`
# Create a service for a replicated nginx, which serves on port 80 and connects to the containers on port 8000.
kubectl expose rc nginx --port=80 --target-port=8000
...
...
@@ -77,7 +77,7 @@ func NewCmdExposeService(f cmdutil.Factory, out io.Writer) *cobra.Command {
options
:=
&
resource
.
FilenameOptions
{}
validArgs
,
argAliases
:=
[]
string
{},
[]
string
{}
resources
:=
regexp
.
MustCompile
(
`\s*,`
)
.
Split
(
expose
_r
esources
,
-
1
)
resources
:=
regexp
.
MustCompile
(
`\s*,`
)
.
Split
(
expose
R
esources
,
-
1
)
for
_
,
r
:=
range
resources
{
validArgs
=
append
(
validArgs
,
strings
.
Fields
(
r
)[
0
])
argAliases
=
kubectl
.
ResourceAliases
(
validArgs
)
...
...
@@ -86,8 +86,8 @@ func NewCmdExposeService(f cmdutil.Factory, out io.Writer) *cobra.Command {
cmd
:=
&
cobra
.
Command
{
Use
:
"expose (-f FILENAME | TYPE NAME) [--port=port] [--protocol=TCP|UDP] [--target-port=number-or-name] [--name=name] [--external-ip=external-ip-of-service] [--type=type]"
,
Short
:
i18n
.
T
(
"Take a replication controller, service, deployment or pod and expose it as a new Kubernetes Service"
),
Long
:
expose
_l
ong
,
Example
:
expose
_e
xample
,
Long
:
expose
L
ong
,
Example
:
expose
E
xample
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
err
:=
RunExpose
(
f
,
out
,
cmd
,
args
,
options
)
cmdutil
.
CheckErr
(
err
)
...
...
pkg/kubectl/cmd/get.go
View file @
ef9ae612
...
...
@@ -289,8 +289,7 @@ func RunGet(f cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args [
first
=
false
return
false
,
nil
}
err
:=
printer
.
PrintObj
(
e
.
Object
,
out
)
return
false
,
err
return
false
,
printer
.
PrintObj
(
e
.
Object
,
out
)
})
return
err
})
...
...
pkg/kubectl/cmd/get_test.go
View file @
ef9ae612
...
...
@@ -506,9 +506,7 @@ func extractResourceList(objs []runtime.Object) ([]runtime.Object, error) {
if
err
!=
nil
{
return
nil
,
err
}
for
_
,
item
:=
range
items
{
finalObjs
=
append
(
finalObjs
,
item
)
}
finalObjs
=
append
(
finalObjs
,
items
...
)
}
return
finalObjs
,
nil
}
...
...
pkg/kubectl/cmd/label.go
View file @
ef9ae612
...
...
@@ -308,7 +308,7 @@ func parseLabels(spec []string) (map[string]string, []string, error) {
labels
:=
map
[
string
]
string
{}
var
remove
[]
string
for
_
,
labelSpec
:=
range
spec
{
if
strings
.
Index
(
labelSpec
,
"="
)
!=
-
1
{
if
strings
.
Contains
(
labelSpec
,
"="
)
{
parts
:=
strings
.
Split
(
labelSpec
,
"="
)
if
len
(
parts
)
!=
2
{
return
nil
,
nil
,
fmt
.
Errorf
(
"invalid label spec: %v"
,
labelSpec
)
...
...
pkg/kubectl/cmd/taint.go
View file @
ef9ae612
...
...
@@ -178,7 +178,7 @@ func parseTaints(spec []string) ([]v1.Taint, []v1.Taint, error) {
uniqueTaints
:=
map
[
v1
.
TaintEffect
]
sets
.
String
{}
for
_
,
taintSpec
:=
range
spec
{
if
strings
.
Index
(
taintSpec
,
"="
)
!=
-
1
&&
strings
.
Index
(
taintSpec
,
":"
)
!=
-
1
{
if
strings
.
Contains
(
taintSpec
,
"="
)
&&
strings
.
Contains
(
taintSpec
,
":"
)
{
newTaint
,
err
:=
utiltaints
.
ParseTaint
(
taintSpec
)
if
err
!=
nil
{
return
nil
,
nil
,
err
...
...
@@ -197,7 +197,7 @@ func parseTaints(spec []string) ([]v1.Taint, []v1.Taint, error) {
}
else
if
strings
.
HasSuffix
(
taintSpec
,
"-"
)
{
taintKey
:=
taintSpec
[
:
len
(
taintSpec
)
-
1
]
var
effect
v1
.
TaintEffect
if
strings
.
Index
(
taintKey
,
":"
)
!=
-
1
{
if
strings
.
Contains
(
taintKey
,
":"
)
{
parts
:=
strings
.
Split
(
taintKey
,
":"
)
taintKey
=
parts
[
0
]
effect
=
v1
.
TaintEffect
(
parts
[
1
])
...
...
pkg/kubectl/cmd/version.go
View file @
ef9ae612
...
...
@@ -107,11 +107,7 @@ func RunVersion(f cmdutil.Factory, out io.Writer, cmd *cobra.Command) error {
}
if
serverErr
!=
nil
{
return
serverErr
}
return
nil
return
serverErr
}
func
retrieveServerVersion
(
f
cmdutil
.
Factory
)
(
*
apimachineryversion
.
Info
,
error
)
{
...
...
pkg/kubectl/rolling_updater.go
View file @
ef9ae612
...
...
@@ -565,10 +565,7 @@ func Rename(c coreclient.ReplicationControllersGetter, rc *api.ReplicationContro
}
// Then create the same RC with the new name.
_
,
err
=
c
.
ReplicationControllers
(
rc
.
Namespace
)
.
Create
(
rc
)
if
err
!=
nil
{
return
err
}
return
nil
return
err
}
func
LoadExistingNextReplicationController
(
c
coreclient
.
ReplicationControllersGetter
,
namespace
,
newName
string
)
(
*
api
.
ReplicationController
,
error
)
{
...
...
@@ -684,14 +681,14 @@ func UpdateExistingReplicationController(rcClient coreclient.ReplicationControll
if
_
,
found
:=
oldRc
.
Spec
.
Selector
[
deploymentKey
];
!
found
{
SetNextControllerAnnotation
(
oldRc
,
newName
)
return
AddDeploymentKeyToReplicationController
(
oldRc
,
rcClient
,
podClient
,
deploymentKey
,
deploymentValue
,
namespace
,
out
)
}
else
{
// If we didn't need to update the controller for the deployment key, we still need to write
// the "next" controller.
applyUpdate
:=
func
(
rc
*
api
.
ReplicationController
)
{
SetNextControllerAnnotation
(
rc
,
newName
)
}
return
updateRcWithRetries
(
rcClient
,
namespace
,
oldRc
,
applyUpdate
)
}
// If we didn't need to update the controller for the deployment key, we still need to write
// the "next" controller.
applyUpdate
:=
func
(
rc
*
api
.
ReplicationController
)
{
SetNextControllerAnnotation
(
rc
,
newName
)
}
return
updateRcWithRetries
(
rcClient
,
namespace
,
oldRc
,
applyUpdate
)
}
func
AddDeploymentKeyToReplicationController
(
oldRc
*
api
.
ReplicationController
,
rcClient
coreclient
.
ReplicationControllersGetter
,
podClient
coreclient
.
PodsGetter
,
deploymentKey
,
deploymentValue
,
namespace
string
,
out
io
.
Writer
)
(
*
api
.
ReplicationController
,
error
)
{
...
...
pkg/kubectl/run.go
View file @
ef9ae612
...
...
@@ -868,9 +868,3 @@ func parseEnvs(envArray []string) ([]v1.EnvVar, error) {
}
return
envs
,
nil
}
func
newBool
(
val
bool
)
*
bool
{
p
:=
new
(
bool
)
*
p
=
val
return
p
}
pkg/kubectl/stop.go
View file @
ef9ae612
...
...
@@ -136,11 +136,6 @@ type StatefulSetReaper struct {
pollInterval
,
timeout
time
.
Duration
}
type
objInterface
interface
{
Delete
(
name
string
)
error
Get
(
name
string
)
(
metav1
.
Object
,
error
)
}
// getOverlappingControllers finds rcs that this controller overlaps, as well as rcs overlapping this controller.
func
getOverlappingControllers
(
rcClient
coreclient
.
ReplicationControllerInterface
,
rc
*
api
.
ReplicationController
)
([]
api
.
ReplicationController
,
error
)
{
rcs
,
err
:=
rcClient
.
List
(
metav1
.
ListOptions
{})
...
...
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