summaryrefslogtreecommitdiff
path: root/libpod/pod.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2018-02-09 17:13:07 -0500
committerAtomic Bot <atomic-devel@projectatomic.io>2018-02-12 14:28:07 +0000
commit4f225b47c9be6f9d72997cea83c029275c3530db (patch)
tree5b9092449ca27777657e7baf1a880bb1c313ed5b /libpod/pod.go
parentaa85ae212e4cc23df7a6bafe8992dc76770bac87 (diff)
downloadpodman-4f225b47c9be6f9d72997cea83c029275c3530db.tar.gz
podman-4f225b47c9be6f9d72997cea83c029275c3530db.tar.bz2
podman-4f225b47c9be6f9d72997cea83c029275c3530db.zip
Refactor Pod to use a Config struct
This allows us to JSON it and stuff it in the DB - previously, all pod fields were private, so JSON couldn't encode them. This allows us to keep all pod fields private by having a substruct with public fields. Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #184 Approved by: baude
Diffstat (limited to 'libpod/pod.go')
-rw-r--r--libpod/pod.go32
1 files changed, 19 insertions, 13 deletions
diff --git a/libpod/pod.go b/libpod/pod.go
index 09e003608..d1e53f415 100644
--- a/libpod/pod.go
+++ b/libpod/pod.go
@@ -11,29 +11,34 @@ import (
// Pod represents a group of containers that may share namespaces
type Pod struct {
- id string `json:"id"`
- name string `json:"name"`
- labels map[string]string `json:"labels"`
+ config *PodConfig
- valid bool `json:"-"`
- runtime *Runtime `json:"-"`
- lock storage.Locker `json:"-"`
+ valid bool
+ runtime *Runtime
+ lock storage.Locker
+}
+
+// PodConfig represents a pod's static configuration
+type PodConfig struct {
+ ID string `json:"id"`
+ Name string `json:"name"`
+ Labels map[string]string `json:""`
}
// ID retrieves the pod's ID
func (p *Pod) ID() string {
- return p.id
+ return p.config.ID
}
// Name retrieves the pod's name
func (p *Pod) Name() string {
- return p.name
+ return p.config.Name
}
// Labels returns the pod's labels
func (p *Pod) Labels() map[string]string {
labels := make(map[string]string)
- for key, value := range p.labels {
+ for key, value := range p.config.Labels {
labels[key] = value
}
@@ -43,13 +48,14 @@ func (p *Pod) Labels() map[string]string {
// Creates a new, empty pod
func newPod(lockDir string, runtime *Runtime) (*Pod, error) {
pod := new(Pod)
- pod.id = stringid.GenerateNonCryptoID()
- pod.name = namesgenerator.GetRandomName(0)
- pod.labels = make(map[string]string)
+ pod.config = new(PodConfig)
+ pod.config.ID = stringid.GenerateNonCryptoID()
+ pod.config.Name = namesgenerator.GetRandomName(0)
+ pod.config.Labels = make(map[string]string)
pod.runtime = runtime
// Path our lock file will reside at
- lockPath := filepath.Join(lockDir, pod.id)
+ lockPath := filepath.Join(lockDir, pod.config.ID)
// Grab a lockfile at the given path
lock, err := storage.GetLockfile(lockPath)
if err != nil {