From eccb57fffe9372e462d5c703007a30a95c5d294d Mon Sep 17 00:00:00 2001 From: Ansuman Satapathy Date: Fri, 16 Aug 2024 12:02:43 +0000 Subject: [PATCH] fix: [CDE-192]: correctly set resources for infraprovider config. (#2524) * fix: [CDE-192]: correctly set resources for infraprovider config. --- app/api/controller/gitspace/action.go | 4 ++-- app/services/gitspaceinfraevent/handler.go | 1 - app/services/infraprovider/infraprovider.go | 12 +++++++----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/api/controller/gitspace/action.go b/app/api/controller/gitspace/action.go index 209bcf1f50..dd88b60cf8 100644 --- a/app/api/controller/gitspace/action.go +++ b/app/api/controller/gitspace/action.go @@ -114,7 +114,7 @@ func (c *Controller) startGitspaceAction( return err } if savedGitspaceInstance == nil || savedGitspaceInstance.State.IsFinalStatus() { - gitspaceInstance, err := c.createGitspaceInstance(config) + gitspaceInstance, err := c.buildGitspaceInstance(config) if err != nil { return err } @@ -208,7 +208,7 @@ func (c *Controller) submitAsyncOps( }() } -func (c *Controller) createGitspaceInstance(config *types.GitspaceConfig) (*types.GitspaceInstance, error) { +func (c *Controller) buildGitspaceInstance(config *types.GitspaceConfig) (*types.GitspaceInstance, error) { gitspaceMachineUser := defaultMachineUser now := time.Now().UnixMilli() suffixUID, err := gonanoid.Generate(allowedUIDAlphabet, 6) diff --git a/app/services/gitspaceinfraevent/handler.go b/app/services/gitspaceinfraevent/handler.go index 202d6fdd88..b1d92a43f9 100644 --- a/app/services/gitspaceinfraevent/handler.go +++ b/app/services/gitspaceinfraevent/handler.go @@ -78,7 +78,6 @@ func (s *Service) handleGitspaceInfraEvent( default: return fmt.Errorf("unknown event type: %s", event.Payload.Type) } - instance.Updated = time.Now().UnixMilli() err = s.gitspaceSvc.UpdateInstance(ctx, instance) if err != nil { return fmt.Errorf("failed to update gitspace instance: %w", err) diff --git a/app/services/infraprovider/infraprovider.go b/app/services/infraprovider/infraprovider.go index 69d97d9b69..ea43b5b7c8 100644 --- a/app/services/infraprovider/infraprovider.go +++ b/app/services/infraprovider/infraprovider.go @@ -66,13 +66,15 @@ func (c *Service) Find( infraProviderConfig.Identifier, err) } infraProviderConfig.SpacePath = space.Path - values := make([]types.InfraProviderResource, len(infraProviderConfig.Resources)) - for i, ptr := range resources { - if ptr != nil { - values[i] = *ptr + if len(resources) > 0 { + providerResources := make([]types.InfraProviderResource, len(resources)) + for i, resource := range resources { + if resource != nil { + providerResources[i] = *resource + } } + infraProviderConfig.Resources = providerResources } - infraProviderConfig.Resources = values return infraProviderConfig, nil }