Files
podman/libpod/pod_internal.go
Valentin Rothberg dcbf7b4481 bump golangci-lint to v1.50.1
Also fix a number of duplicate words.  Yet disable the new `dupword`
linter as it displays too many false positives.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2022-12-15 13:39:56 +01:00

70 lines
1.5 KiB
Go

package libpod
import (
"fmt"
"time"
"github.com/containers/podman/v4/libpod/define"
"github.com/containers/storage/pkg/stringid"
)
// Creates a new, empty pod
func newPod(runtime *Runtime) *Pod {
pod := new(Pod)
pod.config = new(PodConfig)
pod.config.ID = stringid.GenerateRandomID()
pod.config.Labels = make(map[string]string)
pod.config.CreatedTime = time.Now()
// pod.config.InfraContainer = new(ContainerConfig)
pod.state = new(podState)
pod.runtime = runtime
return pod
}
// Update pod state from database
func (p *Pod) updatePod() error {
if err := p.runtime.state.UpdatePod(p); err != nil {
return err
}
return nil
}
// Save pod state to database
func (p *Pod) save() error {
if err := p.runtime.state.SavePod(p); err != nil {
return fmt.Errorf("saving pod %s state: %w", p.ID(), err)
}
return nil
}
// Refresh a pod's state after restart
// This cannot lock any other pod, but may lock individual containers, as those
// will have refreshed by the time pod refresh runs.
func (p *Pod) refresh() error {
// Need to do an update from the DB to pull potentially-missing state
if err := p.runtime.state.UpdatePod(p); err != nil {
return err
}
if !p.valid {
return define.ErrPodRemoved
}
// Retrieve the pod's lock
lock, err := p.runtime.lockManager.AllocateAndRetrieveLock(p.config.LockID)
if err != nil {
return fmt.Errorf("retrieving lock %d for pod %s: %w", p.config.LockID, p.ID(), err)
}
p.lock = lock
if err := p.platformRefresh(); err != nil {
return err
}
// Save changes
return p.save()
}