Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pkg/specgen/generate/kube/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,14 @@ func ToSpecGen(ctx context.Context, opts *CtrSpecGenOptions) (*specgen.SpecGener
return nil, errors.New("got empty pod name on container creation when playing kube")
}

// We do validate against the Container spec however it has Image set as optional to allow
// higher level config management to default or override container images. Image is
// required for pods so we must manually validate here.
// https://github.com/kubernetes/kubernetes/pull/48406
if opts.Container.Image == "" {
return nil, fmt.Errorf("container %q is missing the required 'image' field", opts.Container.Name)
}

if opts.NoPodPrefix {
s.Name = opts.Container.Name
} else {
Expand Down
23 changes: 23 additions & 0 deletions test/e2e/play_kube_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,20 @@ spec:
- containerPort: 80
`

var podWithoutAnImage = `
apiVersion: v1
kind: Pod
metadata:
labels:
app: podDoesntHaveAnImage
name: podDoesntHaveAnImage
spec:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
spec:
metadata:
name: my-pod-name # <--- This is missing
labels:
app: my-app
spec:

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

containers:
- name: podDoesntHaveAnImage
ports:
- containerPort: 80
`

var subpathTestNamedVolume = `
apiVersion: v1
kind: Pod
Expand Down Expand Up @@ -2637,6 +2651,15 @@ var _ = Describe("Podman kube play", func() {
Expect(kube).Should(ExitWithError(125, "pod does not have a name"))
})

It("should error if pod doesn't have an image", func() {
err := writeYaml(podWithoutAnImage, kubeYaml)
Expect(err).ToNot(HaveOccurred())

kube := podmanTest.Podman([]string{"kube", "play", kubeYaml})
kube.WaitWithDefaultTimeout()
Expect(kube).Should(ExitWithError(125, `container "podDoesntHaveAnImage" is missing the required 'image' field`))
})

It("support container liveness probe", func() {
err := writeYaml(livenessProbePodYaml, kubeYaml)
Expect(err).ToNot(HaveOccurred())
Expand Down