Fix scale set param

Do not look for a name when composing the scale set. Preload may not
have been called on an entity, but we still have the ID, which is the
only thing needed when GetEntity() is called.

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
Gabriel Adrian Samfira 2025-07-17 16:39:55 +00:00
parent c95252547e
commit 69779a0a7d
7 changed files with 21 additions and 12 deletions

View file

@ -389,7 +389,7 @@ func (s *sqlDatabase) SetScaleSetLastMessageID(_ context.Context, scaleSetID uin
}
}()
if err := s.conn.Transaction(func(tx *gorm.DB) error {
dbSet, err := s.getScaleSetByID(tx, scaleSetID)
dbSet, err := s.getScaleSetByID(tx, scaleSetID, "Instances", "Enterprise", "Organization", "Repository")
if err != nil {
return errors.Wrap(err, "fetching scale set")
}
@ -416,7 +416,7 @@ func (s *sqlDatabase) SetScaleSetDesiredRunnerCount(_ context.Context, scaleSetI
}
}()
if err := s.conn.Transaction(func(tx *gorm.DB) error {
dbSet, err := s.getScaleSetByID(tx, scaleSetID)
dbSet, err := s.getScaleSetByID(tx, scaleSetID, "Instances", "Enterprise", "Organization", "Repository")
if err != nil {
return errors.Wrap(err, "fetching scale set")
}

View file

@ -362,12 +362,12 @@ func (s *sqlDatabase) sqlToCommonScaleSet(scaleSet ScaleSet) (params.ScaleSet, e
}
}
if scaleSet.OrgID != nil && scaleSet.Organization.Name != "" {
if scaleSet.OrgID != nil {
ret.OrgID = scaleSet.OrgID.String()
ret.OrgName = scaleSet.Organization.Name
}
if scaleSet.EnterpriseID != nil && scaleSet.Enterprise.Name != "" {
if scaleSet.EnterpriseID != nil {
ret.EnterpriseID = scaleSet.EnterpriseID.String()
ret.EnterpriseName = scaleSet.Enterprise.Name
}

View file

@ -570,7 +570,7 @@ func (p ScaleSet) GetEntity() (ForgeEntity, error) {
EntityType: ForgeEntityTypeEnterprise,
}, nil
}
return ForgeEntity{}, fmt.Errorf("pool has no associated entity")
return ForgeEntity{}, fmt.Errorf("scale set has no associated entity")
}
func (p *ScaleSet) ScaleSetType() ForgeEntityType {

View file

@ -68,7 +68,12 @@ const (
)
func NewEntityPoolManager(ctx context.Context, entity params.ForgeEntity, instanceTokenGetter auth.InstanceTokenGetter, providers map[string]common.Provider, store dbCommon.Store) (common.PoolManager, error) {
ctx = garmUtil.WithSlogContext(ctx, slog.Any("pool_mgr", entity.String()), slog.Any("pool_type", entity.EntityType))
ctx = garmUtil.WithSlogContext(
ctx,
slog.Any("pool_mgr", entity.String()),
slog.Any("endpoint", entity.Credentials.Endpoint.Name),
slog.Any("pool_type", entity.EntityType),
)
ghc, err := ghClient.Client(ctx, entity)
if err != nil {
return nil, errors.Wrap(err, "getting github client")

View file

@ -365,7 +365,7 @@ func (w *Worker) handleScaleSetEvent(event common.ChangePayload) {
}
entity, err := scaleSet.GetEntity()
if err != nil {
slog.DebugContext(w.ctx, "getting entity from pool", "error", err)
slog.DebugContext(w.ctx, "getting entity from scale set", "error", err)
return
}

View file

@ -15,9 +15,11 @@
package cache
import (
"context"
"encoding/json"
"fmt"
"io"
"log/slog"
"net/http"
"strings"
"time"
@ -139,7 +141,7 @@ func (g GiteaEntityTools) MinimumVersion() (GiteaEntityTool, bool) {
return GiteaEntityTool{}, false
}
func getTools() ([]commonParams.RunnerApplicationDownload, error) {
func getTools(ctx context.Context) ([]commonParams.RunnerApplicationDownload, error) {
resp, err := http.Get(GiteaRunnerReleasesURL)
if err != nil {
return nil, err
@ -170,11 +172,13 @@ func getTools() ([]commonParams.RunnerApplicationDownload, error) {
for _, asset := range latest.Assets {
arch, err := asset.GetArch()
if err != nil {
return nil, fmt.Errorf("getting arch: %w", err)
slog.InfoContext(ctx, "ignoring unrecognized tools arch", "tool", asset.Name)
continue
}
os, err := asset.GetOS()
if err != nil {
return nil, fmt.Errorf("getting os: %w", err)
slog.InfoContext(ctx, "ignoring unrecognized tools os", "tool", asset.Name)
continue
}
ret = append(ret, commonParams.RunnerApplicationDownload{
OS: os,

View file

@ -162,7 +162,7 @@ func (t *toolsUpdater) giteaUpdateLoop() {
randInt = big.NewInt(0)
}
t.sleepWithCancel(time.Duration(randInt.Int64()) * time.Millisecond)
tools, err := getTools()
tools, err := getTools(t.ctx)
if err != nil {
t.addStatusEvent(fmt.Sprintf("failed to update gitea tools: %q", err), params.EventError)
} else {
@ -181,7 +181,7 @@ func (t *toolsUpdater) giteaUpdateLoop() {
case <-t.ctx.Done():
return
case <-ticker.C:
tools, err := getTools()
tools, err := getTools(t.ctx)
if err != nil {
t.addStatusEvent(fmt.Sprintf("failed to update gitea tools: %q", err), params.EventError)
slog.DebugContext(t.ctx, "failed to update gitea tools", "error", err)