Skip to content

Commit

Permalink
Fix for other cases
Browse files Browse the repository at this point in the history
  • Loading branch information
marctc committed Nov 26, 2024
1 parent ae37a56 commit bcbd853
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions pkg/kubecache/meta/informers_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,30 +231,39 @@ func (inf *Informers) initPodInformer(ctx context.Context, informerFactory infor
len(pod.Status.ContainerStatuses)+
len(pod.Status.InitContainerStatuses)+
len(pod.Status.EphemeralContainerStatuses))
for i := range pod.Status.ContainerStatuses {
for _, cs := range pod.Status.ContainerStatuses {

Check failure on line 234 in pkg/kubecache/meta/informers_init.go

View workflow job for this annotation

GitHub Actions / test (1.23)

rangeValCopy: each iteration copies 144 bytes (consider pointers or indexing) (gocritic)
envs := envsFromContainerSpec(cs.Name, pod.Spec.Containers)
containers = append(containers,
&informer.ContainerInfo{
Name: pod.Status.ContainerStatuses[i].Name,
Id: rmContainerIDSchema(pod.Status.ContainerStatuses[i].ContainerID),
Env: envToMap(inf.config.kubeClient, pod.ObjectMeta, pod.Spec.Containers[i].Env),
Name: cs.Name,
Id: rmContainerIDSchema(cs.ContainerID),
Env: envToMap(inf.config.kubeClient, pod.ObjectMeta, envs),
},
)
}
for i := range pod.Status.InitContainerStatuses {
for _, ics := range pod.Status.InitContainerStatuses {

Check failure on line 244 in pkg/kubecache/meta/informers_init.go

View workflow job for this annotation

GitHub Actions / test (1.23)

rangeValCopy: each iteration copies 144 bytes (consider pointers or indexing) (gocritic)
envs := envsFromContainerSpec(ics.Name, pod.Spec.InitContainers)
containers = append(containers,
&informer.ContainerInfo{
Name: pod.Spec.InitContainers[i].Name,
Id: rmContainerIDSchema(pod.Status.InitContainerStatuses[i].ContainerID),
Env: envToMap(inf.config.kubeClient, pod.ObjectMeta, pod.Spec.InitContainers[i].Env),
Name: ics.Name,
Id: rmContainerIDSchema(ics.ContainerID),
Env: envToMap(inf.config.kubeClient, pod.ObjectMeta, envs),
},
)
}
for i := range pod.Status.EphemeralContainerStatuses {
for _, ecs := range pod.Status.EphemeralContainerStatuses {

Check failure on line 254 in pkg/kubecache/meta/informers_init.go

View workflow job for this annotation

GitHub Actions / test (1.23)

rangeValCopy: each iteration copies 144 bytes (consider pointers or indexing) (gocritic)
envs := []v1.EnvVar{}
for _, c := range pod.Spec.EphemeralContainers {

Check failure on line 256 in pkg/kubecache/meta/informers_init.go

View workflow job for this annotation

GitHub Actions / test (1.23)

rangeValCopy: each iteration copies 400 bytes (consider pointers or indexing) (gocritic)
if c.Name == ecs.Name {
envs = c.Env
break
}
}
containers = append(containers,
&informer.ContainerInfo{
Name: pod.Spec.EphemeralContainers[i].Name,
Id: rmContainerIDSchema(pod.Status.EphemeralContainerStatuses[i].ContainerID),
Env: envToMap(inf.config.kubeClient, pod.ObjectMeta, pod.Spec.EphemeralContainers[i].Env),
Name: ecs.Name,
Id: rmContainerIDSchema(ecs.ContainerID),
Env: envToMap(inf.config.kubeClient, pod.ObjectMeta, envs),
},
)
}
Expand Down Expand Up @@ -321,6 +330,17 @@ func envToMap(kc kubernetes.Interface, objMeta metav1.ObjectMeta, containerEnv [
return envMap
}

func envsFromContainerSpec(containerName string, containers []v1.Container) []v1.EnvVar {
envs := []v1.EnvVar{}
for _, c := range containers {

Check failure on line 335 in pkg/kubecache/meta/informers_init.go

View workflow job for this annotation

GitHub Actions / test (1.23)

rangeValCopy: each iteration copies 384 bytes (consider pointers or indexing) (gocritic)
if c.Name == containerName {
envs = c.Env
break
}
}
return envs
}

// rmContainerIDSchema extracts the hex ID of a container ID that is provided in the form:
// containerd://40c03570b6f4c30bc8d69923d37ee698f5cfcced92c7b7df1c47f6f7887378a9
func rmContainerIDSchema(containerID string) string {
Expand Down

0 comments on commit bcbd853

Please sign in to comment.