Merge pull request #83899 from wojtek-t/describe_lease_in_node
Add information from Lease to kubectl describe node Kubernetes-commit: 4fa7d423014b98274f5c9e89eb7d0a1c8186e4af
This commit is contained in:
commit
5d0b8f2404
|
@ -588,11 +588,11 @@
|
|||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery",
|
||||
"Rev": "fb3eea214746"
|
||||
"Rev": "86f2f1b9c076"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/cli-runtime",
|
||||
"Rev": "c327aea27dcc"
|
||||
"Rev": "5e0efc75cd33"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/client-go",
|
||||
|
@ -604,7 +604,7 @@
|
|||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/component-base",
|
||||
"Rev": "ca590c444ad5"
|
||||
"Rev": "d338b9159fb6"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/gengo",
|
||||
|
|
12
go.mod
12
go.mod
|
@ -36,10 +36,10 @@ require (
|
|||
gopkg.in/yaml.v2 v2.2.4
|
||||
gotest.tools v2.2.0+incompatible // indirect
|
||||
k8s.io/api v0.0.0-20191010143144-fbf594f18f80
|
||||
k8s.io/apimachinery v0.0.0-20191014065749-fb3eea214746
|
||||
k8s.io/cli-runtime v0.0.0-20191014074540-c327aea27dcc
|
||||
k8s.io/apimachinery v0.0.0-20191016060620-86f2f1b9c076
|
||||
k8s.io/cli-runtime v0.0.0-20191016113839-5e0efc75cd33
|
||||
k8s.io/client-go v0.0.0-20191014070654-bd505ee787b2
|
||||
k8s.io/component-base v0.0.0-20191014071552-ca590c444ad5
|
||||
k8s.io/component-base v0.0.0-20191016230640-d338b9159fb6
|
||||
k8s.io/klog v1.0.0
|
||||
k8s.io/kube-openapi v0.0.0-20190816220812-743ec37842bf
|
||||
k8s.io/metrics v0.0.0-20191014074242-8b0351268f72
|
||||
|
@ -57,10 +57,10 @@ replace (
|
|||
golang.org/x/text => golang.org/x/text v0.3.1-0.20181227161524-e6919f6577db
|
||||
golang.org/x/time => golang.org/x/time v0.0.0-20161028155119-f51c12702a4d
|
||||
k8s.io/api => k8s.io/api v0.0.0-20191010143144-fbf594f18f80
|
||||
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20191014065749-fb3eea214746
|
||||
k8s.io/cli-runtime => k8s.io/cli-runtime v0.0.0-20191014074540-c327aea27dcc
|
||||
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20191016060620-86f2f1b9c076
|
||||
k8s.io/cli-runtime => k8s.io/cli-runtime v0.0.0-20191016113839-5e0efc75cd33
|
||||
k8s.io/client-go => k8s.io/client-go v0.0.0-20191014070654-bd505ee787b2
|
||||
k8s.io/code-generator => k8s.io/code-generator v0.0.0-20191003035328-700b1226c0bd
|
||||
k8s.io/component-base => k8s.io/component-base v0.0.0-20191014071552-ca590c444ad5
|
||||
k8s.io/component-base => k8s.io/component-base v0.0.0-20191016230640-d338b9159fb6
|
||||
k8s.io/metrics => k8s.io/metrics v0.0.0-20191014074242-8b0351268f72
|
||||
)
|
||||
|
|
6
go.sum
6
go.sum
|
@ -291,11 +291,11 @@ gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81
|
|||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
k8s.io/api v0.0.0-20191010143144-fbf594f18f80/go.mod h1:X3kixOyiuC4u4LU6y2BxLg5tsvw+hrMhstfga7LZ4Gw=
|
||||
k8s.io/apimachinery v0.0.0-20191014065749-fb3eea214746/go.mod h1:92mWDd8Ji2sw2157KIgino5wCxffA8KSvhW2oY4ypdw=
|
||||
k8s.io/cli-runtime v0.0.0-20191014074540-c327aea27dcc/go.mod h1:ZUJqMOunF/KYCXovzu04AcIbHPhzoMmFYjrFhGGp9FI=
|
||||
k8s.io/apimachinery v0.0.0-20191016060620-86f2f1b9c076/go.mod h1:92mWDd8Ji2sw2157KIgino5wCxffA8KSvhW2oY4ypdw=
|
||||
k8s.io/cli-runtime v0.0.0-20191016113839-5e0efc75cd33/go.mod h1:t0eCH0uXM/ai4gBeT0RS+cojWdhCJtVS7yQ3dA8OS1s=
|
||||
k8s.io/client-go v0.0.0-20191014070654-bd505ee787b2/go.mod h1:ltlqKktkJqApstv/eMdrdx6j1zT39NpwqlWAH747iSM=
|
||||
k8s.io/code-generator v0.0.0-20191003035328-700b1226c0bd/go.mod h1:HC9p4y3SBN+txSs8x57qmNPXFZ/CxdCHiDTNnocCSEw=
|
||||
k8s.io/component-base v0.0.0-20191014071552-ca590c444ad5/go.mod h1:K7cm+qApREO5hh5gsrxxeiL1BbWYNzMXw731icihE2Q=
|
||||
k8s.io/component-base v0.0.0-20191016230640-d338b9159fb6/go.mod h1:L2lcIF6P6N33EyqL0ntnoBvJ6t724ev4LzCc0yjn26g=
|
||||
k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
|
||||
k8s.io/gengo v0.0.0-20190822140433-26a664648505/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
|
||||
k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
|
||||
|
|
|
@ -39,6 +39,7 @@ import (
|
|||
batchv1 "k8s.io/api/batch/v1"
|
||||
batchv1beta1 "k8s.io/api/batch/v1beta1"
|
||||
certificatesv1beta1 "k8s.io/api/certificates/v1beta1"
|
||||
coordinationv1 "k8s.io/api/coordination/v1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
discoveryv1alpha1 "k8s.io/api/discovery/v1alpha1"
|
||||
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
|
||||
|
@ -3000,6 +3001,15 @@ func (d *NodeDescriber) Describe(namespace, name string, describerSettings descr
|
|||
return "", err
|
||||
}
|
||||
|
||||
lease, err := d.CoordinationV1().Leases(corev1.NamespaceNodeLease).Get(name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
if !errors.IsNotFound(err) {
|
||||
return "", err
|
||||
}
|
||||
// Corresponding Lease object doesn't exist - print it accordingly.
|
||||
lease = nil
|
||||
}
|
||||
|
||||
fieldSelector, err := fields.ParseSelector("spec.nodeName=" + name + ",status.phase!=" + string(corev1.PodSucceeded) + ",status.phase!=" + string(corev1.PodFailed))
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
@ -3026,10 +3036,10 @@ func (d *NodeDescriber) Describe(namespace, name string, describerSettings descr
|
|||
}
|
||||
}
|
||||
|
||||
return describeNode(node, nodeNonTerminatedPodsList, events, canViewPods)
|
||||
return describeNode(node, lease, nodeNonTerminatedPodsList, events, canViewPods)
|
||||
}
|
||||
|
||||
func describeNode(node *corev1.Node, nodeNonTerminatedPodsList *corev1.PodList, events *corev1.EventList, canViewPods bool) (string, error) {
|
||||
func describeNode(node *corev1.Node, lease *coordinationv1.Lease, nodeNonTerminatedPodsList *corev1.PodList, events *corev1.EventList, canViewPods bool) (string, error) {
|
||||
return tabbedString(func(out io.Writer) error {
|
||||
w := NewPrefixWriter(out)
|
||||
w.Write(LEVEL_0, "Name:\t%s\n", node.Name)
|
||||
|
@ -3043,6 +3053,24 @@ func describeNode(node *corev1.Node, nodeNonTerminatedPodsList *corev1.PodList,
|
|||
w.Write(LEVEL_0, "CreationTimestamp:\t%s\n", node.CreationTimestamp.Time.Format(time.RFC1123Z))
|
||||
printNodeTaintsMultiline(w, "Taints", node.Spec.Taints)
|
||||
w.Write(LEVEL_0, "Unschedulable:\t%v\n", node.Spec.Unschedulable)
|
||||
|
||||
w.Write(LEVEL_0, "Lease:\n")
|
||||
holderIdentity := "<unset>"
|
||||
if lease != nil && lease.Spec.HolderIdentity != nil {
|
||||
holderIdentity = *lease.Spec.HolderIdentity
|
||||
}
|
||||
w.Write(LEVEL_1, "HolderIdentity:\t%s\n", holderIdentity)
|
||||
acquireTime := "<unset>"
|
||||
if lease != nil && lease.Spec.AcquireTime != nil {
|
||||
acquireTime = lease.Spec.AcquireTime.Time.Format(time.RFC1123Z)
|
||||
}
|
||||
w.Write(LEVEL_1, "AcquireTime:\t%s\n", acquireTime)
|
||||
renewTime := "<unset>"
|
||||
if lease != nil && lease.Spec.RenewTime != nil {
|
||||
renewTime = lease.Spec.RenewTime.Time.Format(time.RFC1123Z)
|
||||
}
|
||||
w.Write(LEVEL_1, "RenewTime:\t%s\n", renewTime)
|
||||
|
||||
if len(node.Status.Conditions) > 0 {
|
||||
w.Write(LEVEL_0, "Conditions:\n Type\tStatus\tLastHeartbeatTime\tLastTransitionTime\tReason\tMessage\n")
|
||||
w.Write(LEVEL_1, "----\t------\t-----------------\t------------------\t------\t-------\n")
|
||||
|
|
|
@ -28,6 +28,7 @@ import (
|
|||
appsv1 "k8s.io/api/apps/v1"
|
||||
autoscalingv1 "k8s.io/api/autoscaling/v1"
|
||||
autoscalingv2beta2 "k8s.io/api/autoscaling/v2beta2"
|
||||
coordinationv1 "k8s.io/api/coordination/v1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
discoveryv1alpha1 "k8s.io/api/discovery/v1alpha1"
|
||||
networkingv1 "k8s.io/api/networking/v1"
|
||||
|
@ -3179,15 +3180,29 @@ Events: <none>` + "\n"
|
|||
}
|
||||
|
||||
func TestDescribeNode(t *testing.T) {
|
||||
fake := fake.NewSimpleClientset(&corev1.Node{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "bar",
|
||||
Namespace: "foo",
|
||||
holderIdentity := "holder"
|
||||
|
||||
fake := fake.NewSimpleClientset(
|
||||
&corev1.Node{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "bar",
|
||||
},
|
||||
Spec: corev1.NodeSpec{
|
||||
Unschedulable: true,
|
||||
},
|
||||
},
|
||||
Spec: corev1.NodeSpec{
|
||||
Unschedulable: true,
|
||||
&coordinationv1.Lease{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "bar",
|
||||
Namespace: corev1.NamespaceNodeLease,
|
||||
},
|
||||
Spec: coordinationv1.LeaseSpec{
|
||||
HolderIdentity: &holderIdentity,
|
||||
AcquireTime: &metav1.MicroTime{Time: time.Now().Add(-time.Hour)},
|
||||
RenewTime: &metav1.MicroTime{Time: time.Now()},
|
||||
},
|
||||
},
|
||||
})
|
||||
)
|
||||
c := &describeClient{T: t, Namespace: "foo", Interface: fake}
|
||||
d := NodeDescriber{c}
|
||||
out, err := d.Describe("foo", "bar", describe.DescriberSettings{ShowEvents: true})
|
||||
|
@ -3195,13 +3210,12 @@ func TestDescribeNode(t *testing.T) {
|
|||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
expectedOut := []string{"Unschedulable", "true"}
|
||||
expectedOut := []string{"Unschedulable", "true", "holder"}
|
||||
for _, expected := range expectedOut {
|
||||
if !strings.Contains(out, expected) {
|
||||
t.Errorf("expected to find %q in output: %q", expected, out)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestDescribeStatefulSet(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue