From bfd486568ae4114082c25079709375f244391b5b Mon Sep 17 00:00:00 2001 From: Nikolai Rodionov Date: Mon, 6 May 2024 21:11:44 +0200 Subject: [PATCH] Use config instead of controller --- api/v1/environments.go | 17 +++++++++++++++++ internal/controllers/environments.go | 1 + 2 files changed, 18 insertions(+) diff --git a/api/v1/environments.go b/api/v1/environments.go index d98dfd4..c908b71 100644 --- a/api/v1/environments.go +++ b/api/v1/environments.go @@ -62,6 +62,7 @@ func (e *EnvironmentsServer) Create(ctx context.Context, in *proto.CreateOptions environment := &controllers.Environemnt{ UserID: in.GetOwnerId().GetUuid(), + Config: ctrl.GetConfigOrDie(), Controller: e.controller, Data: data, Token: in.GetToken().GetToken(), @@ -81,6 +82,10 @@ func (e *EnvironmentsServer) Create(ctx context.Context, in *proto.CreateOptions } func (e *EnvironmentsServer) Update(ctx context.Context, in *proto.UpdateOptions) (*proto.EnvironmentFull, error) { + log := e.logInstance + log.WithValues("user_id", in.GetOwnerId().GetUuid()) + ctx = logr.NewContext(ctx, log) + provider, err := infra.GetProvider(in.GetSpec().GetProvider().String()) if err != nil { return nil, err @@ -112,6 +117,7 @@ func (e *EnvironmentsServer) Update(ctx context.Context, in *proto.UpdateOptions } environment := &controllers.Environemnt{ + Config: ctrl.GetConfigOrDie(), UserID: in.GetOwnerId().GetUuid(), Controller: e.controller, Data: data, @@ -132,12 +138,17 @@ func (e *EnvironmentsServer) Update(ctx context.Context, in *proto.UpdateOptions } func (e *EnvironmentsServer) Delete(ctx context.Context, in *proto.DeleteOptions) (*empty.Empty, error) { + log := e.logInstance + log.WithValues("user_id", in.GetOwnerId().GetUuid()) + ctx = logr.NewContext(ctx, log) + data := &controllers.EnvironemntData{ Name: in.GetMetadata().GetName(), UUID: in.GetId().GetUuid(), } environment := &controllers.Environemnt{ + Config: ctrl.GetConfigOrDie(), UserID: in.GetOwnerId().GetUuid(), Controller: e.controller, Data: data, @@ -151,11 +162,16 @@ func (e *EnvironmentsServer) Delete(ctx context.Context, in *proto.DeleteOptions } func (e *EnvironmentsServer) Get(ctx context.Context, in *proto.GetOptions) (*proto.EnvironmentFull, error) { + log := e.logInstance + log.WithValues("user_id", in.GetOwnerId().GetUuid()) + ctx = logr.NewContext(ctx, log) + data := &controllers.EnvironemntData{ UUID: in.GetId().GetUuid(), } environment := &controllers.Environemnt{ + Config: ctrl.GetConfigOrDie(), UserID: in.GetOwnerId().GetUuid(), Controller: e.controller, Data: data, @@ -197,6 +213,7 @@ func (e *EnvironmentsServer) List(in *proto.ListOptions, stream proto.Environmen ctx := logr.NewContext(stream.Context(), log) environment := &controllers.Environemnt{ + Config: ctrl.GetConfigOrDie(), UserID: in.GetOwnerId().GetUuid(), Controller: e.controller, Token: in.GetToken().GetToken(), diff --git a/internal/controllers/environments.go b/internal/controllers/environments.go index fb8bed4..7a7c25d 100644 --- a/internal/controllers/environments.go +++ b/internal/controllers/environments.go @@ -43,6 +43,7 @@ type EnvironemntData struct { } func (e *EnvironemntData) buildVars() (string, error) { + // Please make sure that the same variables are used by ansible vars := fmt.Sprintf(`# -- Generated by the softplayer controller SP_PROVIDER=%s SP_KUBERNETES=%s