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
a14a288c
Commit
a14a288c
authored
May 29, 2016
by
Gyu-Ho Lee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pkg/kubectl: preallocate slice
To avoid slice growth with append operations.
parent
825cd920
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
21 additions
and
20 deletions
+21
-20
bash_comp_utils.go
pkg/kubectl/bash_comp_utils.go
+1
-1
describe.go
pkg/kubectl/describe.go
+16
-15
history.go
pkg/kubectl/history.go
+1
-1
kubectl.go
pkg/kubectl/kubectl.go
+2
-2
run.go
pkg/kubectl/run.go
+1
-1
No files found.
pkg/kubectl/bash_comp_utils.go
View file @
a14a288c
...
@@ -28,7 +28,7 @@ import (
...
@@ -28,7 +28,7 @@ import (
func
AddJsonFilenameFlag
(
cmd
*
cobra
.
Command
,
value
*
[]
string
,
usage
string
)
{
func
AddJsonFilenameFlag
(
cmd
*
cobra
.
Command
,
value
*
[]
string
,
usage
string
)
{
cmd
.
Flags
()
.
StringSliceVarP
(
value
,
"filename"
,
"f"
,
*
value
,
usage
)
cmd
.
Flags
()
.
StringSliceVarP
(
value
,
"filename"
,
"f"
,
*
value
,
usage
)
annotations
:=
[]
string
{}
annotations
:=
make
([]
string
,
0
,
len
(
resource
.
FileExtensions
))
for
_
,
ext
:=
range
resource
.
FileExtensions
{
for
_
,
ext
:=
range
resource
.
FileExtensions
{
annotations
=
append
(
annotations
,
strings
.
TrimLeft
(
ext
,
"."
))
annotations
=
append
(
annotations
,
strings
.
TrimLeft
(
ext
,
"."
))
}
}
...
...
pkg/kubectl/describe.go
View file @
a14a288c
...
@@ -280,7 +280,7 @@ func DescribeResourceQuotas(quotas *api.ResourceQuotaList, w io.Writer) {
...
@@ -280,7 +280,7 @@ func DescribeResourceQuotas(quotas *api.ResourceQuotaList, w io.Writer) {
for
_
,
q
:=
range
quotas
.
Items
{
for
_
,
q
:=
range
quotas
.
Items
{
fmt
.
Fprintf
(
w
,
"
\n
Name:
\t
%s
\n
"
,
q
.
Name
)
fmt
.
Fprintf
(
w
,
"
\n
Name:
\t
%s
\n
"
,
q
.
Name
)
if
len
(
q
.
Spec
.
Scopes
)
>
0
{
if
len
(
q
.
Spec
.
Scopes
)
>
0
{
scopes
:=
[]
string
{}
scopes
:=
make
([]
string
,
0
,
len
(
q
.
Spec
.
Scopes
))
for
_
,
scope
:=
range
q
.
Spec
.
Scopes
{
for
_
,
scope
:=
range
q
.
Spec
.
Scopes
{
scopes
=
append
(
scopes
,
string
(
scope
))
scopes
=
append
(
scopes
,
string
(
scope
))
}
}
...
@@ -297,7 +297,7 @@ func DescribeResourceQuotas(quotas *api.ResourceQuotaList, w io.Writer) {
...
@@ -297,7 +297,7 @@ func DescribeResourceQuotas(quotas *api.ResourceQuotaList, w io.Writer) {
fmt
.
Fprintf
(
w
,
" Resource
\t
Used
\t
Hard
\n
"
)
fmt
.
Fprintf
(
w
,
" Resource
\t
Used
\t
Hard
\n
"
)
fmt
.
Fprint
(
w
,
" --------
\t
---
\t
---
\n
"
)
fmt
.
Fprint
(
w
,
" --------
\t
---
\t
---
\n
"
)
resources
:=
[]
api
.
ResourceName
{}
resources
:=
make
([]
api
.
ResourceName
,
0
,
len
(
q
.
Status
.
Hard
))
for
resource
:=
range
q
.
Status
.
Hard
{
for
resource
:=
range
q
.
Status
.
Hard
{
resources
=
append
(
resources
,
resource
)
resources
=
append
(
resources
,
resource
)
}
}
...
@@ -433,7 +433,7 @@ func describeQuota(resourceQuota *api.ResourceQuota) (string, error) {
...
@@ -433,7 +433,7 @@ func describeQuota(resourceQuota *api.ResourceQuota) (string, error) {
fmt
.
Fprintf
(
out
,
"Name:
\t
%s
\n
"
,
resourceQuota
.
Name
)
fmt
.
Fprintf
(
out
,
"Name:
\t
%s
\n
"
,
resourceQuota
.
Name
)
fmt
.
Fprintf
(
out
,
"Namespace:
\t
%s
\n
"
,
resourceQuota
.
Namespace
)
fmt
.
Fprintf
(
out
,
"Namespace:
\t
%s
\n
"
,
resourceQuota
.
Namespace
)
if
len
(
resourceQuota
.
Spec
.
Scopes
)
>
0
{
if
len
(
resourceQuota
.
Spec
.
Scopes
)
>
0
{
scopes
:=
[]
string
{}
scopes
:=
make
([]
string
,
0
,
len
(
resourceQuota
.
Spec
.
Scopes
))
for
_
,
scope
:=
range
resourceQuota
.
Spec
.
Scopes
{
for
_
,
scope
:=
range
resourceQuota
.
Spec
.
Scopes
{
scopes
=
append
(
scopes
,
string
(
scope
))
scopes
=
append
(
scopes
,
string
(
scope
))
}
}
...
@@ -449,7 +449,7 @@ func describeQuota(resourceQuota *api.ResourceQuota) (string, error) {
...
@@ -449,7 +449,7 @@ func describeQuota(resourceQuota *api.ResourceQuota) (string, error) {
fmt
.
Fprintf
(
out
,
"Resource
\t
Used
\t
Hard
\n
"
)
fmt
.
Fprintf
(
out
,
"Resource
\t
Used
\t
Hard
\n
"
)
fmt
.
Fprintf
(
out
,
"--------
\t
----
\t
----
\n
"
)
fmt
.
Fprintf
(
out
,
"--------
\t
----
\t
----
\n
"
)
resources
:=
[]
api
.
ResourceName
{}
resources
:=
make
([]
api
.
ResourceName
,
0
,
len
(
resourceQuota
.
Status
.
Hard
))
for
resource
:=
range
resourceQuota
.
Status
.
Hard
{
for
resource
:=
range
resourceQuota
.
Status
.
Hard
{
resources
=
append
(
resources
,
resource
)
resources
=
append
(
resources
,
resource
)
}
}
...
@@ -920,7 +920,7 @@ func describeContainers(label string, containers []api.Container, containerStatu
...
@@ -920,7 +920,7 @@ func describeContainers(label string, containers []api.Container, containerStatu
}
}
func
describeContainerPorts
(
cPorts
[]
api
.
ContainerPort
)
string
{
func
describeContainerPorts
(
cPorts
[]
api
.
ContainerPort
)
string
{
ports
:=
[]
string
{}
ports
:=
make
([]
string
,
0
,
len
(
cPorts
))
for
_
,
cPort
:=
range
cPorts
{
for
_
,
cPort
:=
range
cPorts
{
ports
=
append
(
ports
,
fmt
.
Sprintf
(
"%d/%s"
,
cPort
.
ContainerPort
,
cPort
.
Protocol
))
ports
=
append
(
ports
,
fmt
.
Sprintf
(
"%d/%s"
,
cPort
.
ContainerPort
,
cPort
.
Protocol
))
}
}
...
@@ -1471,7 +1471,7 @@ func describeEndpoints(ep *api.Endpoints, events *api.EventList) (string, error)
...
@@ -1471,7 +1471,7 @@ func describeEndpoints(ep *api.Endpoints, events *api.EventList) (string, error)
for
i
:=
range
ep
.
Subsets
{
for
i
:=
range
ep
.
Subsets
{
subset
:=
&
ep
.
Subsets
[
i
]
subset
:=
&
ep
.
Subsets
[
i
]
addresses
:=
[]
string
{}
addresses
:=
make
([]
string
,
0
,
len
(
subset
.
Addresses
))
for
_
,
addr
:=
range
subset
.
Addresses
{
for
_
,
addr
:=
range
subset
.
Addresses
{
addresses
=
append
(
addresses
,
addr
.
IP
)
addresses
=
append
(
addresses
,
addr
.
IP
)
}
}
...
@@ -1481,7 +1481,7 @@ func describeEndpoints(ep *api.Endpoints, events *api.EventList) (string, error)
...
@@ -1481,7 +1481,7 @@ func describeEndpoints(ep *api.Endpoints, events *api.EventList) (string, error)
}
}
fmt
.
Fprintf
(
out
,
" Addresses:
\t
%s
\n
"
,
addressesString
)
fmt
.
Fprintf
(
out
,
" Addresses:
\t
%s
\n
"
,
addressesString
)
notReadyAddresses
:=
[]
string
{}
notReadyAddresses
:=
make
([]
string
,
0
,
len
(
subset
.
NotReadyAddresses
))
for
_
,
addr
:=
range
subset
.
NotReadyAddresses
{
for
_
,
addr
:=
range
subset
.
NotReadyAddresses
{
notReadyAddresses
=
append
(
notReadyAddresses
,
addr
.
IP
)
notReadyAddresses
=
append
(
notReadyAddresses
,
addr
.
IP
)
}
}
...
@@ -1655,7 +1655,7 @@ func describeNode(node *api.Node, nodeNonTerminatedPodsList *api.PodList, events
...
@@ -1655,7 +1655,7 @@ func describeNode(node *api.Node, nodeNonTerminatedPodsList *api.PodList, events
c
.
Message
)
c
.
Message
)
}
}
}
}
var
addresses
[]
string
addresses
:=
make
([]
string
,
0
,
len
(
node
.
Status
.
Addresses
))
for
_
,
address
:=
range
node
.
Status
.
Addresses
{
for
_
,
address
:=
range
node
.
Status
.
Addresses
{
addresses
=
append
(
addresses
,
address
.
Address
)
addresses
=
append
(
addresses
,
address
.
Address
)
}
}
...
@@ -1974,7 +1974,7 @@ func getDaemonSetsForLabels(c client.DaemonSetInterface, labelsToMatch labels.La
...
@@ -1974,7 +1974,7 @@ func getDaemonSetsForLabels(c client.DaemonSetInterface, labelsToMatch labels.La
func
printReplicationControllersByLabels
(
matchingRCs
[]
*
api
.
ReplicationController
)
string
{
func
printReplicationControllersByLabels
(
matchingRCs
[]
*
api
.
ReplicationController
)
string
{
// Format the matching RC's into strings.
// Format the matching RC's into strings.
var
rcStrings
[]
string
rcStrings
:=
make
([]
string
,
0
,
len
(
matchingRCs
))
for
_
,
controller
:=
range
matchingRCs
{
for
_
,
controller
:=
range
matchingRCs
{
rcStrings
=
append
(
rcStrings
,
fmt
.
Sprintf
(
"%s (%d/%d replicas created)"
,
controller
.
Name
,
controller
.
Status
.
Replicas
,
controller
.
Spec
.
Replicas
))
rcStrings
=
append
(
rcStrings
,
fmt
.
Sprintf
(
"%s (%d/%d replicas created)"
,
controller
.
Name
,
controller
.
Status
.
Replicas
,
controller
.
Spec
.
Replicas
))
}
}
...
@@ -1988,7 +1988,7 @@ func printReplicationControllersByLabels(matchingRCs []*api.ReplicationControlle
...
@@ -1988,7 +1988,7 @@ func printReplicationControllersByLabels(matchingRCs []*api.ReplicationControlle
func
printReplicaSetsByLabels
(
matchingRSs
[]
*
extensions
.
ReplicaSet
)
string
{
func
printReplicaSetsByLabels
(
matchingRSs
[]
*
extensions
.
ReplicaSet
)
string
{
// Format the matching ReplicaSets into strings.
// Format the matching ReplicaSets into strings.
var
rsStrings
[]
string
rsStrings
:=
make
([]
string
,
0
,
len
(
matchingRSs
))
for
_
,
rs
:=
range
matchingRSs
{
for
_
,
rs
:=
range
matchingRSs
{
rsStrings
=
append
(
rsStrings
,
fmt
.
Sprintf
(
"%s (%d/%d replicas created)"
,
rs
.
Name
,
rs
.
Status
.
Replicas
,
rs
.
Spec
.
Replicas
))
rsStrings
=
append
(
rsStrings
,
fmt
.
Sprintf
(
"%s (%d/%d replicas created)"
,
rs
.
Name
,
rs
.
Status
.
Replicas
,
rs
.
Spec
.
Replicas
))
}
}
...
@@ -2138,7 +2138,7 @@ func describeNetworkPolicy(networkPolicy *extensions.NetworkPolicy) (string, err
...
@@ -2138,7 +2138,7 @@ func describeNetworkPolicy(networkPolicy *extensions.NetworkPolicy) (string, err
// newErrNoDescriber creates a new ErrNoDescriber with the names of the provided types.
// newErrNoDescriber creates a new ErrNoDescriber with the names of the provided types.
func
newErrNoDescriber
(
types
...
reflect
.
Type
)
error
{
func
newErrNoDescriber
(
types
...
reflect
.
Type
)
error
{
names
:=
[]
string
{}
names
:=
make
([]
string
,
0
,
len
(
types
))
for
_
,
t
:=
range
types
{
for
_
,
t
:=
range
types
{
names
=
append
(
names
,
t
.
String
())
names
=
append
(
names
,
t
.
String
())
}
}
...
@@ -2177,7 +2177,7 @@ func (d *Describers) DescribeObject(exact interface{}, extra ...interface{}) (st
...
@@ -2177,7 +2177,7 @@ func (d *Describers) DescribeObject(exact interface{}, extra ...interface{}) (st
return
fns
[
0
]
.
Describe
(
exact
,
extra
...
)
return
fns
[
0
]
.
Describe
(
exact
,
extra
...
)
}
}
types
:=
[]
reflect
.
Type
{}
types
:=
make
([]
reflect
.
Type
,
0
,
len
(
extra
))
for
_
,
obj
:=
range
extra
{
for
_
,
obj
:=
range
extra
{
types
=
append
(
types
,
reflect
.
TypeOf
(
obj
))
types
=
append
(
types
,
reflect
.
TypeOf
(
obj
))
}
}
...
@@ -2202,14 +2202,15 @@ func (d *Describers) Add(fns ...interface{}) error {
...
@@ -2202,14 +2202,15 @@ func (d *Describers) Add(fns ...interface{}) error {
if
ft
.
Kind
()
!=
reflect
.
Func
{
if
ft
.
Kind
()
!=
reflect
.
Func
{
return
fmt
.
Errorf
(
"expected func, got: %v"
,
ft
)
return
fmt
.
Errorf
(
"expected func, got: %v"
,
ft
)
}
}
if
ft
.
NumIn
()
==
0
{
numIn
:=
ft
.
NumIn
()
if
numIn
==
0
{
return
fmt
.
Errorf
(
"expected at least one 'in' params, got: %v"
,
ft
)
return
fmt
.
Errorf
(
"expected at least one 'in' params, got: %v"
,
ft
)
}
}
if
ft
.
NumOut
()
!=
2
{
if
ft
.
NumOut
()
!=
2
{
return
fmt
.
Errorf
(
"expected two 'out' params - (string, error), got: %v"
,
ft
)
return
fmt
.
Errorf
(
"expected two 'out' params - (string, error), got: %v"
,
ft
)
}
}
types
:=
[]
reflect
.
Type
{}
types
:=
make
([]
reflect
.
Type
,
0
,
numIn
)
for
i
:=
0
;
i
<
ft
.
NumIn
()
;
i
++
{
for
i
:=
0
;
i
<
numIn
;
i
++
{
types
=
append
(
types
,
ft
.
In
(
i
))
types
=
append
(
types
,
ft
.
In
(
i
))
}
}
if
ft
.
Out
(
0
)
!=
reflect
.
TypeOf
(
string
(
""
))
{
if
ft
.
Out
(
0
)
!=
reflect
.
TypeOf
(
string
(
""
))
{
...
...
pkg/kubectl/history.go
View file @
a14a288c
...
@@ -101,7 +101,7 @@ func PrintRolloutHistory(historyInfo HistoryInfo, resource, name string) (string
...
@@ -101,7 +101,7 @@ func PrintRolloutHistory(historyInfo HistoryInfo, resource, name string) (string
return
fmt
.
Sprintf
(
"No rollout history found in %s %q"
,
resource
,
name
),
nil
return
fmt
.
Sprintf
(
"No rollout history found in %s %q"
,
resource
,
name
),
nil
}
}
// Sort the revisionToChangeCause map by revision
// Sort the revisionToChangeCause map by revision
var
revisions
[]
int64
revisions
:=
make
([]
int64
,
0
,
len
(
historyInfo
.
RevisionToTemplate
))
for
r
:=
range
historyInfo
.
RevisionToTemplate
{
for
r
:=
range
historyInfo
.
RevisionToTemplate
{
revisions
=
append
(
revisions
,
r
)
revisions
=
append
(
revisions
,
r
)
}
}
...
...
pkg/kubectl/kubectl.go
View file @
a14a288c
...
@@ -43,7 +43,7 @@ type NamespaceInfo struct {
...
@@ -43,7 +43,7 @@ type NamespaceInfo struct {
}
}
func
listOfImages
(
spec
*
api
.
PodSpec
)
[]
string
{
func
listOfImages
(
spec
*
api
.
PodSpec
)
[]
string
{
var
images
[]
string
images
:=
make
([]
string
,
0
,
len
(
spec
.
Containers
))
for
_
,
container
:=
range
spec
.
Containers
{
for
_
,
container
:=
range
spec
.
Containers
{
images
=
append
(
images
,
container
.
Image
)
images
=
append
(
images
,
container
.
Image
)
}
}
...
@@ -64,7 +64,7 @@ func NewThirdPartyResourceMapper(gvs []unversioned.GroupVersion, gvks []unversio
...
@@ -64,7 +64,7 @@ func NewThirdPartyResourceMapper(gvs []unversioned.GroupVersion, gvks []unversio
},
nil
},
nil
}
}
}
}
groupVersions
:=
[]
string
{}
groupVersions
:=
make
([]
string
,
0
,
len
(
gvs
))
for
ix
:=
range
gvs
{
for
ix
:=
range
gvs
{
groupVersions
=
append
(
groupVersions
,
gvs
[
ix
]
.
String
())
groupVersions
=
append
(
groupVersions
,
gvs
[
ix
]
.
String
())
}
}
...
...
pkg/kubectl/run.go
View file @
a14a288c
...
@@ -827,7 +827,7 @@ func (BasicPod) Generate(genericParams map[string]interface{}) (runtime.Object,
...
@@ -827,7 +827,7 @@ func (BasicPod) Generate(genericParams map[string]interface{}) (runtime.Object,
}
}
func
parseEnvs
(
envArray
[]
string
)
([]
api
.
EnvVar
,
error
)
{
func
parseEnvs
(
envArray
[]
string
)
([]
api
.
EnvVar
,
error
)
{
envs
:=
[]
api
.
EnvVar
{}
envs
:=
make
([]
api
.
EnvVar
,
0
,
len
(
envArray
))
for
_
,
env
:=
range
envArray
{
for
_
,
env
:=
range
envArray
{
pos
:=
strings
.
Index
(
env
,
"="
)
pos
:=
strings
.
Index
(
env
,
"="
)
if
pos
==
-
1
{
if
pos
==
-
1
{
...
...
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