Skip to content

Commit

Permalink
fix(rollout): 修复获取历史记录中容器信息的问题
Browse files Browse the repository at this point in the history
- 在获取 ReplicaSet 历史记录时,增加了对容器列表非空的判断
- 这样可以避免在没有容器的情况下发生空指针异常
- 提高了代码的健壮性和稳定性
  • Loading branch information
weibaohui committed Jan 21, 2025
1 parent 0b4d00b commit faf5893
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions kom/ctl_rollout.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,17 @@ func (d *rollout) History() ([]RolloutHistory, error) {
var historyEntries []RolloutHistory
for _, rs := range rsList {
revision := rs.Annotations["deployment.kubernetes.io/revision"]
cs := rs.Spec.Template.Spec.Containers
var containers []ContainerInfo
for _, c := range cs {
containers = append(containers, ContainerInfo{
Name: c.Name,
Image: c.Image,
})
if rs.Spec.Template.Spec.Containers != nil {
cs := rs.Spec.Template.Spec.Containers
for _, c := range cs {
containers = append(containers, ContainerInfo{
Name: c.Name,
Image: c.Image,
})
}
}

historyEntries = append(historyEntries, RolloutHistory{
Kind: "ReplicaSet",
Name: rs.GetName(),
Expand Down

0 comments on commit faf5893

Please sign in to comment.