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
27d51f09
Commit
27d51f09
authored
Oct 14, 2016
by
Ivan Shvedunov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove duplicate code from kubectl describe
parent
9b3ca2fb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
124 deletions
+67
-124
describe.go
pkg/kubectl/describe.go
+67
-124
No files found.
pkg/kubectl/describe.go
View file @
27d51f09
...
@@ -212,6 +212,71 @@ func describeNamespace(namespace *api.Namespace, resourceQuotaList *api.Resource
...
@@ -212,6 +212,71 @@ func describeNamespace(namespace *api.Namespace, resourceQuotaList *api.Resource
})
})
}
}
func
describeLimitRangeSpec
(
spec
api
.
LimitRangeSpec
,
prefix
string
,
w
io
.
Writer
)
{
for
i
:=
range
spec
.
Limits
{
item
:=
spec
.
Limits
[
i
]
maxResources
:=
item
.
Max
minResources
:=
item
.
Min
defaultLimitResources
:=
item
.
Default
defaultRequestResources
:=
item
.
DefaultRequest
ratio
:=
item
.
MaxLimitRequestRatio
set
:=
map
[
api
.
ResourceName
]
bool
{}
for
k
:=
range
maxResources
{
set
[
k
]
=
true
}
for
k
:=
range
minResources
{
set
[
k
]
=
true
}
for
k
:=
range
defaultLimitResources
{
set
[
k
]
=
true
}
for
k
:=
range
defaultRequestResources
{
set
[
k
]
=
true
}
for
k
:=
range
ratio
{
set
[
k
]
=
true
}
for
k
:=
range
set
{
// if no value is set, we output -
maxValue
:=
"-"
minValue
:=
"-"
defaultLimitValue
:=
"-"
defaultRequestValue
:=
"-"
ratioValue
:=
"-"
maxQuantity
,
maxQuantityFound
:=
maxResources
[
k
]
if
maxQuantityFound
{
maxValue
=
maxQuantity
.
String
()
}
minQuantity
,
minQuantityFound
:=
minResources
[
k
]
if
minQuantityFound
{
minValue
=
minQuantity
.
String
()
}
defaultLimitQuantity
,
defaultLimitQuantityFound
:=
defaultLimitResources
[
k
]
if
defaultLimitQuantityFound
{
defaultLimitValue
=
defaultLimitQuantity
.
String
()
}
defaultRequestQuantity
,
defaultRequestQuantityFound
:=
defaultRequestResources
[
k
]
if
defaultRequestQuantityFound
{
defaultRequestValue
=
defaultRequestQuantity
.
String
()
}
ratioQuantity
,
ratioQuantityFound
:=
ratio
[
k
]
if
ratioQuantityFound
{
ratioValue
=
ratioQuantity
.
String
()
}
msg
:=
"%s%s
\t
%v
\t
%v
\t
%v
\t
%v
\t
%v
\t
%v
\n
"
fmt
.
Fprintf
(
w
,
msg
,
prefix
,
item
.
Type
,
k
,
minValue
,
maxValue
,
defaultRequestValue
,
defaultLimitValue
,
ratioValue
)
}
}
}
// DescribeLimitRanges merges a set of limit range items into a single tabular description
// DescribeLimitRanges merges a set of limit range items into a single tabular description
func
DescribeLimitRanges
(
limitRanges
*
api
.
LimitRangeList
,
w
io
.
Writer
)
{
func
DescribeLimitRanges
(
limitRanges
*
api
.
LimitRangeList
,
w
io
.
Writer
)
{
if
len
(
limitRanges
.
Items
)
==
0
{
if
len
(
limitRanges
.
Items
)
==
0
{
...
@@ -221,68 +286,7 @@ func DescribeLimitRanges(limitRanges *api.LimitRangeList, w io.Writer) {
...
@@ -221,68 +286,7 @@ func DescribeLimitRanges(limitRanges *api.LimitRangeList, w io.Writer) {
fmt
.
Fprintf
(
w
,
"Resource Limits
\n
Type
\t
Resource
\t
Min
\t
Max
\t
Default Request
\t
Default Limit
\t
Max Limit/Request Ratio
\n
"
)
fmt
.
Fprintf
(
w
,
"Resource Limits
\n
Type
\t
Resource
\t
Min
\t
Max
\t
Default Request
\t
Default Limit
\t
Max Limit/Request Ratio
\n
"
)
fmt
.
Fprintf
(
w
,
" ----
\t
--------
\t
---
\t
---
\t
---------------
\t
-------------
\t
-----------------------
\n
"
)
fmt
.
Fprintf
(
w
,
" ----
\t
--------
\t
---
\t
---
\t
---------------
\t
-------------
\t
-----------------------
\n
"
)
for
_
,
limitRange
:=
range
limitRanges
.
Items
{
for
_
,
limitRange
:=
range
limitRanges
.
Items
{
for
i
:=
range
limitRange
.
Spec
.
Limits
{
describeLimitRangeSpec
(
limitRange
.
Spec
,
" "
,
w
)
item
:=
limitRange
.
Spec
.
Limits
[
i
]
maxResources
:=
item
.
Max
minResources
:=
item
.
Min
defaultLimitResources
:=
item
.
Default
defaultRequestResources
:=
item
.
DefaultRequest
ratio
:=
item
.
MaxLimitRequestRatio
set
:=
map
[
api
.
ResourceName
]
bool
{}
for
k
:=
range
maxResources
{
set
[
k
]
=
true
}
for
k
:=
range
minResources
{
set
[
k
]
=
true
}
for
k
:=
range
defaultLimitResources
{
set
[
k
]
=
true
}
for
k
:=
range
defaultRequestResources
{
set
[
k
]
=
true
}
for
k
:=
range
ratio
{
set
[
k
]
=
true
}
for
k
:=
range
set
{
// if no value is set, we output -
maxValue
:=
"-"
minValue
:=
"-"
defaultLimitValue
:=
"-"
defaultRequestValue
:=
"-"
ratioValue
:=
"-"
maxQuantity
,
maxQuantityFound
:=
maxResources
[
k
]
if
maxQuantityFound
{
maxValue
=
maxQuantity
.
String
()
}
minQuantity
,
minQuantityFound
:=
minResources
[
k
]
if
minQuantityFound
{
minValue
=
minQuantity
.
String
()
}
defaultLimitQuantity
,
defaultLimitQuantityFound
:=
defaultLimitResources
[
k
]
if
defaultLimitQuantityFound
{
defaultLimitValue
=
defaultLimitQuantity
.
String
()
}
defaultRequestQuantity
,
defaultRequestQuantityFound
:=
defaultRequestResources
[
k
]
if
defaultRequestQuantityFound
{
defaultRequestValue
=
defaultRequestQuantity
.
String
()
}
ratioQuantity
,
ratioQuantityFound
:=
ratio
[
k
]
if
ratioQuantityFound
{
ratioValue
=
ratioQuantity
.
String
()
}
msg
:=
" %s
\t
%v
\t
%v
\t
%v
\t
%v
\t
%v
\t
%v
\n
"
fmt
.
Fprintf
(
w
,
msg
,
item
.
Type
,
k
,
minValue
,
maxValue
,
defaultRequestValue
,
defaultLimitValue
,
ratioValue
)
}
}
}
}
}
}
...
@@ -350,68 +354,7 @@ func describeLimitRange(limitRange *api.LimitRange) (string, error) {
...
@@ -350,68 +354,7 @@ func describeLimitRange(limitRange *api.LimitRange) (string, error) {
fmt
.
Fprintf
(
out
,
"Namespace:
\t
%s
\n
"
,
limitRange
.
Namespace
)
fmt
.
Fprintf
(
out
,
"Namespace:
\t
%s
\n
"
,
limitRange
.
Namespace
)
fmt
.
Fprintf
(
out
,
"Type
\t
Resource
\t
Min
\t
Max
\t
Default Request
\t
Default Limit
\t
Max Limit/Request Ratio
\n
"
)
fmt
.
Fprintf
(
out
,
"Type
\t
Resource
\t
Min
\t
Max
\t
Default Request
\t
Default Limit
\t
Max Limit/Request Ratio
\n
"
)
fmt
.
Fprintf
(
out
,
"----
\t
--------
\t
---
\t
---
\t
---------------
\t
-------------
\t
-----------------------
\n
"
)
fmt
.
Fprintf
(
out
,
"----
\t
--------
\t
---
\t
---
\t
---------------
\t
-------------
\t
-----------------------
\n
"
)
for
i
:=
range
limitRange
.
Spec
.
Limits
{
describeLimitRangeSpec
(
limitRange
.
Spec
,
""
,
out
)
item
:=
limitRange
.
Spec
.
Limits
[
i
]
maxResources
:=
item
.
Max
minResources
:=
item
.
Min
defaultLimitResources
:=
item
.
Default
defaultRequestResources
:=
item
.
DefaultRequest
ratio
:=
item
.
MaxLimitRequestRatio
set
:=
map
[
api
.
ResourceName
]
bool
{}
for
k
:=
range
maxResources
{
set
[
k
]
=
true
}
for
k
:=
range
minResources
{
set
[
k
]
=
true
}
for
k
:=
range
defaultLimitResources
{
set
[
k
]
=
true
}
for
k
:=
range
defaultRequestResources
{
set
[
k
]
=
true
}
for
k
:=
range
ratio
{
set
[
k
]
=
true
}
for
k
:=
range
set
{
// if no value is set, we output -
maxValue
:=
"-"
minValue
:=
"-"
defaultLimitValue
:=
"-"
defaultRequestValue
:=
"-"
ratioValue
:=
"-"
maxQuantity
,
maxQuantityFound
:=
maxResources
[
k
]
if
maxQuantityFound
{
maxValue
=
maxQuantity
.
String
()
}
minQuantity
,
minQuantityFound
:=
minResources
[
k
]
if
minQuantityFound
{
minValue
=
minQuantity
.
String
()
}
defaultLimitQuantity
,
defaultLimitQuantityFound
:=
defaultLimitResources
[
k
]
if
defaultLimitQuantityFound
{
defaultLimitValue
=
defaultLimitQuantity
.
String
()
}
defaultRequestQuantity
,
defaultRequestQuantityFound
:=
defaultRequestResources
[
k
]
if
defaultRequestQuantityFound
{
defaultRequestValue
=
defaultRequestQuantity
.
String
()
}
ratioQuantity
,
ratioQuantityFound
:=
ratio
[
k
]
if
ratioQuantityFound
{
ratioValue
=
ratioQuantity
.
String
()
}
msg
:=
"%v
\t
%v
\t
%v
\t
%v
\t
%v
\t
%v
\t
%v
\n
"
fmt
.
Fprintf
(
out
,
msg
,
item
.
Type
,
k
,
minValue
,
maxValue
,
defaultRequestValue
,
defaultLimitValue
,
ratioValue
)
}
}
return
nil
return
nil
})
})
}
}
...
...
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