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
265f80ee
Unverified
Commit
265f80ee
authored
Mar 22, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
Mar 22, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #75176 from mars1024/bugfix/hpa_not_working_in_kubectl_since_v1.13
make describers of different versions work properly when autoscaling/v2beta2 is not supported
parents
057ad6d4
814e1ca7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
158 additions
and
10 deletions
+158
-10
BUILD
pkg/kubectl/describe/versioned/BUILD
+2
-0
describe.go
pkg/kubectl/describe/versioned/describe.go
+58
-8
describe_test.go
pkg/kubectl/describe/versioned/describe_test.go
+98
-2
No files found.
pkg/kubectl/describe/versioned/BUILD
View file @
265f80ee
...
@@ -18,6 +18,7 @@ go_library(
...
@@ -18,6 +18,7 @@ go_library(
"//pkg/kubectl/util/slice:go_default_library",
"//pkg/kubectl/util/slice:go_default_library",
"//pkg/kubectl/util/storage:go_default_library",
"//pkg/kubectl/util/storage:go_default_library",
"//staging/src/k8s.io/api/apps/v1:go_default_library",
"//staging/src/k8s.io/api/apps/v1:go_default_library",
"//staging/src/k8s.io/api/autoscaling/v1:go_default_library",
"//staging/src/k8s.io/api/autoscaling/v2beta2:go_default_library",
"//staging/src/k8s.io/api/autoscaling/v2beta2:go_default_library",
"//staging/src/k8s.io/api/batch/v1:go_default_library",
"//staging/src/k8s.io/api/batch/v1:go_default_library",
"//staging/src/k8s.io/api/batch/v1beta1:go_default_library",
"//staging/src/k8s.io/api/batch/v1beta1:go_default_library",
...
@@ -73,6 +74,7 @@ go_test(
...
@@ -73,6 +74,7 @@ go_test(
deps = [
deps = [
"//pkg/kubectl/describe:go_default_library",
"//pkg/kubectl/describe:go_default_library",
"//staging/src/k8s.io/api/apps/v1:go_default_library",
"//staging/src/k8s.io/api/apps/v1:go_default_library",
"//staging/src/k8s.io/api/autoscaling/v1:go_default_library",
"//staging/src/k8s.io/api/autoscaling/v2beta2:go_default_library",
"//staging/src/k8s.io/api/autoscaling/v2beta2:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/api/networking/v1:go_default_library",
"//staging/src/k8s.io/api/networking/v1:go_default_library",
...
...
pkg/kubectl/describe/versioned/describe.go
View file @
265f80ee
...
@@ -33,6 +33,7 @@ import (
...
@@ -33,6 +33,7 @@ import (
"github.com/fatih/camelcase"
"github.com/fatih/camelcase"
appsv1
"k8s.io/api/apps/v1"
appsv1
"k8s.io/api/apps/v1"
autoscalingv1
"k8s.io/api/autoscaling/v1"
autoscalingv2beta2
"k8s.io/api/autoscaling/v2beta2"
autoscalingv2beta2
"k8s.io/api/autoscaling/v2beta2"
batchv1
"k8s.io/api/batch/v1"
batchv1
"k8s.io/api/batch/v1"
batchv1beta1
"k8s.io/api/batch/v1beta1"
batchv1beta1
"k8s.io/api/batch/v1beta1"
...
@@ -3074,20 +3075,31 @@ type HorizontalPodAutoscalerDescriber struct {
...
@@ -3074,20 +3075,31 @@ type HorizontalPodAutoscalerDescriber struct {
}
}
func
(
d
*
HorizontalPodAutoscalerDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
describe
.
DescriberSettings
)
(
string
,
error
)
{
func
(
d
*
HorizontalPodAutoscalerDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
describe
.
DescriberSettings
)
(
string
,
error
)
{
hpa
,
err
:=
d
.
client
.
AutoscalingV2beta2
()
.
HorizontalPodAutoscalers
(
namespace
)
.
Get
(
name
,
metav1
.
GetOptions
{})
var
events
*
corev1
.
EventList
if
err
!=
nil
{
return
""
,
err
// autoscaling/v2beta2 is introduced since v1.12 and autoscaling/v1 does not have full backward compatibility
// with autoscaling/v2beta2, so describer will try to get and describe hpa v2beta2 object firstly, if it fails,
// describer will fall back to do with hpa v1 object
hpaV2beta2
,
err
:=
d
.
client
.
AutoscalingV2beta2
()
.
HorizontalPodAutoscalers
(
namespace
)
.
Get
(
name
,
metav1
.
GetOptions
{})
if
err
==
nil
{
if
describerSettings
.
ShowEvents
{
events
,
_
=
d
.
client
.
CoreV1
()
.
Events
(
namespace
)
.
Search
(
scheme
.
Scheme
,
hpaV2beta2
)
}
return
describeHorizontalPodAutoscalerV2beta2
(
hpaV2beta2
,
events
,
d
)
}
}
var
events
*
corev1
.
EventList
hpaV1
,
err
:=
d
.
client
.
AutoscalingV1
()
.
HorizontalPodAutoscalers
(
namespace
)
.
Get
(
name
,
metav1
.
GetOptions
{})
if
describerSettings
.
ShowEvents
{
if
err
==
nil
{
events
,
_
=
d
.
client
.
CoreV1
()
.
Events
(
namespace
)
.
Search
(
scheme
.
Scheme
,
hpa
)
if
describerSettings
.
ShowEvents
{
events
,
_
=
d
.
client
.
CoreV1
()
.
Events
(
namespace
)
.
Search
(
scheme
.
Scheme
,
hpaV1
)
}
return
describeHorizontalPodAutoscalerV1
(
hpaV1
,
events
,
d
)
}
}
return
describeHorizontalPodAutoscaler
(
hpa
,
events
,
d
)
return
""
,
err
}
}
func
describeHorizontalPodAutoscaler
(
hpa
*
autoscalingv2beta2
.
HorizontalPodAutoscaler
,
events
*
corev1
.
EventList
,
d
*
HorizontalPodAutoscalerDescriber
)
(
string
,
error
)
{
func
describeHorizontalPodAutoscaler
V2beta2
(
hpa
*
autoscalingv2beta2
.
HorizontalPodAutoscaler
,
events
*
corev1
.
EventList
,
d
*
HorizontalPodAutoscalerDescriber
)
(
string
,
error
)
{
return
tabbedString
(
func
(
out
io
.
Writer
)
error
{
return
tabbedString
(
func
(
out
io
.
Writer
)
error
{
w
:=
NewPrefixWriter
(
out
)
w
:=
NewPrefixWriter
(
out
)
w
.
Write
(
LEVEL_0
,
"Name:
\t
%s
\n
"
,
hpa
.
Name
)
w
.
Write
(
LEVEL_0
,
"Name:
\t
%s
\n
"
,
hpa
.
Name
)
...
@@ -3188,6 +3200,44 @@ func describeHorizontalPodAutoscaler(hpa *autoscalingv2beta2.HorizontalPodAutosc
...
@@ -3188,6 +3200,44 @@ func describeHorizontalPodAutoscaler(hpa *autoscalingv2beta2.HorizontalPodAutosc
})
})
}
}
func
describeHorizontalPodAutoscalerV1
(
hpa
*
autoscalingv1
.
HorizontalPodAutoscaler
,
events
*
corev1
.
EventList
,
d
*
HorizontalPodAutoscalerDescriber
)
(
string
,
error
)
{
return
tabbedString
(
func
(
out
io
.
Writer
)
error
{
w
:=
NewPrefixWriter
(
out
)
w
.
Write
(
LEVEL_0
,
"Name:
\t
%s
\n
"
,
hpa
.
Name
)
w
.
Write
(
LEVEL_0
,
"Namespace:
\t
%s
\n
"
,
hpa
.
Namespace
)
printLabelsMultiline
(
w
,
"Labels"
,
hpa
.
Labels
)
printAnnotationsMultiline
(
w
,
"Annotations"
,
hpa
.
Annotations
)
w
.
Write
(
LEVEL_0
,
"CreationTimestamp:
\t
%s
\n
"
,
hpa
.
CreationTimestamp
.
Time
.
Format
(
time
.
RFC1123Z
))
w
.
Write
(
LEVEL_0
,
"Reference:
\t
%s/%s
\n
"
,
hpa
.
Spec
.
ScaleTargetRef
.
Kind
,
hpa
.
Spec
.
ScaleTargetRef
.
Name
)
if
hpa
.
Spec
.
TargetCPUUtilizationPercentage
!=
nil
{
w
.
Write
(
LEVEL_0
,
"Target CPU utilization:
\t
%d%%
\n
"
,
*
hpa
.
Spec
.
TargetCPUUtilizationPercentage
)
current
:=
"<unknown>"
if
hpa
.
Status
.
CurrentCPUUtilizationPercentage
!=
nil
{
current
=
fmt
.
Sprintf
(
"%d"
,
*
hpa
.
Status
.
CurrentCPUUtilizationPercentage
)
}
w
.
Write
(
LEVEL_0
,
"Current CPU utilization:
\t
%s%%
\n
"
,
current
)
}
minReplicas
:=
"<unset>"
if
hpa
.
Spec
.
MinReplicas
!=
nil
{
minReplicas
=
fmt
.
Sprintf
(
"%d"
,
*
hpa
.
Spec
.
MinReplicas
)
}
w
.
Write
(
LEVEL_0
,
"Min replicas:
\t
%s
\n
"
,
minReplicas
)
w
.
Write
(
LEVEL_0
,
"Max replicas:
\t
%d
\n
"
,
hpa
.
Spec
.
MaxReplicas
)
w
.
Write
(
LEVEL_0
,
"%s pods:
\t
"
,
hpa
.
Spec
.
ScaleTargetRef
.
Kind
)
w
.
Write
(
LEVEL_0
,
"%d current / %d desired
\n
"
,
hpa
.
Status
.
CurrentReplicas
,
hpa
.
Status
.
DesiredReplicas
)
if
events
!=
nil
{
DescribeEvents
(
events
,
w
)
}
return
nil
})
}
func
describeNodeResource
(
nodeNonTerminatedPodsList
*
corev1
.
PodList
,
node
*
corev1
.
Node
,
w
PrefixWriter
)
{
func
describeNodeResource
(
nodeNonTerminatedPodsList
*
corev1
.
PodList
,
node
*
corev1
.
Node
,
w
PrefixWriter
)
{
w
.
Write
(
LEVEL_0
,
"Non-terminated Pods:
\t
(%d in total)
\n
"
,
len
(
nodeNonTerminatedPodsList
.
Items
))
w
.
Write
(
LEVEL_0
,
"Non-terminated Pods:
\t
(%d in total)
\n
"
,
len
(
nodeNonTerminatedPodsList
.
Items
))
w
.
Write
(
LEVEL_1
,
"Namespace
\t
Name
\t\t
CPU Requests
\t
CPU Limits
\t
Memory Requests
\t
Memory Limits
\t
AGE
\n
"
)
w
.
Write
(
LEVEL_1
,
"Namespace
\t
Name
\t\t
CPU Requests
\t
CPU Limits
\t
Memory Requests
\t
Memory Limits
\t
AGE
\n
"
)
...
...
pkg/kubectl/describe/versioned/describe_test.go
View file @
265f80ee
...
@@ -26,6 +26,7 @@ import (
...
@@ -26,6 +26,7 @@ import (
"time"
"time"
appsv1
"k8s.io/api/apps/v1"
appsv1
"k8s.io/api/apps/v1"
autoscalingv1
"k8s.io/api/autoscaling/v1"
autoscalingv2beta2
"k8s.io/api/autoscaling/v2beta2"
autoscalingv2beta2
"k8s.io/api/autoscaling/v2beta2"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
corev1
"k8s.io/api/core/v1"
corev1
"k8s.io/api/core/v1"
...
@@ -1628,7 +1629,7 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
...
@@ -1628,7 +1629,7 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"unable to parse label selector: %v"
,
err
)
t
.
Errorf
(
"unable to parse label selector: %v"
,
err
)
}
}
tests
:=
[]
struct
{
tests
V2beta2
:=
[]
struct
{
name
string
name
string
hpa
autoscalingv2beta2
.
HorizontalPodAutoscaler
hpa
autoscalingv2beta2
.
HorizontalPodAutoscaler
}{
}{
...
@@ -2270,7 +2271,102 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
...
@@ -2270,7 +2271,102 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
},
},
}
}
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
testsV2beta2
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
test
.
hpa
.
ObjectMeta
=
metav1
.
ObjectMeta
{
Name
:
"bar"
,
Namespace
:
"foo"
,
}
fake
:=
fake
.
NewSimpleClientset
(
&
test
.
hpa
)
desc
:=
HorizontalPodAutoscalerDescriber
{
fake
}
str
,
err
:=
desc
.
Describe
(
"foo"
,
"bar"
,
describe
.
DescriberSettings
{
ShowEvents
:
true
})
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error for test %s: %v"
,
test
.
name
,
err
)
}
if
str
==
""
{
t
.
Errorf
(
"Unexpected empty string for test %s. Expected HPA Describer output"
,
test
.
name
)
}
t
.
Logf
(
"Description for %q:
\n
%s"
,
test
.
name
,
str
)
})
}
testsV1
:=
[]
struct
{
name
string
hpa
autoscalingv1
.
HorizontalPodAutoscaler
}{
{
"minReplicas unset"
,
autoscalingv1
.
HorizontalPodAutoscaler
{
Spec
:
autoscalingv1
.
HorizontalPodAutoscalerSpec
{
ScaleTargetRef
:
autoscalingv1
.
CrossVersionObjectReference
{
Name
:
"some-rc"
,
Kind
:
"ReplicationController"
,
},
MaxReplicas
:
10
,
},
Status
:
autoscalingv1
.
HorizontalPodAutoscalerStatus
{
CurrentReplicas
:
4
,
DesiredReplicas
:
5
,
},
},
},
{
"minReplicas set"
,
autoscalingv1
.
HorizontalPodAutoscaler
{
Spec
:
autoscalingv1
.
HorizontalPodAutoscalerSpec
{
ScaleTargetRef
:
autoscalingv1
.
CrossVersionObjectReference
{
Name
:
"some-rc"
,
Kind
:
"ReplicationController"
,
},
MinReplicas
:
&
minReplicasVal
,
MaxReplicas
:
10
,
},
Status
:
autoscalingv1
.
HorizontalPodAutoscalerStatus
{
CurrentReplicas
:
4
,
DesiredReplicas
:
5
,
},
},
},
{
"with target no current"
,
autoscalingv1
.
HorizontalPodAutoscaler
{
Spec
:
autoscalingv1
.
HorizontalPodAutoscalerSpec
{
ScaleTargetRef
:
autoscalingv1
.
CrossVersionObjectReference
{
Name
:
"some-rc"
,
Kind
:
"ReplicationController"
,
},
MinReplicas
:
&
minReplicasVal
,
MaxReplicas
:
10
,
TargetCPUUtilizationPercentage
:
&
targetUtilizationVal
,
},
Status
:
autoscalingv1
.
HorizontalPodAutoscalerStatus
{
CurrentReplicas
:
4
,
DesiredReplicas
:
5
,
},
},
},
{
"with target and current"
,
autoscalingv1
.
HorizontalPodAutoscaler
{
Spec
:
autoscalingv1
.
HorizontalPodAutoscalerSpec
{
ScaleTargetRef
:
autoscalingv1
.
CrossVersionObjectReference
{
Name
:
"some-rc"
,
Kind
:
"ReplicationController"
,
},
MinReplicas
:
&
minReplicasVal
,
MaxReplicas
:
10
,
TargetCPUUtilizationPercentage
:
&
targetUtilizationVal
,
},
Status
:
autoscalingv1
.
HorizontalPodAutoscalerStatus
{
CurrentReplicas
:
4
,
DesiredReplicas
:
5
,
CurrentCPUUtilizationPercentage
:
&
currentUtilizationVal
,
},
},
},
}
for
_
,
test
:=
range
testsV1
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
test
.
hpa
.
ObjectMeta
=
metav1
.
ObjectMeta
{
test
.
hpa
.
ObjectMeta
=
metav1
.
ObjectMeta
{
Name
:
"bar"
,
Name
:
"bar"
,
...
...
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