Skip to content

Commit

Permalink
Ignore forbidden error for leases when describing node
Browse files Browse the repository at this point in the history
  • Loading branch information
uthark committed May 23, 2020
1 parent c37837e commit 8aa0df4
Showing 1 changed file with 32 additions and 26 deletions.
58 changes: 32 additions & 26 deletions staging/src/k8s.io/kubectl/pkg/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -3038,15 +3038,6 @@ func (d *NodeDescriber) Describe(namespace, name string, describerSettings Descr
return "", err
}

lease, err := d.CoordinationV1().Leases(corev1.NamespaceNodeLease).Get(context.TODO(), 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
Expand All @@ -3073,10 +3064,15 @@ func (d *NodeDescriber) Describe(namespace, name string, describerSettings Descr
}
}

return describeNode(node, lease, nodeNonTerminatedPodsList, events, canViewPods)
return describeNode(node, nodeNonTerminatedPodsList, events, canViewPods, &LeaseDescriber{d})
}

func describeNode(node *corev1.Node, lease *coordinationv1.Lease, nodeNonTerminatedPodsList *corev1.PodList, events *corev1.EventList, canViewPods bool) (string, error) {
type LeaseDescriber struct {
client clientset.Interface
}

func describeNode(node *corev1.Node, nodeNonTerminatedPodsList *corev1.PodList, events *corev1.EventList,
canViewPods bool, ld *LeaseDescriber) (string, error) {
return tabbedString(func(out io.Writer) error {
w := NewPrefixWriter(out)
w.Write(LEVEL_0, "Name:\t%s\n", node.Name)
Expand All @@ -3091,22 +3087,13 @@ func describeNode(node *corev1.Node, lease *coordinationv1.Lease, nodeNonTermina
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)
if ld != nil {
if lease, err := ld.client.CoordinationV1().Leases(corev1.NamespaceNodeLease).Get(context.TODO(), node.Name, metav1.GetOptions{}); err == nil {
describeNodeLease(lease, w)
} else {
w.Write(LEVEL_0, "Lease:\tFailed to get lease: %s\n", err)
}
}
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")
Expand Down Expand Up @@ -3183,6 +3170,25 @@ func describeNode(node *corev1.Node, lease *coordinationv1.Lease, nodeNonTermina
})
}

func describeNodeLease(lease *coordinationv1.Lease, w PrefixWriter) {
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)
}

type StatefulSetDescriber struct {
client clientset.Interface
}
Expand Down

0 comments on commit 8aa0df4

Please sign in to comment.