Skip to content

Commit cc24ba5

Browse files
macskok8s-publishing-bot
authored andcommitted
kubectl: Add Workload to kubectl describe pod
Kubernetes-commit: 02acdd605744afc9b93aa088a5814c1d40b036fb
1 parent 3e0ce44 commit cc24ba5

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

pkg/describe/describe.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,9 @@ func describePod(pod *corev1.Pod, events *corev1.EventList) (string, error) {
880880
printLabelsMultiline(w, "Node-Selectors", pod.Spec.NodeSelector)
881881
printPodTolerationsMultiline(w, "Tolerations", pod.Spec.Tolerations)
882882
describeTopologySpreadConstraints(pod.Spec.TopologySpreadConstraints, w, "")
883+
if pod.Spec.WorkloadRef != nil {
884+
describeWorkloadReference(pod.Spec.WorkloadRef, w, "")
885+
}
883886
if events != nil {
884887
DescribeEvents(events, w)
885888
}
@@ -1011,6 +1014,15 @@ func describeVolumes(volumes []corev1.Volume, w PrefixWriter, space string) {
10111014
}
10121015
}
10131016

1017+
func describeWorkloadReference(workloadRef *corev1.WorkloadReference, w PrefixWriter, space string) {
1018+
w.Write(LEVEL_0, "%sWorkloadRef:\n", space)
1019+
w.Write(LEVEL_1, "Name:\t%s\n", workloadRef.Name)
1020+
w.Write(LEVEL_1, "PodGroup:\t%s\n", workloadRef.PodGroup)
1021+
if workloadRef.PodGroupReplicaKey != "" {
1022+
w.Write(LEVEL_1, "PodGroupReplicaKey:\t%s\n", workloadRef.PodGroupReplicaKey)
1023+
}
1024+
}
1025+
10141026
func printHostPathVolumeSource(hostPath *corev1.HostPathVolumeSource, w PrefixWriter) {
10151027
hostPathType := "<none>"
10161028
if hostPath.Type != nil {
@@ -2241,6 +2253,9 @@ func DescribePodTemplate(template *corev1.PodTemplateSpec, w PrefixWriter) {
22412253
}
22422254
printLabelsMultiline(w, " Node-Selectors", template.Spec.NodeSelector)
22432255
printPodTolerationsMultiline(w, " Tolerations", template.Spec.Tolerations)
2256+
if template.Spec.WorkloadRef != nil {
2257+
describeWorkloadReference(template.Spec.WorkloadRef, w, " ")
2258+
}
22442259
}
22452260

22462261
// ReplicaSetDescriber generates information about a ReplicaSet and the pods it has created.

pkg/describe/describe_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,65 @@ func TestDescribePodRuntimeClass(t *testing.T) {
612612
}
613613
}
614614

615+
func TestDescribePodWorkloadReference(t *testing.T) {
616+
testCases := []struct {
617+
name string
618+
pod *corev1.Pod
619+
expected string
620+
}{
621+
{
622+
name: "test1",
623+
pod: &corev1.Pod{
624+
ObjectMeta: metav1.ObjectMeta{
625+
Name: "bar",
626+
},
627+
Spec: corev1.PodSpec{
628+
WorkloadRef: &corev1.WorkloadReference{
629+
Name: "workload",
630+
PodGroup: "pg",
631+
},
632+
},
633+
},
634+
expected: `WorkloadRef:
635+
Name: workload
636+
PodGroup: pg`,
637+
},
638+
{
639+
name: "test2",
640+
pod: &corev1.Pod{
641+
ObjectMeta: metav1.ObjectMeta{
642+
Name: "bar",
643+
},
644+
Spec: corev1.PodSpec{
645+
WorkloadRef: &corev1.WorkloadReference{
646+
Name: "workload",
647+
PodGroup: "pg",
648+
PodGroupReplicaKey: "pg1",
649+
},
650+
},
651+
},
652+
expected: `WorkloadRef:
653+
Name: workload
654+
PodGroup: pg
655+
PodGroupReplicaKey: pg1`,
656+
},
657+
}
658+
for _, tc := range testCases {
659+
t.Run(tc.name, func(t *testing.T) {
660+
fake := fake.NewClientset(tc.pod)
661+
c := &describeClient{T: t, Interface: fake}
662+
d := PodDescriber{c}
663+
out, err := d.Describe("", "bar", DescriberSettings{ShowEvents: true})
664+
if err != nil {
665+
t.Errorf("Unexpected error: %v", err)
666+
}
667+
if !strings.Contains(out, tc.expected) {
668+
t.Errorf("Expected to find %q in output: %q", tc.expected, out)
669+
}
670+
})
671+
}
672+
}
673+
615674
func TestDescribePriorityClass(t *testing.T) {
616675
preemptLowerPriority := corev1.PreemptLowerPriority
617676
preemptNever := corev1.PreemptNever

0 commit comments

Comments
 (0)