Merge pull request #7152 from Luap99/fix#7087
fix pod creation with "new:" syntax
This commit is contained in:
commit
4c75fe3f70
|
@ -124,7 +124,7 @@ func create(cmd *cobra.Command, args []string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := createPodIfNecessary(s); err != nil {
|
if _, err := createPodIfNecessary(s, cliVals.Net); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,7 +283,7 @@ func openCidFile(cidfile string) (*os.File, error) {
|
||||||
// createPodIfNecessary automatically creates a pod when requested. if the pod name
|
// createPodIfNecessary automatically creates a pod when requested. if the pod name
|
||||||
// has the form new:ID, the pod ID is created and the name in the spec generator is replaced
|
// has the form new:ID, the pod ID is created and the name in the spec generator is replaced
|
||||||
// with ID.
|
// with ID.
|
||||||
func createPodIfNecessary(s *specgen.SpecGenerator) (*entities.PodCreateReport, error) {
|
func createPodIfNecessary(s *specgen.SpecGenerator, netOpts *entities.NetOptions) (*entities.PodCreateReport, error) {
|
||||||
if !strings.HasPrefix(s.Pod, "new:") {
|
if !strings.HasPrefix(s.Pod, "new:") {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
@ -292,11 +292,10 @@ func createPodIfNecessary(s *specgen.SpecGenerator) (*entities.PodCreateReport,
|
||||||
return nil, errors.Errorf("new pod name must be at least one character")
|
return nil, errors.Errorf("new pod name must be at least one character")
|
||||||
}
|
}
|
||||||
createOptions := entities.PodCreateOptions{
|
createOptions := entities.PodCreateOptions{
|
||||||
Name: podName,
|
Name: podName,
|
||||||
Infra: true,
|
Infra: true,
|
||||||
Net: &entities.NetOptions{
|
Net: netOpts,
|
||||||
PublishPorts: s.PortMappings,
|
CreateCommand: os.Args,
|
||||||
},
|
|
||||||
}
|
}
|
||||||
s.Pod = podName
|
s.Pod = podName
|
||||||
return registry.ContainerEngine().PodCreate(context.Background(), createOptions)
|
return registry.ContainerEngine().PodCreate(context.Background(), createOptions)
|
||||||
|
|
|
@ -176,7 +176,7 @@ func run(cmd *cobra.Command, args []string) error {
|
||||||
}
|
}
|
||||||
runOpts.Spec = s
|
runOpts.Spec = s
|
||||||
|
|
||||||
if _, err := createPodIfNecessary(s); err != nil {
|
if _, err := createPodIfNecessary(s, cliVals.Net); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -462,6 +462,10 @@ func specConfigureNamespaces(s *specgen.SpecGenerator, g *generate.Generator, rt
|
||||||
func GetNamespaceOptions(ns []string) ([]libpod.PodCreateOption, error) {
|
func GetNamespaceOptions(ns []string) ([]libpod.PodCreateOption, error) {
|
||||||
var options []libpod.PodCreateOption
|
var options []libpod.PodCreateOption
|
||||||
var erroredOptions []libpod.PodCreateOption
|
var erroredOptions []libpod.PodCreateOption
|
||||||
|
if ns == nil {
|
||||||
|
//set the default namespaces
|
||||||
|
ns = strings.Split(specgen.DefaultKernelNamespaces, ",")
|
||||||
|
}
|
||||||
for _, toShare := range ns {
|
for _, toShare := range ns {
|
||||||
switch toShare {
|
switch toShare {
|
||||||
case "cgroup":
|
case "cgroup":
|
||||||
|
|
|
@ -812,7 +812,11 @@ USER mail`
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman run --pod automatically", func() {
|
It("podman run --pod automatically", func() {
|
||||||
session := podmanTest.Podman([]string{"run", "--pod", "new:foobar", ALPINE, "ls"})
|
session := podmanTest.Podman([]string{"run", "-d", "--pod", "new:foobar", ALPINE, "nc", "-l", "-p", "8080"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
session = podmanTest.Podman([]string{"run", "--pod", "foobar", ALPINE, "/bin/sh", "-c", "echo test | nc -w 1 127.0.0.1 8080"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue