Skip to content

Commit 291bce9

Browse files
able8able8
andauthored
Fix the issue of incorrect container resource specs (#30)
Co-authored-by: able8 <able.lv@airwallex.com>
1 parent e48f133 commit 291bce9

3 files changed

Lines changed: 15 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [1.2.1] - 2023-04-27
8+
### Fixed
9+
- Container resource specs showing wrong values [#26](https://github.com/airwallex/k8s-pod-restart-info-collector/issues/26)
10+
11+
### Improved
12+
- Add backticks to format slack message nicely [#25](https://github.com/airwallex/k8s-pod-restart-info-collector/issues/25)
713

814
## [1.2.0] - 2023-01-03
915
### Added

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
TAG="v1.2.0"
2+
TAG="v1.2.1"
33
docker buildx build --platform linux/amd64 -t devopsairwallex/k8s-pod-restart-info-collector:${TAG} .
44
docker push devopsairwallex/k8s-pod-restart-info-collector:${TAG}
55

controller.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ func (c *Controller) handlePod(pod *v1.Pod) error {
213213
}
214214

215215
// check and collect restarted container info
216-
for i, status := range pod.Status.ContainerStatuses {
216+
for _, status := range pod.Status.ContainerStatuses {
217217
if status.RestartCount == 0 {
218218
continue
219219
}
@@ -232,7 +232,13 @@ func (c *Controller) handlePod(pod *v1.Pod) error {
232232

233233
restartReason := printContainerLastStateReason(status)
234234

235-
containerSpec := pod.Spec.Containers[i]
235+
var containerSpec v1.Container
236+
for _, container := range pod.Spec.Containers {
237+
if status.Name == container.Name {
238+
containerSpec = container
239+
break
240+
}
241+
}
236242
containerResource, err := getContainerResource(containerSpec)
237243
if err != nil {
238244
return err

0 commit comments

Comments
 (0)