From 4477c558f2b30a81c50bb87af6379cc0a39d881b Mon Sep 17 00:00:00 2001 From: Nikolai Rodionov Date: Mon, 6 May 2024 21:57:54 +0200 Subject: [PATCH] Add disk size as an option --- api/v1/environments.go | 4 ++++ go.mod | 2 +- go.sum | 4 ++-- internal/controllers/environments.go | 11 +++++++++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/api/v1/environments.go b/api/v1/environments.go index c908b71..639d558 100644 --- a/api/v1/environments.go +++ b/api/v1/environments.go @@ -58,6 +58,7 @@ func (e *EnvironmentsServer) Create(ctx context.Context, in *proto.CreateOptions Kubernetes: k8s.GetKubernetesName(), Location: location, ServerType: serverType, + DiskSize: int(in.GetSpec().GetDiskSize()), } environment := &controllers.Environemnt{ @@ -114,6 +115,7 @@ func (e *EnvironmentsServer) Update(ctx context.Context, in *proto.UpdateOptions Kubernetes: k8s.GetKubernetesName(), Location: location, ServerType: serverType, + DiskSize: int(in.GetSpec().GetDiskSize()), } environment := &controllers.Environemnt{ @@ -198,6 +200,7 @@ func (e *EnvironmentsServer) Get(ctx context.Context, in *proto.GetOptions) (*pr Kubernetes: proto.Kubernetes(proto.Kubernetes_value[k8s.RawKubernetesName()]), ServerLocation: proto.Location(proto.Location_value[provider.RawServerLocation(environment.Data.Location)]), ServerType: proto.ServerType(proto.ServerType_value[provider.RawServerType(environment.Data.ServerType)]), + DiskSize: int32(environment.Data.DiskSize), }, Id: in.GetId(), Metadata: &proto.EnvironmentMetadata{ @@ -248,6 +251,7 @@ func (e *EnvironmentsServer) List(in *proto.ListOptions, stream proto.Environmen Kubernetes: proto.Kubernetes(proto.Kubernetes_value[k8s.RawKubernetesName()]), ServerLocation: proto.Location(proto.Location_value[provider.RawServerLocation(env.Data.Location)]), ServerType: proto.ServerType(proto.ServerType_value[provider.RawServerType(env.Data.ServerType)]), + DiskSize: int32(env.Data.DiskSize), }, }); err != nil { return err diff --git a/go.mod b/go.mod index e4f15e3..18c3182 100644 --- a/go.mod +++ b/go.mod @@ -150,7 +150,7 @@ require ( ) require ( - git.badhouseplants.net/softplayer/softplayer-go-proto v0.1.11 + git.badhouseplants.net/softplayer/softplayer-go-proto v0.1.12 github.com/golang/protobuf v1.5.4 golang.org/x/net v0.24.0 // indirect golang.org/x/sys v0.19.0 // indirect diff --git a/go.sum b/go.sum index c69c10a..1127125 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,6 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -git.badhouseplants.net/softplayer/softplayer-go-proto v0.1.11 h1:Kjdz7HUOhg5f8wktvf+QG6SNv0sN3OXfz9yErwrfl38= -git.badhouseplants.net/softplayer/softplayer-go-proto v0.1.11/go.mod h1:OU+833cHwvecr+gsnPEKQYlAJbpL8bqSJVLobdw63qI= +git.badhouseplants.net/softplayer/softplayer-go-proto v0.1.12 h1:aaMAZ0Pw+4QF3+azngsGNgKxLCRjrFFRngNfh8ucL6o= +git.badhouseplants.net/softplayer/softplayer-go-proto v0.1.12/go.mod h1:OU+833cHwvecr+gsnPEKQYlAJbpL8bqSJVLobdw63qI= github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 h1:bvDV9vkmnHYOMsOr4WLk+Vo07yKIzd94sVoIqshQ4bU= github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8= github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= diff --git a/internal/controllers/environments.go b/internal/controllers/environments.go index 7a7c25d..54ec429 100644 --- a/internal/controllers/environments.go +++ b/internal/controllers/environments.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "strconv" "strings" "github.com/go-logr/logr" @@ -392,6 +393,16 @@ func (env *Environemnt) Get(ctx context.Context) error { } else { env.Data.Location = "" } + if val, ok := res["SP_DISK_SIZE"]; ok { + intVal, err := strconv.Atoi(val) + if err != nil { + log.Error(err, "Couldn't parse disk size") + intVal = 0 + } + env.Data.DiskSize = intVal + } else { + env.Data.Location = "" + } return nil }