summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
Diffstat (limited to 'pkg')
-rw-r--r--pkg/domain/entities/engine.go1
-rw-r--r--pkg/domain/entities/events.go2
-rw-r--r--pkg/domain/entities/pods.go12
-rw-r--r--pkg/domain/infra/abi/images.go50
-rw-r--r--pkg/machine/config.go9
-rw-r--r--pkg/machine/qemu/machine.go122
-rw-r--r--pkg/specgen/podspecgen.go2
7 files changed, 163 insertions, 35 deletions
diff --git a/pkg/domain/entities/engine.go b/pkg/domain/entities/engine.go
index a8023f7cf..055af7ff9 100644
--- a/pkg/domain/entities/engine.go
+++ b/pkg/domain/entities/engine.go
@@ -40,6 +40,7 @@ type PodmanConfig struct {
Identity string // ssh identity for connecting to server
MaxWorks int // maximum number of parallel threads
MemoryProfile string // Hidden: Should memory profile be taken
+ NoOut bool // Don't output to stdout
RegistriesConf string // allows for specifying a custom registries.conf
Remote bool // Connection to Podman API Service will use RESTful API
RuntimePath string // --runtime flag will set Engine.RuntimePath
diff --git a/pkg/domain/entities/events.go b/pkg/domain/entities/events.go
index 73a375b94..fa815d7b9 100644
--- a/pkg/domain/entities/events.go
+++ b/pkg/domain/entities/events.go
@@ -42,7 +42,7 @@ func ConvertToLibpodEvent(e Event) *libpodEvents.Event {
Image: image,
Name: name,
Status: status,
- Time: time.Unix(e.Time, e.TimeNano),
+ Time: time.Unix(0, e.TimeNano),
Type: t,
Details: libpodEvents.Details{
Attributes: details,
diff --git a/pkg/domain/entities/pods.go b/pkg/domain/entities/pods.go
index 1b5a1be51..cc9476d79 100644
--- a/pkg/domain/entities/pods.go
+++ b/pkg/domain/entities/pods.go
@@ -139,6 +139,7 @@ type PodCreateOptions struct {
Volume []string `json:"volume,omitempty"`
VolumesFrom []string `json:"volumes_from,omitempty"`
SecurityOpt []string `json:"security_opt,omitempty"`
+ Sysctl []string `json:"sysctl,omitempty"`
}
// PodLogsOptions describes the options to extract pod logs.
@@ -240,7 +241,7 @@ type ContainerCreateOptions struct {
StorageOpts []string
SubUIDName string
SubGIDName string
- Sysctl []string
+ Sysctl []string `json:"sysctl,omitempty"`
Systemd string
Timeout uint
TLSVerify commonFlag.OptionalBool
@@ -360,6 +361,15 @@ func ToPodSpecGen(s specgen.PodSpecGenerator, p *PodCreateOptions) (*specgen.Pod
}
}
s.Userns = p.Userns
+ sysctl := map[string]string{}
+ if ctl := p.Sysctl; len(ctl) > 0 {
+ sysctl, err = util.ValidateSysctls(ctl)
+ if err != nil {
+ return nil, err
+ }
+ }
+ s.Sysctl = sysctl
+
return &s, nil
}
diff --git a/pkg/domain/infra/abi/images.go b/pkg/domain/infra/abi/images.go
index 84c83ea8e..592e0f4e3 100644
--- a/pkg/domain/infra/abi/images.go
+++ b/pkg/domain/infra/abi/images.go
@@ -745,11 +745,17 @@ func putSignature(manifestBlob []byte, mech signature.SigningMechanism, sigStore
// TransferRootless creates new podman processes using exec.Command and sudo, transferring images between the given source and destination users
func transferRootless(source entities.ImageScpOptions, dest entities.ImageScpOptions, podman string, parentFlags []string) error {
var cmdSave *exec.Cmd
- saveCommand := parentFlags
- saveCommand = append(saveCommand, []string{"save", "--output", source.File, source.Image}...)
+ saveCommand, loadCommand := parentFlags, parentFlags
+ saveCommand = append(saveCommand, []string{"save"}...)
+ loadCommand = append(loadCommand, []string{"load"}...)
+ if source.Quiet {
+ saveCommand = append(saveCommand, "-q")
+ loadCommand = append(loadCommand, "-q")
+ }
+
+ saveCommand = append(saveCommand, []string{"--output", source.File, source.Image}...)
- loadCommand := parentFlags
- loadCommand = append(loadCommand, []string{"load", "--input", dest.File}...)
+ loadCommand = append(loadCommand, []string{"--input", dest.File}...)
if source.User == "root" {
cmdSave = exec.Command("sudo", podman)
@@ -757,7 +763,7 @@ func transferRootless(source entities.ImageScpOptions, dest entities.ImageScpOpt
cmdSave = exec.Command(podman)
}
cmdSave = utils.CreateSCPCommand(cmdSave, saveCommand)
- logrus.Debug("Executing save command")
+ logrus.Debugf("Executing save command: %q", cmdSave)
err := cmdSave.Run()
if err != nil {
return err
@@ -770,20 +776,22 @@ func transferRootless(source entities.ImageScpOptions, dest entities.ImageScpOpt
cmdLoad = exec.Command(podman)
}
cmdLoad = utils.CreateSCPCommand(cmdLoad, loadCommand)
- logrus.Debug("Executing load command")
- err = cmdLoad.Run()
- if err != nil {
- return err
- }
- return nil
+ logrus.Debugf("Executing load command: %q", cmdLoad)
+ return cmdLoad.Run()
}
-// TransferRootless creates new podman processes using exec.Command and su/machinectl, transferring images between the given source and destination users
+// TransferRootful creates new podman processes using exec.Command and su/machinectl, transferring images between the given source and destination users
func transferRootful(source entities.ImageScpOptions, dest entities.ImageScpOptions, podman string, parentFlags []string) error {
basicCommand := []string{podman}
basicCommand = append(basicCommand, parentFlags...)
- saveCommand := append(basicCommand, []string{"save", "--output", source.File, source.Image}...)
- loadCommand := append(basicCommand, []string{"load", "--input", dest.File}...)
+ saveCommand := append(basicCommand, "save")
+ loadCommand := append(basicCommand, "load")
+ if source.Quiet {
+ saveCommand = append(saveCommand, "-q")
+ loadCommand = append(loadCommand, "-q")
+ }
+ saveCommand = append(saveCommand, []string{"--output", source.File, source.Image}...)
+ loadCommand = append(loadCommand, []string{"--input", dest.File}...)
save := []string{strings.Join(saveCommand, " ")}
load := []string{strings.Join(loadCommand, " ")}
@@ -846,18 +854,18 @@ func lookupUser(u string) (*user.User, error) {
func execSu(execUser *user.User, command []string) error {
cmd := exec.Command("su", "-l", execUser.Username, "--command")
cmd = utils.CreateSCPCommand(cmd, command)
- logrus.Debug("Executing command su")
+ logrus.Debugf("Executing via su: %q", cmd)
return cmd.Run()
}
func execMachine(execUser *user.User, command []string, machinectl string) error {
- var cmd *exec.Cmd
+ verb := machinectl
+ args := []string{"shell", "-q", execUser.Username + "@.host"}
if execUser.Uid == "0" {
- cmd = exec.Command("sudo", machinectl, "shell", "-q", execUser.Username+"@.host")
- } else {
- cmd = exec.Command(machinectl, "shell", "-q", execUser.Username+"@.host")
+ args = append([]string{verb}, args...)
+ verb = "sudo"
}
- cmd = utils.CreateSCPCommand(cmd, command)
- logrus.Debug("Executing command machinectl")
+ cmd := utils.CreateSCPCommand(exec.Command(verb, args...), command)
+ logrus.Debugf("Executing via machinectl: %q", cmd)
return cmd.Run()
}
diff --git a/pkg/machine/config.go b/pkg/machine/config.go
index 27a7c1b1f..97237f5e5 100644
--- a/pkg/machine/config.go
+++ b/pkg/machine/config.go
@@ -29,6 +29,15 @@ type InitOptions struct {
ReExec bool
}
+type QemuMachineStatus = string
+
+const (
+ // Running indicates the qemu vm is running
+ Running QemuMachineStatus = "running"
+ // Stopped indicates the vm has stopped
+ Stopped QemuMachineStatus = "stopped"
+)
+
type Provider interface {
NewMachine(opts InitOptions) (VM, error)
LoadVMByName(name string) (VM, error)
diff --git a/pkg/machine/qemu/machine.go b/pkg/machine/qemu/machine.go
index a43d78665..560037542 100644
--- a/pkg/machine/qemu/machine.go
+++ b/pkg/machine/qemu/machine.go
@@ -386,8 +386,16 @@ func (v *MachineVM) Start(name string, _ machine.StartOptions) error {
}
if len(v.Mounts) > 0 {
- for !v.isRunning() || !v.isListening() {
+ running, err := v.isRunning()
+ if err != nil {
+ return err
+ }
+ for running || !v.isListening() {
time.Sleep(100 * time.Millisecond)
+ running, err = v.isRunning()
+ if err != nil {
+ return err
+ }
}
}
for _, mount := range v.Mounts {
@@ -416,8 +424,48 @@ func (v *MachineVM) Start(name string, _ machine.StartOptions) error {
return nil
}
+func (v *MachineVM) checkStatus(monitor *qmp.SocketMonitor) (machine.QemuMachineStatus, error) {
+ // this is the format returned from the monitor
+ // {"return": {"status": "running", "singlestep": false, "running": true}}
+
+ type statusDetails struct {
+ Status string `json:"status"`
+ Step bool `json:"singlestep"`
+ Running bool `json:"running"`
+ }
+ type statusResponse struct {
+ Response statusDetails `json:"return"`
+ }
+ var response statusResponse
+
+ checkCommand := struct {
+ Execute string `json:"execute"`
+ }{
+ Execute: "query-status",
+ }
+ input, err := json.Marshal(checkCommand)
+ if err != nil {
+ return "", err
+ }
+ b, err := monitor.Run(input)
+ if err != nil {
+ if errors.Cause(err) == os.ErrNotExist {
+ return machine.Stopped, nil
+ }
+ return "", err
+ }
+ if err := json.Unmarshal(b, &response); err != nil {
+ return "", err
+ }
+ if response.Response.Status == machine.Running {
+ return machine.Running, nil
+ }
+ return machine.Stopped, nil
+}
+
// Stop uses the qmp monitor to call a system_powerdown
func (v *MachineVM) Stop(name string, _ machine.StopOptions) error {
+ var disconnected bool
// check if the qmp socket is there. if not, qemu instance is gone
if _, err := os.Stat(v.QMPMonitor.Address); os.IsNotExist(err) {
// Right now it is NOT an error to stop a stopped machine
@@ -442,19 +490,22 @@ func (v *MachineVM) Stop(name string, _ machine.StopOptions) error {
return err
}
defer func() {
- if err := qmpMonitor.Disconnect(); err != nil {
- logrus.Error(err)
+ if !disconnected {
+ if err := qmpMonitor.Disconnect(); err != nil {
+ logrus.Error(err)
+ }
}
}()
+
if _, err = qmpMonitor.Run(input); err != nil {
return err
}
+
qemuSocketFile, pidFile, err := v.getSocketandPid()
if err != nil {
return err
}
if _, err := os.Stat(pidFile); os.IsNotExist(err) {
- logrus.Info(err)
return nil
}
pidString, err := ioutil.ReadFile(pidFile)
@@ -483,6 +534,24 @@ func (v *MachineVM) Stop(name string, _ machine.StopOptions) error {
return err
}
+ if err := qmpMonitor.Disconnect(); err != nil {
+ return nil
+ }
+
+ disconnected = true
+ waitInternal := 250 * time.Millisecond
+ for i := 0; i < 5; i++ {
+ running, err := v.isRunning()
+ if err != nil {
+ return err
+ }
+ if !running {
+ break
+ }
+ time.Sleep(waitInternal)
+ waitInternal = waitInternal * 2
+ }
+
return nil
}
@@ -519,7 +588,11 @@ func (v *MachineVM) Remove(name string, opts machine.RemoveOptions) (string, fun
)
// cannot remove a running vm
- if v.isRunning() {
+ running, err := v.isRunning()
+ if err != nil {
+ return "", nil, err
+ }
+ if running {
return "", nil, errors.Errorf("running vm %q cannot be destroyed", v.Name)
}
@@ -578,16 +651,33 @@ func (v *MachineVM) Remove(name string, opts machine.RemoveOptions) (string, fun
}, nil
}
-func (v *MachineVM) isRunning() bool {
+func (v *MachineVM) isRunning() (bool, error) {
// Check if qmp socket path exists
if _, err := os.Stat(v.QMPMonitor.Address); os.IsNotExist(err) {
- return false
+ return false, nil
}
// Check if we can dial it
- if _, err := qmp.NewSocketMonitor(v.QMPMonitor.Network, v.QMPMonitor.Address, v.QMPMonitor.Timeout); err != nil {
- return false
+ monitor, err := qmp.NewSocketMonitor(v.QMPMonitor.Network, v.QMPMonitor.Address, v.QMPMonitor.Timeout)
+ if err != nil {
+ return false, nil
}
- return true
+ if err := monitor.Connect(); err != nil {
+ return false, err
+ }
+ defer func() {
+ if err := monitor.Disconnect(); err != nil {
+ logrus.Error(err)
+ }
+ }()
+ // If there is a monitor, lets see if we can query state
+ state, err := v.checkStatus(monitor)
+ if err != nil {
+ return false, err
+ }
+ if state == machine.Running {
+ return true, nil
+ }
+ return false, nil
}
func (v *MachineVM) isListening() bool {
@@ -603,7 +693,11 @@ func (v *MachineVM) isListening() bool {
// SSH opens an interactive SSH session to the vm specified.
// Added ssh function to VM interface: pkg/machine/config/go : line 58
func (v *MachineVM) SSH(name string, opts machine.SSHOptions) error {
- if !v.isRunning() {
+ running, err := v.isRunning()
+ if err != nil {
+ return err
+ }
+ if !running {
return errors.Errorf("vm %q is not running.", v.Name)
}
@@ -710,7 +804,11 @@ func GetVMInfos() ([]*machine.ListResponse, error) {
return err
}
listEntry.LastUp = fi.ModTime()
- if vm.isRunning() {
+ running, err := vm.isRunning()
+ if err != nil {
+ return err
+ }
+ if running {
listEntry.Running = true
}
diff --git a/pkg/specgen/podspecgen.go b/pkg/specgen/podspecgen.go
index ec4c66595..b6f2d6bf0 100644
--- a/pkg/specgen/podspecgen.go
+++ b/pkg/specgen/podspecgen.go
@@ -74,6 +74,8 @@ type PodBasicConfig struct {
Userns Namespace `json:"userns,omitempty"`
// Devices contains user specified Devices to be added to the Pod
Devices []string `json:"pod_devices,omitempty"`
+ // Sysctl sets kernel parameters for the pod
+ Sysctl map[string]string `json:"sysctl,omitempty"`
}
// PodNetworkConfig contains networking configuration for a pod.