From 0879a948445b53b0090ac4e7721ff3a37f477cdd Mon Sep 17 00:00:00 2001 From: arcnmx Date: Wed, 23 Dec 2015 05:52:47 -0500 Subject: [PATCH 1/2] Appropriately mark optional fields as omitempty Signed-off-by: Jonathan Boulle --- config.go | 6 +++--- config_linux.go | 2 +- runtime_config.go | 12 ++++++------ runtime_config_linux.go | 10 +++++----- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/config.go b/config.go index de2aa5a47..cff5336b5 100644 --- a/config.go +++ b/config.go @@ -13,7 +13,7 @@ type Spec struct { // Root is the root information for the container's filesystem. Root Root `json:"root"` // Hostname is the container's host name. - Hostname string `json:"hostname"` + Hostname string `json:"hostname,omitempty"` // Mounts profile configuration for adding mounts to the container's filesystem. Mounts []MountPoint `json:"mounts"` } @@ -27,10 +27,10 @@ type Process struct { // Args specifies the binary and arguments for the application to execute. Args []string `json:"args"` // Env populates the process environment for the process. - Env []string `json:"env"` + Env []string `json:"env,omitempty"` // Cwd is the current working directory for the process and must be // relative to the container's root. - Cwd string `json:"cwd"` + Cwd string `json:"cwd,omitempty"` } // Root contains information about the container's root filesystem on the host. diff --git a/config_linux.go b/config_linux.go index b9915538a..a715bb567 100644 --- a/config_linux.go +++ b/config_linux.go @@ -21,5 +21,5 @@ type User struct { // GID is the group id. GID uint32 `json:"gid"` // AdditionalGids are additional group ids set for the container's process. - AdditionalGids []uint32 `json:"additionalGids"` + AdditionalGids []uint32 `json:"additionalGids,omitempty"` } diff --git a/runtime_config.go b/runtime_config.go index 5665ca9f9..931f912c4 100644 --- a/runtime_config.go +++ b/runtime_config.go @@ -15,19 +15,19 @@ type RuntimeSpec struct { // Hook specifies a command that is run at a particular event in the lifecycle of a container type Hook struct { Path string `json:"path"` - Args []string `json:"args"` - Env []string `json:"env"` + Args []string `json:"args,omitempty"` + Env []string `json:"env,omitempty"` } // Hooks for container setup and teardown type Hooks struct { // Prestart is a list of hooks to be run before the container process is executed. // On Linux, they are run after the container namespaces are created. - Prestart []Hook `json:"prestart"` + Prestart []Hook `json:"prestart,omitempty"` // Poststart is a list of hooks to be run after the container process is started. - Poststart []Hook `json:"poststart"` + Poststart []Hook `json:"poststart,omitempty"` // Poststop is a list of hooks to be run after the container process exits. - Poststop []Hook `json:"poststop"` + Poststop []Hook `json:"poststop,omitempty"` } // Mount specifies a mount for a container @@ -38,5 +38,5 @@ type Mount struct { // linux based systems this would be the file on the host. Source string `json:"source"` // Options are fstab style mount options. - Options []string `json:"options"` + Options []string `json:"options,omitempty"` } diff --git a/runtime_config_linux.go b/runtime_config_linux.go index 0ce0c1083..aeca94271 100644 --- a/runtime_config_linux.go +++ b/runtime_config_linux.go @@ -15,13 +15,13 @@ type LinuxRuntimeSpec struct { // LinuxRuntime hosts the Linux-only runtime information type LinuxRuntime struct { // UIDMapping specifies user mappings for supporting user namespaces on linux. - UIDMappings []IDMapping `json:"uidMappings"` + UIDMappings []IDMapping `json:"uidMappings,omitempty"` // GIDMapping specifies group mappings for supporting user namespaces on linux. - GIDMappings []IDMapping `json:"gidMappings"` + GIDMappings []IDMapping `json:"gidMappings,omitempty"` // Rlimits specifies rlimit options to apply to the container's process. - Rlimits []Rlimit `json:"rlimits"` + Rlimits []Rlimit `json:"rlimits,omitempty"` // Sysctl are a set of key value pairs that are set for the container on start - Sysctl map[string]string `json:"sysctl"` + Sysctl map[string]string `json:"sysctl,omitempty"` // Resources contain cgroup information for handling resource constraints // for the container Resources *Resources `json:"resources,omitempty"` @@ -49,7 +49,7 @@ type Namespace struct { Type NamespaceType `json:"type"` // Path is a path to an existing namespace persisted on disk that can be joined // and is of the same type - Path string `json:"path"` + Path string `json:"path,omitempty"` } // NamespaceType is one of the linux namespaces From 986fc9831eb4b90909679435e2921673442109ae Mon Sep 17 00:00:00 2001 From: Jonathan Boulle Date: Thu, 31 Dec 2015 12:16:27 +0100 Subject: [PATCH 2/2] Mark RootfsPropagation as omitempty Signed-off-by: Jonathan Boulle --- runtime_config_linux.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime_config_linux.go b/runtime_config_linux.go index aeca94271..d01cc7bc3 100644 --- a/runtime_config_linux.go +++ b/runtime_config_linux.go @@ -40,7 +40,7 @@ type LinuxRuntime struct { // Seccomp specifies the seccomp security settings for the container. Seccomp Seccomp `json:"seccomp"` // RootfsPropagation is the rootfs mount propagation mode for the container - RootfsPropagation string `json:"rootfsPropagation"` + RootfsPropagation string `json:"rootfsPropagation,omitempty"` } // Namespace is the configuration for a linux namespace