summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile18
-rw-r--r--docs/source/markdown/podman-login.1.md4
-rw-r--r--libpod/kube.go18
-rw-r--r--libpod/runtime_pod_infra_linux.go4
-rw-r--r--pkg/domain/infra/abi/play.go13
-rw-r--r--pkg/domain/infra/tunnel/images.go17
-rw-r--r--test/e2e/build_test.go2
-rw-r--r--test/e2e/generate_kube_test.go34
-rw-r--r--test/e2e/play_kube_test.go68
-rw-r--r--test/e2e/pod_create_test.go24
10 files changed, 174 insertions, 28 deletions
diff --git a/Makefile b/Makefile
index 07ff21445..d4bc0cf56 100644
--- a/Makefile
+++ b/Makefile
@@ -38,7 +38,7 @@ PRE_COMMIT = $(shell command -v bin/venv/bin/pre-commit ~/.local/bin/pre-commit
SOURCES = $(shell find . -path './.*' -prune -o -name "*.go")
-GO_BUILD ?= $(GO) build -mod=vendor
+BUILDFLAGS := -mod=vendor $(BUILDFLAGS)
BUILDTAGS_CROSS ?= containers_image_openpgp exclude_graphdriver_btrfs exclude_graphdriver_devicemapper exclude_graphdriver_overlay
ifneq (,$(findstring varlink,$(BUILDTAGS)))
@@ -170,11 +170,11 @@ gofmt: ## Verify the source code gofmt
.PHONY: test/checkseccomp/checkseccomp
test/checkseccomp/checkseccomp: .gopathok $(wildcard test/checkseccomp/*.go)
- $(GO_BUILD) -ldflags '$(LDFLAGS_PODMAN)' -tags "$(BUILDTAGS)" -o $@ ./test/checkseccomp
+ $(GO) build $(BUILDFLAGS) -ldflags '$(LDFLAGS_PODMAN)' -tags "$(BUILDTAGS)" -o $@ ./test/checkseccomp
.PHONY: test/goecho/goechoe
test/goecho/goecho: .gopathok $(wildcard test/goecho/*.go)
- $(GO_BUILD) -ldflags '$(LDFLAGS_PODMAN)' -o $@ ./test/goecho
+ $(GO) build $(BUILDFLAGS) -ldflags '$(LDFLAGS_PODMAN)' -o $@ ./test/goecho
.PHONY: bin/podman
@@ -184,18 +184,18 @@ ifeq (,$(findstring systemd,$(BUILDTAGS)))
@echo "Podman is being compiled without the systemd build tag. Install libsystemd on \
Ubuntu or systemd-devel on rpm based distro for journald support."
endif
- $(GO_BUILD) $(BUILDFLAGS) -gcflags '$(GCFLAGS)' -asmflags '$(ASMFLAGS)' -ldflags '$(LDFLAGS_PODMAN)' -tags "$(BUILDTAGS)" -o $@ ./cmd/podman
+ $(GO) build $(BUILDFLAGS) -gcflags '$(GCFLAGS)' -asmflags '$(ASMFLAGS)' -ldflags '$(LDFLAGS_PODMAN)' -tags "$(BUILDTAGS)" -o $@ ./cmd/podman
.PHONY: podman
podman: bin/podman
.PHONY: bin/podman-remote
bin/podman-remote: .gopathok $(SOURCES) go.mod go.sum $(PODMAN_VARLINK_DEPENDENCIES) ## Build with podman on remote environment
- $(GO_BUILD) $(BUILDFLAGS) -gcflags '$(GCFLAGS)' -asmflags '$(ASMFLAGS)' -ldflags '$(LDFLAGS_PODMAN)' -tags "${REMOTETAGS}" -o $@ ./cmd/podman
+ $(GO) build $(BUILDFLAGS) -gcflags '$(GCFLAGS)' -asmflags '$(ASMFLAGS)' -ldflags '$(LDFLAGS_PODMAN)' -tags "${REMOTETAGS}" -o $@ ./cmd/podman
.PHONY: bin/podman-remote-static
podman-remote-static: bin/podman-remote-static
- CGO_ENABLED=0 $(GO_BUILD) $(BUILDFLAGS) -gcflags '$(GCFLAGS)' -asmflags '$(ASMFLAGS)' -ldflags '$(LDFLAGS_PODMAN_STATIC)' -tags "${REMOTETAGS}" -o bin/podman-remote-static ./cmd/podman
+ CGO_ENABLED=0 $(GO) build $(BUILDFLAGS) -gcflags '$(GCFLAGS)' -asmflags '$(ASMFLAGS)' -ldflags '$(LDFLAGS_PODMAN_STATIC)' -tags "${REMOTETAGS}" -o bin/podman-remote-static ./cmd/podman
.PHONY: podman-remote
podman-remote: bin/podman-remote
@@ -209,7 +209,7 @@ podman.msi: podman-remote podman-remote-windows install-podman-remote-windows-do
podman-remote-%: .gopathok $(PODMAN_VARLINK_DEPENDENCIES) ## Build podman for a specific GOOS
$(eval BINSFX := $(shell test "$*" != "windows" || echo ".exe"))
- CGO_ENABLED=0 GOOS=$* $(GO_BUILD) -gcflags '$(GCFLAGS)' -asmflags '$(ASMFLAGS)' -ldflags '$(LDFLAGS_PODMAN)' -tags "${REMOTETAGS}" -o bin/$@$(BINSFX) ./cmd/podman
+ CGO_ENABLED=0 GOOS=$* $(GO) build $(BUILDFLAGS) -gcflags '$(GCFLAGS)' -asmflags '$(ASMFLAGS)' -ldflags '$(LDFLAGS_PODMAN)' -tags "${REMOTETAGS}" -o bin/$@$(BINSFX) ./cmd/podman
local-cross: $(CROSS_BUILD_TARGETS) ## Cross local compilation
@@ -217,7 +217,7 @@ bin/podman.cross.%: .gopathok
TARGET="$*"; \
GOOS="$${TARGET%%.*}" \
GOARCH="$${TARGET##*.}" \
- $(GO_BUILD) -gcflags '$(GCFLAGS)' -asmflags '$(ASMFLAGS)' -ldflags '$(LDFLAGS_PODMAN)' -tags '$(BUILDTAGS_CROSS)' -o "$@" ./cmd/podman
+ $(GO) build $(BUILDFLAGS) -gcflags '$(GCFLAGS)' -asmflags '$(ASMFLAGS)' -ldflags '$(LDFLAGS_PODMAN)' -tags '$(BUILDTAGS_CROSS)' -o "$@" ./cmd/podman
# Update nix/nixpkgs.json its latest stable commit
.PHONY: nixpkgs
@@ -622,7 +622,7 @@ endef
.PHONY: .install.ginkgo
.install.ginkgo: .gopathok
if [ ! -x "$(GOBIN)/ginkgo" ]; then \
- $(GO_BUILD) -o ${GOPATH}/bin/ginkgo ./vendor/github.com/onsi/ginkgo/ginkgo ; \
+ $(GO) install $(BUILDFLAGS) ./vendor/github.com/onsi/ginkgo/ginkgo ; \
fi
.PHONY: .install.gitvalidation
diff --git a/docs/source/markdown/podman-login.1.md b/docs/source/markdown/podman-login.1.md
index efc7f05e2..9b4ff74ed 100644
--- a/docs/source/markdown/podman-login.1.md
+++ b/docs/source/markdown/podman-login.1.md
@@ -18,7 +18,7 @@ Podman will first search for the username and password in the **${XDG\_RUNTIME\_
Podman will then use any existing credentials found in **$HOME/.docker/config.json**.
If those credentials are not present, Podman will create **${XDG\_RUNTIME\_DIR}/containers/auth.json** (if the file does not exist) and
will then store the username and password from STDIN as a base64 encoded string in it.
-For more details about format and configurations of the auth,json file, please refer to containers-auth.json(5)
+For more details about format and configurations of the auth.json file, please refer to containers-auth.json(5)
**podman [GLOBAL OPTIONS]**
@@ -108,7 +108,7 @@ Login Succeeded!
```
## SEE ALSO
-podman(1), podman-logout(1), containers-auth.json(5)
+podman(1), podman-logout(1), containers-auth.json(5), containers-registries.conf(5)
## HISTORY
August 2017, Originally compiled by Urvashi Mohnani <umohnani@redhat.com>
diff --git a/libpod/kube.go b/libpod/kube.go
index 9d5cbe68b..f83e99d82 100644
--- a/libpod/kube.go
+++ b/libpod/kube.go
@@ -77,6 +77,24 @@ func (p *Pod) GenerateForKube() (*v1.Pod, []v1.ServicePort, error) {
}
pod.Spec.HostAliases = extraHost
+ // vendor/k8s.io/api/core/v1/types.go: v1.Container cannot save restartPolicy
+ // so set it at here
+ for _, ctr := range allContainers {
+ if !ctr.IsInfra() {
+ switch ctr.Config().RestartPolicy {
+ case RestartPolicyAlways:
+ pod.Spec.RestartPolicy = v1.RestartPolicyAlways
+ case RestartPolicyOnFailure:
+ pod.Spec.RestartPolicy = v1.RestartPolicyOnFailure
+ case RestartPolicyNo:
+ pod.Spec.RestartPolicy = v1.RestartPolicyNever
+ default: // some pod create from cmdline, such as "", so set it to Never
+ pod.Spec.RestartPolicy = v1.RestartPolicyNever
+ }
+ break
+ }
+ }
+
if p.SharesPID() {
// unfortunately, go doesn't have a nice way to specify a pointer to a bool
b := true
diff --git a/libpod/runtime_pod_infra_linux.go b/libpod/runtime_pod_infra_linux.go
index 164068638..570cdd38f 100644
--- a/libpod/runtime_pod_infra_linux.go
+++ b/libpod/runtime_pod_infra_linux.go
@@ -50,7 +50,11 @@ func (r *Runtime) makeInfraContainer(ctx context.Context, p *Pod, imgName, rawIm
entryPoint = config.Entrypoint
entryCmd = config.Entrypoint
}
+ } else { // so use the InfraCommand
+ entrypointSet = true
+ entryCmd = entryPoint
}
+
if len(config.Cmd) > 0 {
// We can't use the default pause command, since we're
// sourcing from the image. If we didn't already set an
diff --git a/pkg/domain/infra/abi/play.go b/pkg/domain/infra/abi/play.go
index 659cc799c..aa6aeede2 100644
--- a/pkg/domain/infra/abi/play.go
+++ b/pkg/domain/infra/abi/play.go
@@ -299,6 +299,18 @@ func (ic *ContainerEngine) playKubePod(ctx context.Context, podName string, podY
return nil, err
}
+ var ctrRestartPolicy string
+ switch podYAML.Spec.RestartPolicy {
+ case v1.RestartPolicyAlways:
+ ctrRestartPolicy = libpod.RestartPolicyAlways
+ case v1.RestartPolicyOnFailure:
+ ctrRestartPolicy = libpod.RestartPolicyOnFailure
+ case v1.RestartPolicyNever:
+ ctrRestartPolicy = libpod.RestartPolicyNo
+ default: // Default to Always
+ ctrRestartPolicy = libpod.RestartPolicyAlways
+ }
+
containers := make([]*libpod.Container, 0, len(podYAML.Spec.Containers))
for _, container := range podYAML.Spec.Containers {
pullPolicy := util.PullImageMissing
@@ -326,6 +338,7 @@ func (ic *ContainerEngine) playKubePod(ctx context.Context, podName string, podY
if err != nil {
return nil, err
}
+ conf.RestartPolicy = ctrRestartPolicy
ctr, err := createconfig.CreateContainerFromCreateConfig(ctx, ic.Libpod, conf, pod)
if err != nil {
return nil, err
diff --git a/pkg/domain/infra/tunnel/images.go b/pkg/domain/infra/tunnel/images.go
index 50b8342a3..332a7c2eb 100644
--- a/pkg/domain/infra/tunnel/images.go
+++ b/pkg/domain/infra/tunnel/images.go
@@ -306,7 +306,22 @@ func (ir *ImageEngine) Config(_ context.Context) (*config.Config, error) {
}
func (ir *ImageEngine) Build(_ context.Context, containerFiles []string, opts entities.BuildOptions) (*entities.BuildReport, error) {
- return images.Build(ir.ClientCxt, containerFiles, opts)
+ report, err := images.Build(ir.ClientCxt, containerFiles, opts)
+ if err != nil {
+ return nil, err
+ }
+ // For remote clients, if the option for writing to a file was
+ // selected, we need to write to the *client's* filesystem.
+ if len(opts.IIDFile) > 0 {
+ f, err := os.Create(opts.IIDFile)
+ if err != nil {
+ return nil, err
+ }
+ if _, err := f.WriteString(report.ID); err != nil {
+ return nil, err
+ }
+ }
+ return report, nil
}
func (ir *ImageEngine) Tree(ctx context.Context, nameOrID string, opts entities.ImageTreeOptions) (*entities.ImageTreeReport, error) {
diff --git a/test/e2e/build_test.go b/test/e2e/build_test.go
index 0b6e919d0..06054bcb4 100644
--- a/test/e2e/build_test.go
+++ b/test/e2e/build_test.go
@@ -179,8 +179,6 @@ var _ = Describe("Podman build", func() {
})
It("podman build basic alpine and print id to external file", func() {
- SkipIfRemote()
-
// Switch to temp dir and restore it afterwards
cwd, err := os.Getwd()
Expect(err).To(BeNil())
diff --git a/test/e2e/generate_kube_test.go b/test/e2e/generate_kube_test.go
index e886c6000..a3a841dc6 100644
--- a/test/e2e/generate_kube_test.go
+++ b/test/e2e/generate_kube_test.go
@@ -3,6 +3,7 @@ package integration
import (
"os"
"path/filepath"
+ "strconv"
. "github.com/containers/podman/v2/test/utils"
"github.com/ghodss/yaml"
@@ -201,6 +202,39 @@ var _ = Describe("Podman generate kube", func() {
// Expect(err).To(BeNil())
})
+ It("podman generate kube on pod with restartPolicy", func() {
+ // podName, set, expect
+ testSli := [][]string{
+ {"testPod1", "", "Never"}, // some pod create from cmdline, so set it to Never
+ {"testPod2", "always", "Always"},
+ {"testPod3", "on-failure", "OnFailure"},
+ {"testPod4", "no", "Never"},
+ }
+
+ for k, v := range testSli {
+ podName := v[0]
+ podSession := podmanTest.Podman([]string{"pod", "create", "--name", podName})
+ podSession.WaitWithDefaultTimeout()
+ Expect(podSession.ExitCode()).To(Equal(0))
+
+ ctrName := "ctr" + strconv.Itoa(k)
+ ctr1Session := podmanTest.Podman([]string{"create", "--name", ctrName, "--pod", podName,
+ "--restart", v[1], ALPINE, "top"})
+ ctr1Session.WaitWithDefaultTimeout()
+ Expect(ctr1Session.ExitCode()).To(Equal(0))
+
+ kube := podmanTest.Podman([]string{"generate", "kube", podName})
+ kube.WaitWithDefaultTimeout()
+ Expect(kube.ExitCode()).To(Equal(0))
+
+ pod := new(v1.Pod)
+ err := yaml.Unmarshal(kube.Out.Contents(), pod)
+ Expect(err).To(BeNil())
+
+ Expect(string(pod.Spec.RestartPolicy)).To(Equal(v[2]))
+ }
+ })
+
It("podman generate kube on pod with ports", func() {
podName := "test"
podSession := podmanTest.Podman([]string{"pod", "create", "--name", podName, "-p", "4000:4000", "-p", "5000:5000"})
diff --git a/test/e2e/play_kube_test.go b/test/e2e/play_kube_test.go
index f58862ab2..7a5aebcc2 100644
--- a/test/e2e/play_kube_test.go
+++ b/test/e2e/play_kube_test.go
@@ -46,6 +46,7 @@ metadata:
{{ end }}
spec:
+ restartPolicy: {{ .RestartPolicy }}
hostname: {{ .Hostname }}
hostAliases:
{{ range .HostAliases }}
@@ -165,6 +166,7 @@ spec:
{{- end }}
{{- end }}
spec:
+ restartPolicy: {{ .RestartPolicy }}
hostname: {{ .Hostname }}
containers:
{{ with .Ctrs }}
@@ -274,13 +276,14 @@ func generateDeploymentKubeYaml(deployment *Deployment, fileName string) error {
// Pod describes the options a kube yaml can be configured at pod level
type Pod struct {
- Name string
- Hostname string
- HostAliases []HostAlias
- Ctrs []*Ctr
- Volumes []*Volume
- Labels map[string]string
- Annotations map[string]string
+ Name string
+ RestartPolicy string
+ Hostname string
+ HostAliases []HostAlias
+ Ctrs []*Ctr
+ Volumes []*Volume
+ Labels map[string]string
+ Annotations map[string]string
}
type HostAlias struct {
@@ -293,13 +296,14 @@ type HostAlias struct {
// if no containers are added, it will add the default container
func getPod(options ...podOption) *Pod {
p := Pod{
- Name: defaultPodName,
- Hostname: "",
- HostAliases: nil,
- Ctrs: make([]*Ctr, 0),
- Volumes: make([]*Volume, 0),
- Labels: make(map[string]string),
- Annotations: make(map[string]string),
+ Name: defaultPodName,
+ RestartPolicy: "Never",
+ Hostname: "",
+ HostAliases: nil,
+ Ctrs: make([]*Ctr, 0),
+ Volumes: make([]*Volume, 0),
+ Labels: make(map[string]string),
+ Annotations: make(map[string]string),
}
for _, option := range options {
option(&p)
@@ -312,6 +316,12 @@ func getPod(options ...podOption) *Pod {
type podOption func(*Pod)
+func withPodName(name string) podOption {
+ return func(pod *Pod) {
+ pod.Name = name
+ }
+}
+
func withHostname(h string) podOption {
return func(pod *Pod) {
pod.Hostname = h
@@ -333,6 +343,12 @@ func withCtr(c *Ctr) podOption {
}
}
+func withRestartPolicy(policy string) podOption {
+ return func(pod *Pod) {
+ pod.RestartPolicy = policy
+ }
+}
+
func withLabel(k, v string) podOption {
return func(pod *Pod) {
pod.Labels[k] = v
@@ -649,6 +665,30 @@ var _ = Describe("Podman generate kube", func() {
Expect(inspect.OutputToString()).To(ContainSubstring(`[echo hello world]`))
})
+ It("podman play kube test restartPolicy", func() {
+ // podName, set, expect
+ testSli := [][]string{
+ {"testPod1", "", "always"}, // Default eqaul to always
+ {"testPod2", "Always", "always"},
+ {"testPod3", "OnFailure", "on-failure"},
+ {"testPod4", "Never", "no"},
+ }
+ for _, v := range testSli {
+ pod := getPod(withPodName(v[0]), withRestartPolicy(v[1]))
+ err := generatePodKubeYaml(pod, kubeYaml)
+ Expect(err).To(BeNil())
+
+ kube := podmanTest.Podman([]string{"play", "kube", kubeYaml})
+ kube.WaitWithDefaultTimeout()
+ Expect(kube.ExitCode()).To(Equal(0))
+
+ inspect := podmanTest.Podman([]string{"inspect", getCtrNameInPod(pod), "--format", "{{.HostConfig.RestartPolicy.Name}}"})
+ inspect.WaitWithDefaultTimeout()
+ Expect(inspect.ExitCode()).To(Equal(0))
+ Expect(inspect.OutputToString()).To(Equal(v[2]))
+ }
+ })
+
It("podman play kube test hostname", func() {
pod := getPod()
err := generatePodKubeYaml(pod, kubeYaml)
diff --git a/test/e2e/pod_create_test.go b/test/e2e/pod_create_test.go
index ed62e8a4b..168150bff 100644
--- a/test/e2e/pod_create_test.go
+++ b/test/e2e/pod_create_test.go
@@ -345,6 +345,12 @@ var _ = Describe("Podman pod create", func() {
check1.WaitWithDefaultTimeout()
Expect(check1.ExitCode()).To(Equal(0))
Expect(check1.OutputToString()).To(Equal("/pause"))
+
+ // check the Path and Args
+ check2 := podmanTest.Podman([]string{"container", "inspect", "--format", "{{.Path}}:{{.Args}}", data.Containers[0].ID})
+ check2.WaitWithDefaultTimeout()
+ Expect(check2.ExitCode()).To(Equal(0))
+ Expect(check2.OutputToString()).To(Equal("/pause:[/pause]"))
})
It("podman create pod with --infra-command", func() {
@@ -362,6 +368,12 @@ var _ = Describe("Podman pod create", func() {
check1.WaitWithDefaultTimeout()
Expect(check1.ExitCode()).To(Equal(0))
Expect(check1.OutputToString()).To(Equal("/pause1"))
+
+ // check the Path and Args
+ check2 := podmanTest.Podman([]string{"container", "inspect", "--format", "{{.Path}}:{{.Args}}", data.Containers[0].ID})
+ check2.WaitWithDefaultTimeout()
+ Expect(check2.ExitCode()).To(Equal(0))
+ Expect(check2.OutputToString()).To(Equal("/pause1:[/pause1]"))
})
It("podman create pod with --infra-image", func() {
@@ -383,6 +395,12 @@ entrypoint ["/fromimage"]
check1.WaitWithDefaultTimeout()
Expect(check1.ExitCode()).To(Equal(0))
Expect(check1.OutputToString()).To(Equal("/fromimage"))
+
+ // check the Path and Args
+ check2 := podmanTest.Podman([]string{"container", "inspect", "--format", "{{.Path}}:{{.Args}}", data.Containers[0].ID})
+ check2.WaitWithDefaultTimeout()
+ Expect(check2.ExitCode()).To(Equal(0))
+ Expect(check2.OutputToString()).To(Equal("/fromimage:[/fromimage]"))
})
It("podman create pod with --infra-command --infra-image", func() {
@@ -404,5 +422,11 @@ entrypoint ["/fromimage"]
check1.WaitWithDefaultTimeout()
Expect(check1.ExitCode()).To(Equal(0))
Expect(check1.OutputToString()).To(Equal("/fromcommand"))
+
+ // check the Path and Args
+ check2 := podmanTest.Podman([]string{"container", "inspect", "--format", "{{.Path}}:{{.Args}}", data.Containers[0].ID})
+ check2.WaitWithDefaultTimeout()
+ Expect(check2.ExitCode()).To(Equal(0))
+ Expect(check2.OutputToString()).To(Equal("/fromcommand:[/fromcommand]"))
})
})