kubectl: Add Workload to kubectl describe pod

Kubernetes-commit: 02acdd605744afc9b93aa088a5814c1d40b036fb
This commit is contained in:
Maciej Skoczeń 2025-10-10 09:43:12 +00:00 committed by Kubernetes Publisher
parent 3e0ce445d5
commit cc24ba554f
2 changed files with 74 additions and 0 deletions

View file

@ -880,6 +880,9 @@ func describePod(pod *corev1.Pod, events *corev1.EventList) (string, error) {
printLabelsMultiline(w, "Node-Selectors", pod.Spec.NodeSelector)
printPodTolerationsMultiline(w, "Tolerations", pod.Spec.Tolerations)
describeTopologySpreadConstraints(pod.Spec.TopologySpreadConstraints, w, "")
if pod.Spec.WorkloadRef != nil {
describeWorkloadReference(pod.Spec.WorkloadRef, w, "")
}
if events != nil {
DescribeEvents(events, w)
}
@ -1011,6 +1014,15 @@ func describeVolumes(volumes []corev1.Volume, w PrefixWriter, space string) {
}
}
func describeWorkloadReference(workloadRef *corev1.WorkloadReference, w PrefixWriter, space string) {
w.Write(LEVEL_0, "%sWorkloadRef:\n", space)
w.Write(LEVEL_1, "Name:\t%s\n", workloadRef.Name)
w.Write(LEVEL_1, "PodGroup:\t%s\n", workloadRef.PodGroup)
if workloadRef.PodGroupReplicaKey != "" {
w.Write(LEVEL_1, "PodGroupReplicaKey:\t%s\n", workloadRef.PodGroupReplicaKey)
}
}
func printHostPathVolumeSource(hostPath *corev1.HostPathVolumeSource, w PrefixWriter) {
hostPathType := "<none>"
if hostPath.Type != nil {
@ -2241,6 +2253,9 @@ func DescribePodTemplate(template *corev1.PodTemplateSpec, w PrefixWriter) {
}
printLabelsMultiline(w, " Node-Selectors", template.Spec.NodeSelector)
printPodTolerationsMultiline(w, " Tolerations", template.Spec.Tolerations)
if template.Spec.WorkloadRef != nil {
describeWorkloadReference(template.Spec.WorkloadRef, w, " ")
}
}
// ReplicaSetDescriber generates information about a ReplicaSet and the pods it has created.

View file

@ -612,6 +612,65 @@ func TestDescribePodRuntimeClass(t *testing.T) {
}
}
func TestDescribePodWorkloadReference(t *testing.T) {
testCases := []struct {
name string
pod *corev1.Pod
expected string
}{
{
name: "test1",
pod: &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "bar",
},
Spec: corev1.PodSpec{
WorkloadRef: &corev1.WorkloadReference{
Name: "workload",
PodGroup: "pg",
},
},
},
expected: `WorkloadRef:
Name: workload
PodGroup: pg`,
},
{
name: "test2",
pod: &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "bar",
},
Spec: corev1.PodSpec{
WorkloadRef: &corev1.WorkloadReference{
Name: "workload",
PodGroup: "pg",
PodGroupReplicaKey: "pg1",
},
},
},
expected: `WorkloadRef:
Name: workload
PodGroup: pg
PodGroupReplicaKey: pg1`,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
fake := fake.NewClientset(tc.pod)
c := &describeClient{T: t, Interface: fake}
d := PodDescriber{c}
out, err := d.Describe("", "bar", DescriberSettings{ShowEvents: true})
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
if !strings.Contains(out, tc.expected) {
t.Errorf("Expected to find %q in output: %q", tc.expected, out)
}
})
}
}
func TestDescribePriorityClass(t *testing.T) {
preemptLowerPriority := corev1.PreemptLowerPriority
preemptNever := corev1.PreemptNever