Skip to content

Commit

Permalink
fix #2958
Browse files Browse the repository at this point in the history
  • Loading branch information
derailed committed Nov 16, 2024
1 parent da9f0a8 commit dade8d9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 21 deletions.
22 changes: 14 additions & 8 deletions internal/dao/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,25 +82,31 @@ func makeContainerRes(kind string, idx int, co v1.Container, po *v1.Pod, cmx *mv
return render.ContainerRes{
Idx: kind + strconv.Itoa(idx+1),
Container: &co,
Status: getContainerStatus(kind, idx, po.Status),
Status: getContainerStatus(kind, co.Name, po.Status),
MX: cmx,
Age: po.GetCreationTimestamp(),
}
}

func getContainerStatus(kind string, idx int, status v1.PodStatus) *v1.ContainerStatus {
func getContainerStatus(kind string, name string, status v1.PodStatus) *v1.ContainerStatus {
switch kind {
case mainIDX:
if idx < len(status.ContainerStatuses) {
return &status.ContainerStatuses[idx]
for _, s := range status.ContainerStatuses {
if s.Name == name {
return &s
}
}
case initIDX:
if idx < len(status.InitContainerStatuses) {
return &status.InitContainerStatuses[idx]
for _, s := range status.InitContainerStatuses {
if s.Name == name {
return &s
}
}
case ephIDX:
if idx < len(status.EphemeralContainerStatuses) {
return &status.EphemeralContainerStatuses[idx]
for _, s := range status.EphemeralContainerStatuses {
if s.Name == name {
return &s
}
}
}

Expand Down
34 changes: 21 additions & 13 deletions internal/dao/dp.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,17 @@ func hasPC(spec *v1.PodSpec, name string) bool {

func hasConfigMap(spec *v1.PodSpec, name string) bool {
for _, c := range spec.InitContainers {
if containerHasConfigMap(c, name) {
if containerHasConfigMap(c.EnvFrom, c.Env, name) {
return true
}
}
for _, c := range spec.Containers {
if containerHasConfigMap(c, name) {
if containerHasConfigMap(c.EnvFrom, c.Env, name) {
return true
}
}
for _, c := range spec.EphemeralContainers {
if containerHasConfigMap(c.EnvFrom, c.Env, name) {
return true
}
}
Expand All @@ -321,15 +326,19 @@ func hasConfigMap(spec *v1.PodSpec, name string) bool {
return false
}

// BOZO !! Need to deal with ephemeral containers.
func hasSecret(f Factory, spec *v1.PodSpec, ns, name string, wait bool) (bool, error) {
for _, c := range spec.InitContainers {
if containerHasSecret(c, name) {
if containerHasSecret(c.EnvFrom, c.Env, name) {
return true, nil
}
}
for _, c := range spec.Containers {
if containerHasSecret(c, name) {
if containerHasSecret(c.EnvFrom, c.Env, name) {
return true, nil
}
}
for _, c := range spec.EphemeralContainers {
if containerHasSecret(c.EnvFrom, c.Env, name) {
return true, nil
}
}
Expand All @@ -340,8 +349,7 @@ func hasSecret(f Factory, spec *v1.PodSpec, ns, name string, wait bool) (bool, e
}
}

saName := spec.ServiceAccountName
if saName != "" {
if saName := spec.ServiceAccountName; saName != "" {
o, err := f.Get("v1/serviceaccounts", client.FQN(ns, saName), wait, labels.Everything())
if err != nil {
return false, err
Expand Down Expand Up @@ -370,13 +378,13 @@ func hasSecret(f Factory, spec *v1.PodSpec, ns, name string, wait bool) (bool, e
return false, nil
}

func containerHasSecret(c v1.Container, name string) bool {
for _, e := range c.EnvFrom {
func containerHasSecret(envFrom []v1.EnvFromSource, env []v1.EnvVar, name string) bool {
for _, e := range envFrom {
if e.SecretRef != nil && e.SecretRef.Name == name {
return true
}
}
for _, e := range c.Env {
for _, e := range env {
if e.ValueFrom == nil || e.ValueFrom.SecretKeyRef == nil {
continue
}
Expand All @@ -388,13 +396,13 @@ func containerHasSecret(c v1.Container, name string) bool {
return false
}

func containerHasConfigMap(c v1.Container, name string) bool {
for _, e := range c.EnvFrom {
func containerHasConfigMap(envFrom []v1.EnvFromSource, env []v1.EnvVar, name string) bool {
for _, e := range envFrom {
if e.ConfigMapRef != nil && e.ConfigMapRef.Name == name {
return true
}
}
for _, e := range c.Env {
for _, e := range env {
if e.ValueFrom == nil || e.ValueFrom.ConfigMapKeyRef == nil {
continue
}
Expand Down

0 comments on commit dade8d9

Please sign in to comment.