mirror of https://github.com/containers/podman.git
play kube: Container->Ctr
for berevity Signed-off-by: Peter Hunt <pehunt@redhat.com>
This commit is contained in:
parent
6ad4fb0c49
commit
e0fda971da
|
|
@ -23,7 +23,7 @@ metadata:
|
||||||
spec:
|
spec:
|
||||||
hostname: {{ .Hostname }}
|
hostname: {{ .Hostname }}
|
||||||
containers:
|
containers:
|
||||||
{{ with .Containers }}
|
{{ with .Ctrs }}
|
||||||
{{ range . }}
|
{{ range . }}
|
||||||
- command:
|
- command:
|
||||||
{{ range .Cmd }}
|
{{ range .Cmd }}
|
||||||
|
|
@ -95,21 +95,21 @@ func generateKubeYaml(pod *Pod, fileName string) error {
|
||||||
|
|
||||||
// Pod describes the options a kube yaml can be configured at pod level
|
// Pod describes the options a kube yaml can be configured at pod level
|
||||||
type Pod struct {
|
type Pod struct {
|
||||||
Name string
|
Name string
|
||||||
Hostname string
|
Hostname string
|
||||||
Containers []*Container
|
Ctrs []*Ctr
|
||||||
}
|
}
|
||||||
|
|
||||||
// getPod takes a list of podOptions and returns a pod with sane defaults
|
// getPod takes a list of podOptions and returns a pod with sane defaults
|
||||||
// and the configured options
|
// and the configured options
|
||||||
// if no containers are added, it will add the default container
|
// if no containers are added, it will add the default container
|
||||||
func getPod(options ...podOption) *Pod {
|
func getPod(options ...podOption) *Pod {
|
||||||
p := Pod{defaultPodName, "", make([]*Container, 0)}
|
p := Pod{defaultPodName, "", make([]*Ctr, 0)}
|
||||||
for _, option := range options {
|
for _, option := range options {
|
||||||
option(&p)
|
option(&p)
|
||||||
}
|
}
|
||||||
if len(p.Containers) == 0 {
|
if len(p.Ctrs) == 0 {
|
||||||
p.Containers = []*Container{getContainer()}
|
p.Ctrs = []*Ctr{getCtr()}
|
||||||
}
|
}
|
||||||
return &p
|
return &p
|
||||||
}
|
}
|
||||||
|
|
@ -122,14 +122,14 @@ func withHostname(h string) podOption {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func withContainer(c *Container) podOption {
|
func withCtr(c *Ctr) podOption {
|
||||||
return func(pod *Pod) {
|
return func(pod *Pod) {
|
||||||
pod.Containers = append(pod.Containers, c)
|
pod.Ctrs = append(pod.Ctrs, c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Container describes the options a kube yaml can be configured at container level
|
// Ctr describes the options a kube yaml can be configured at container level
|
||||||
type Container struct {
|
type Ctr struct {
|
||||||
Name string
|
Name string
|
||||||
Image string
|
Image string
|
||||||
Cmd []string
|
Cmd []string
|
||||||
|
|
@ -139,45 +139,45 @@ type Container struct {
|
||||||
CapDrop []string
|
CapDrop []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// getContainer takes a list of containerOptions and returns a container with sane defaults
|
// getCtr takes a list of ctrOptions and returns a Ctr with sane defaults
|
||||||
// and the configured options
|
// and the configured options
|
||||||
func getContainer(options ...containerOption) *Container {
|
func getCtr(options ...ctrOption) *Ctr {
|
||||||
c := Container{defaultCtrName, defaultCtrImage, defaultCtrCmd, true, false, nil, nil}
|
c := Ctr{defaultCtrName, defaultCtrImage, defaultCtrCmd, true, false, nil, nil}
|
||||||
for _, option := range options {
|
for _, option := range options {
|
||||||
option(&c)
|
option(&c)
|
||||||
}
|
}
|
||||||
return &c
|
return &c
|
||||||
}
|
}
|
||||||
|
|
||||||
type containerOption func(*Container)
|
type ctrOption func(*Ctr)
|
||||||
|
|
||||||
func withCmd(cmd []string) containerOption {
|
func withCmd(cmd []string) ctrOption {
|
||||||
return func(c *Container) {
|
return func(c *Ctr) {
|
||||||
c.Cmd = cmd
|
c.Cmd = cmd
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func withImage(img string) containerOption {
|
func withImage(img string) ctrOption {
|
||||||
return func(c *Container) {
|
return func(c *Ctr) {
|
||||||
c.Image = img
|
c.Image = img
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func withSecurityContext(sc bool) containerOption {
|
func withSecurityContext(sc bool) ctrOption {
|
||||||
return func(c *Container) {
|
return func(c *Ctr) {
|
||||||
c.SecurityContext = sc
|
c.SecurityContext = sc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func withCapAdd(caps []string) containerOption {
|
func withCapAdd(caps []string) ctrOption {
|
||||||
return func(c *Container) {
|
return func(c *Ctr) {
|
||||||
c.CapAdd = caps
|
c.CapAdd = caps
|
||||||
c.Caps = true
|
c.Caps = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func withCapDrop(caps []string) containerOption {
|
func withCapDrop(caps []string) ctrOption {
|
||||||
return func(c *Container) {
|
return func(c *Ctr) {
|
||||||
c.CapDrop = caps
|
c.CapDrop = caps
|
||||||
c.Caps = true
|
c.Caps = true
|
||||||
}
|
}
|
||||||
|
|
@ -224,7 +224,7 @@ var _ = Describe("Podman generate kube", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman play kube test correct output", func() {
|
It("podman play kube test correct output", func() {
|
||||||
p := getPod(withContainer(getContainer(withCmd([]string{"echo", "hello"}))))
|
p := getPod(withCtr(getCtr(withCmd([]string{"echo", "hello"}))))
|
||||||
|
|
||||||
err := generateKubeYaml(p, kubeYaml)
|
err := generateKubeYaml(p, kubeYaml)
|
||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
|
|
@ -275,9 +275,9 @@ var _ = Describe("Podman generate kube", func() {
|
||||||
|
|
||||||
It("podman play kube cap add", func() {
|
It("podman play kube cap add", func() {
|
||||||
capAdd := "CAP_SYS_ADMIN"
|
capAdd := "CAP_SYS_ADMIN"
|
||||||
ctr := getContainer(withCapAdd([]string{capAdd}), withCmd([]string{"cat", "/proc/self/status"}))
|
ctr := getCtr(withCapAdd([]string{capAdd}), withCmd([]string{"cat", "/proc/self/status"}))
|
||||||
|
|
||||||
err := generateKubeYaml(getPod(withContainer(ctr)), kubeYaml)
|
err := generateKubeYaml(getPod(withCtr(ctr)), kubeYaml)
|
||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
|
|
||||||
kube := podmanTest.Podman([]string{"play", "kube", kubeYaml})
|
kube := podmanTest.Podman([]string{"play", "kube", kubeYaml})
|
||||||
|
|
@ -292,9 +292,9 @@ var _ = Describe("Podman generate kube", func() {
|
||||||
|
|
||||||
It("podman play kube cap drop", func() {
|
It("podman play kube cap drop", func() {
|
||||||
capDrop := "CAP_CHOWN"
|
capDrop := "CAP_CHOWN"
|
||||||
ctr := getContainer(withCapDrop([]string{capDrop}))
|
ctr := getCtr(withCapDrop([]string{capDrop}))
|
||||||
|
|
||||||
err := generateKubeYaml(getPod(withContainer(ctr)), kubeYaml)
|
err := generateKubeYaml(getPod(withCtr(ctr)), kubeYaml)
|
||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
|
|
||||||
kube := podmanTest.Podman([]string{"play", "kube", kubeYaml})
|
kube := podmanTest.Podman([]string{"play", "kube", kubeYaml})
|
||||||
|
|
@ -309,7 +309,7 @@ var _ = Describe("Podman generate kube", func() {
|
||||||
|
|
||||||
It("podman play kube no security context", func() {
|
It("podman play kube no security context", func() {
|
||||||
// expect play kube to not fail if no security context is specified
|
// expect play kube to not fail if no security context is specified
|
||||||
err := generateKubeYaml(getPod(withContainer(getContainer(withSecurityContext(false)))), kubeYaml)
|
err := generateKubeYaml(getPod(withCtr(getCtr(withSecurityContext(false)))), kubeYaml)
|
||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
|
|
||||||
kube := podmanTest.Podman([]string{"play", "kube", kubeYaml})
|
kube := podmanTest.Podman([]string{"play", "kube", kubeYaml})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue