Fix issues instantiating the server struct
This commit is contained in:
parent
bdf546c47a
commit
be14811eb4
3
go.mod
3
go.mod
|
@ -9,7 +9,7 @@ require (
|
|||
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a
|
||||
github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23
|
||||
github.com/containerd/fifo v0.0.0-20190226154929-a9fb20d87448 // indirect
|
||||
github.com/creasty/defaults v1.3.0 // indirect
|
||||
github.com/creasty/defaults v1.3.0
|
||||
github.com/docker/distribution v2.7.1+incompatible // indirect
|
||||
github.com/docker/docker v0.0.0-20180422163414-57142e89befe
|
||||
github.com/docker/go-connections v0.4.0
|
||||
|
@ -23,6 +23,7 @@ require (
|
|||
github.com/imdario/mergo v0.3.8
|
||||
github.com/julienschmidt/httprouter v1.2.0
|
||||
github.com/kr/pretty v0.1.0 // indirect
|
||||
github.com/mcuadros/go-defaults v1.1.0
|
||||
github.com/olebedev/emitter v0.0.0-20190110104742-e8d1457e6aee
|
||||
github.com/onsi/ginkgo v1.8.0 // indirect
|
||||
github.com/onsi/gomega v1.5.0 // indirect
|
||||
|
|
2
go.sum
2
go.sum
|
@ -53,6 +53,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
|||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/magefile/mage v1.9.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
|
||||
github.com/mcuadros/go-defaults v1.1.0 h1:K0LgSNfsSUrbEHR7HgfZpOHVWYsPnYh/dKTA7pGeZ/I=
|
||||
github.com/mcuadros/go-defaults v1.1.0/go.mod h1:vl9cJiNIIHISQeboDhZBUCiCOa3GkeioLe3Y95NXF6Y=
|
||||
github.com/olebedev/emitter v0.0.0-20190110104742-e8d1457e6aee h1:IquUs3fIykn10zWDIyddanhpTqBvAHMaPnFhQuyYw5U=
|
||||
github.com/olebedev/emitter v0.0.0-20190110104742-e8d1457e6aee/go.mod h1:eT2/Pcsim3XBjbvldGiJBvvgiqZkAFyiOJJsDKXs/ts=
|
||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
|
|
|
@ -32,14 +32,14 @@ func New(data []byte) (*Installer, error) {
|
|||
State: server.ProcessOfflineState,
|
||||
Invocation: "",
|
||||
EnvVars: make(map[string]string),
|
||||
Build: &server.BuildSettings{
|
||||
Build: server.BuildSettings{
|
||||
MemoryLimit: getInt(data, "build", "memory"),
|
||||
Swap: getInt(data, "build", "swap"),
|
||||
IoWeight: uint16(getInt(data, "build", "io")),
|
||||
CpuLimit: getInt(data, "build", "cpu"),
|
||||
DiskSpace: getInt(data, "build", "disk"),
|
||||
},
|
||||
Allocations: &server.Allocations{
|
||||
Allocations: server.Allocations{
|
||||
Mappings: make(map[string][]int),
|
||||
},
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package server
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mcuadros/go-defaults"
|
||||
"github.com/patrickmn/go-cache"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/pterodactyl/wings/api"
|
||||
|
@ -38,8 +39,11 @@ type Server struct {
|
|||
// server process.
|
||||
EnvVars map[string]string `json:"environment" yaml:"environment"`
|
||||
|
||||
Build *BuildSettings `json:"build"`
|
||||
Allocations *Allocations `json:"allocations"`
|
||||
Build BuildSettings `json:"build"`
|
||||
Allocations Allocations `json:"allocations"`
|
||||
Environment Environment `json:"-" yaml:"-"`
|
||||
Filesystem Filesystem `json:"-" yaml:"-"`
|
||||
Resources ResourceUsage `json:"resources" yaml:"-"`
|
||||
|
||||
Container struct {
|
||||
// Defines the Docker image that will be used for this server
|
||||
|
@ -51,12 +55,6 @@ type Server struct {
|
|||
RebuildRequired bool `default:"false" json:"rebuild_required,omitempty" yaml:"rebuild_required"`
|
||||
} `json:"container,omitempty"`
|
||||
|
||||
Environment Environment `json:"-" yaml:"-"`
|
||||
|
||||
Filesystem *Filesystem `json:"-" yaml:"-"`
|
||||
|
||||
Resources *ResourceUsage `json:"resources" yaml:"-"`
|
||||
|
||||
// Server cache used to store frequently requested information in memory and make
|
||||
// certain long operations return faster. For example, FS disk space usage.
|
||||
Cache *cache.Cache `json:"-" yaml:"-"`
|
||||
|
@ -199,7 +197,8 @@ func (s *Server) Init() {
|
|||
// given struct using a YAML marshaler. This will also configure the given environment
|
||||
// for a server.
|
||||
func FromConfiguration(data []byte, cfg *config.SystemConfiguration) (*Server, error) {
|
||||
s := &Server{}
|
||||
s := new(Server)
|
||||
defaults.SetDefaults(s)
|
||||
s.Init()
|
||||
|
||||
if err := yaml.Unmarshal(data, s); err != nil {
|
||||
|
@ -226,11 +225,11 @@ func FromConfiguration(data []byte, cfg *config.SystemConfiguration) (*Server, e
|
|||
|
||||
s.Environment = env
|
||||
s.Cache = cache.New(time.Minute*10, time.Minute*15)
|
||||
s.Filesystem = &Filesystem{
|
||||
s.Filesystem = Filesystem{
|
||||
Configuration: cfg,
|
||||
Server: s,
|
||||
}
|
||||
s.Resources = &ResourceUsage{}
|
||||
s.Resources = ResourceUsage{}
|
||||
|
||||
// This is also done when the server is booted, however we need to account for instances
|
||||
// where the server is already running and the Daemon reboots. In those cases this will
|
||||
|
@ -277,6 +276,7 @@ func (s *Server) SetState(state string) error {
|
|||
return errors.New(fmt.Sprintf("invalid server state received: %s", state))
|
||||
}
|
||||
|
||||
prevState := s.State
|
||||
s.State = state
|
||||
|
||||
// Persist this change to the disk immediately so that should the Daemon be stopped or
|
||||
|
|
|
@ -61,7 +61,7 @@ func (s *Server) UpdateDataStructure(data []byte) error {
|
|||
s.EnvVars = src.EnvVars
|
||||
}
|
||||
|
||||
if src.Allocations != nil && src.Allocations.Mappings != nil && len(src.Allocations.Mappings) > 0 {
|
||||
if src.Allocations.Mappings != nil && len(src.Allocations.Mappings) > 0 {
|
||||
s.Allocations.Mappings = src.Allocations.Mappings
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user