From 636881ece56f77df4c6a25dc5faa68a740607e3f Mon Sep 17 00:00:00 2001
From: Valentin Rothberg <rothberg@redhat.com>
Date: Thu, 28 May 2020 10:54:17 +0200
Subject: pod config: add a `CreateCommand` field

Add a `CreateCommand` field to the pod config which includes the entire
`os.Args` at pod-creation.  Similar to the already existing field in a
container config, we need this information to properly generate generic
systemd unit files for pods.  It's a prerequisite to support the `--new`
flag for pods.

Also add the `CreateCommand` to the pod-inspect data, which can come in
handy for debugging, general inspection and certainly for the tests that
are added along with the other changes.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
---
 libpod/define/pod_inspect.go |  3 +++
 libpod/options.go            | 12 ++++++++++++
 libpod/pod.go                |  4 ++++
 libpod/pod_api.go            |  1 +
 4 files changed, 20 insertions(+)

(limited to 'libpod')

diff --git a/libpod/define/pod_inspect.go b/libpod/define/pod_inspect.go
index 26fd2cab4..7f06e16fc 100644
--- a/libpod/define/pod_inspect.go
+++ b/libpod/define/pod_inspect.go
@@ -18,6 +18,9 @@ type InspectPodData struct {
 	Namespace string `json:"Namespace,omitempty"`
 	// Created is the time when the pod was created.
 	Created time.Time
+	// CreateCommand is the full command plus arguments of the process the
+	// container has been created with.
+	CreateCommand []string `json:"CreateCommand,omitempty"`
 	// State represents the current state of the pod.
 	State string `json:"State"`
 	// Hostname is the hostname that the pod will set.
diff --git a/libpod/options.go b/libpod/options.go
index 8e0d3df86..75d098815 100644
--- a/libpod/options.go
+++ b/libpod/options.go
@@ -1538,6 +1538,18 @@ func WithPodHostname(hostname string) PodCreateOption {
 	}
 }
 
+// WithPodCreateCommand adds the full command plus arguments of the current
+// process to the pod config.
+func WithPodCreateCommand() PodCreateOption {
+	return func(pod *Pod) error {
+		if pod.valid {
+			return define.ErrPodFinalized
+		}
+		pod.config.CreateCommand = os.Args
+		return nil
+	}
+}
+
 // WithPodLabels sets the labels of a pod.
 func WithPodLabels(labels map[string]string) PodCreateOption {
 	return func(pod *Pod) error {
diff --git a/libpod/pod.go b/libpod/pod.go
index 8afaa6052..38fe1fd2c 100644
--- a/libpod/pod.go
+++ b/libpod/pod.go
@@ -64,6 +64,10 @@ type PodConfig struct {
 	// Time pod was created
 	CreatedTime time.Time `json:"created"`
 
+	// CreateCommand is the full command plus arguments of the process the
+	// container has been created with.
+	CreateCommand []string `json:"CreateCommand,omitempty"`
+
 	// ID of the pod's lock
 	LockID uint32 `json:"lockID"`
 }
diff --git a/libpod/pod_api.go b/libpod/pod_api.go
index e2c4b515d..c8605eb69 100644
--- a/libpod/pod_api.go
+++ b/libpod/pod_api.go
@@ -489,6 +489,7 @@ func (p *Pod) Inspect() (*define.InspectPodData, error) {
 		Name:             p.Name(),
 		Namespace:        p.Namespace(),
 		Created:          p.CreatedTime(),
+		CreateCommand:    p.config.CreateCommand,
 		State:            podState,
 		Hostname:         p.config.Hostname,
 		Labels:           p.Labels(),
-- 
cgit v1.2.3-54-g00ecf