Skip to content

Commit

Permalink
Fix #1815 - skip pods with empty node names (#1844)
Browse files Browse the repository at this point in the history
## Description

This resolves an issue where Zarf hangs on init when a pending pod (with
no node name) exists.

## Related Issue

Fixes #1815 

## Type of change

- [X] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Other (security config, docs update, etc)

## Checklist before merging

- [X] Test, docs, adr added or updated as needed
- [X] [Contributor Guide
Steps](https://github.com/defenseunicorns/zarf/blob/main/CONTRIBUTING.md#developer-workflow)
followed
  • Loading branch information
Racer159 committed Jun 24, 2023
1 parent a0b581c commit 6fca25a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/pkg/k8s/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,22 @@ func (k *K8s) GetImagesWithNodes(namespace string) (ImageNodeMap, error) {
return nil, fmt.Errorf("unable to get the list of pods in the cluster")
}

findImages:
findImages:
for _, pod := range pods.Items {
nodeName := pod.Spec.NodeName

// If this pod doesn't have a node (i.e. is Pending), skip it
if nodeName == "" {
continue
}

nodeDetails, err := k.GetNode(nodeName)
if err != nil {
return nil, fmt.Errorf("unable to get the node %s", pod.Spec.NodeName)
}

for _, taint := range nodeDetails.Spec.Taints {
if (taint.Effect == corev1.TaintEffectNoSchedule || taint.Effect == corev1.TaintEffectNoExecute) {
if taint.Effect == corev1.TaintEffectNoSchedule || taint.Effect == corev1.TaintEffectNoExecute {
continue findImages
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/test/e2e/20_zarf_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ func TestZarfInit(t *testing.T) {
require.Error(t, err, stdErr)
require.Contains(t, stdErr, expectedErrorMessage)

if !e2e.ApplianceMode {
// throw a pending pod into the cluster to ensure we can properly ignore them when selecting images
_, _, err = e2e.Kubectl("apply", "-f", "https://raw.githubusercontent.com/kubernetes/website/main/content/en/examples/pods/pod-with-node-affinity.yaml")
require.NoError(t, err)
}

// run `zarf init`
_, initStdErr, err := e2e.Zarf("init", "--components="+initComponents, "--nodeport", "31337", "-l", "trace", "--confirm")
require.NoError(t, err)
Expand Down

0 comments on commit 6fca25a

Please sign in to comment.