Skip to content

Commit c21aabf

Browse files
authored
Merge pull request kubernetes#125991 from xuzhenglun/fix-watch-rc-panic
fix panic when watching ReplicationController with Bookmark enabled
2 parents 1080554 + 07198b9 commit c21aabf

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

pkg/printers/internalversion/printers.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,11 @@ func printReplicationController(obj *api.ReplicationController, options printers
11261126

11271127
row.Cells = append(row.Cells, obj.Name, int64(desiredReplicas), int64(currentReplicas), int64(readyReplicas), translateTimestampSince(obj.CreationTimestamp))
11281128
if options.Wide {
1129-
names, images := layoutContainerCells(obj.Spec.Template.Spec.Containers)
1129+
var containers []api.Container
1130+
if obj.Spec.Template != nil {
1131+
containers = obj.Spec.Template.Spec.Containers
1132+
}
1133+
names, images := layoutContainerCells(containers)
11301134
row.Cells = append(row.Cells, names, images, labels.FormatLabels(obj.Spec.Selector))
11311135
}
11321136
return []metav1.TableRow{row}, nil

pkg/printers/internalversion/printers_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4666,6 +4666,19 @@ func TestPrintReplicationController(t *testing.T) {
46664666
// Columns: Name, Desired, Current, Ready, Age, Containers, Images, Selector
46674667
expected: []metav1.TableRow{{Cells: []interface{}{"rc1", int64(5), int64(3), int64(1), "<unknown>", "test", "test_image", "a=b"}}},
46684668
},
4669+
{
4670+
// make sure Bookmark event will not lead a panic
4671+
rc: api.ReplicationController{
4672+
ObjectMeta: metav1.ObjectMeta{
4673+
Annotations: map[string]string{
4674+
metav1.InitialEventsAnnotationKey: "true",
4675+
},
4676+
},
4677+
},
4678+
options: printers.GenerateOptions{Wide: true},
4679+
// Columns: Name, Desired, Current, Ready, Age, Containers, Images, Selector
4680+
expected: []metav1.TableRow{{Cells: []interface{}{"", int64(0), int64(0), int64(0), "<unknown>", "", "", "<none>"}}},
4681+
},
46694682
}
46704683

46714684
for i, test := range tests {

0 commit comments

Comments
 (0)