diff --git a/database/common/store.go b/database/common/store.go index 2ac55a4b..b7222d1c 100644 --- a/database/common/store.go +++ b/database/common/store.go @@ -143,6 +143,7 @@ type ScaleSetsStore interface { GetScaleSetByID(ctx context.Context, scaleSet uint) (params.ScaleSet, error) DeleteScaleSetByID(ctx context.Context, scaleSetID uint) (err error) SetScaleSetLastMessageID(ctx context.Context, scaleSetID uint, lastMessageID int64) error + SetScaleSetDesiredRunnerCount(ctx context.Context, scaleSetID uint, desiredRunnerCount int64) error } type ScaleSetInstanceStore interface { diff --git a/database/sql/models.go b/database/sql/models.go index 5b4d86f9..ce156ccd 100644 --- a/database/sql/models.go +++ b/database/sql/models.go @@ -119,6 +119,7 @@ type ScaleSet struct { OSArch commonParams.OSArch Enabled bool LastMessageID int64 + DesiredRunnerCount int64 // ExtraSpecs is an opaque json that gets sent to the provider // as part of the bootstrap params for instances. It can contain // any kind of data needed by providers. diff --git a/database/sql/scalesets.go b/database/sql/scalesets.go index 7a67f2d6..03c34800 100644 --- a/database/sql/scalesets.go +++ b/database/sql/scalesets.go @@ -391,3 +391,15 @@ func (s *sqlDatabase) SetScaleSetLastMessageID(ctx context.Context, scaleSetID u } return nil } + +func (s *sqlDatabase) SetScaleSetDesiredRunnerCount(ctx context.Context, scaleSetID uint, desiredRunnerCount int64) error { + if err := s.conn.Transaction(func(tx *gorm.DB) error { + if q := tx.Model(&ScaleSet{}).Where("id = ?", scaleSetID).Update("desired_runner_count", desiredRunnerCount); q.Error != nil { + return errors.Wrap(q.Error, "saving database entry") + } + return nil + }); err != nil { + return errors.Wrap(err, "setting desired runner count") + } + return nil +} diff --git a/database/sql/util.go b/database/sql/util.go index c7b64961..dda3e9cf 100644 --- a/database/sql/util.go +++ b/database/sql/util.go @@ -310,6 +310,7 @@ func (s *sqlDatabase) sqlToCommonScaleSet(scaleSet ScaleSet) (params.ScaleSet, e State: scaleSet.State, ExtendedState: scaleSet.ExtendedState, LastMessageID: scaleSet.LastMessageID, + DesiredRunnerCount: scaleSet.DesiredRunnerCount, } if scaleSet.RepoID != nil { diff --git a/go.mod b/go.mod index 79a09894..bd2a0c86 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ toolchain go1.23.6 require ( github.com/BurntSushi/toml v1.5.0 github.com/bradleyfalzon/ghinstallation/v2 v2.15.0 - github.com/cloudbase/garm-provider-common v0.1.4 + github.com/cloudbase/garm-provider-common v0.1.5-0.20250417155201-8ef03502d06e github.com/felixge/httpsnoop v1.0.4 github.com/go-openapi/errors v0.22.1 github.com/go-openapi/runtime v0.28.0 diff --git a/go.sum b/go.sum index e14f0c22..1deb1931 100644 --- a/go.sum +++ b/go.sum @@ -19,8 +19,8 @@ github.com/chzyer/readline v1.5.1/go.mod h1:Eh+b79XXUwfKfcPLepksvw2tcLE/Ct21YObk github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/chzyer/test v1.0.0 h1:p3BQDXSxOhOG0P9z6/hGnII4LGiEPOYBhs8asl/fC04= github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8= -github.com/cloudbase/garm-provider-common v0.1.4 h1:spRjl0PV4r8vKaCTNp6xBQbRKfls/cmbBEl/i/eGWSo= -github.com/cloudbase/garm-provider-common v0.1.4/go.mod h1:sK26i2NpjjAjhanNKiWw8iPkqt+XeohTKpFnEP7JdZ4= +github.com/cloudbase/garm-provider-common v0.1.5-0.20250417155201-8ef03502d06e h1:giq2Prk9I/ez1dc4/r9jivf2jbhjX9apZ41TWQ5g3qE= +github.com/cloudbase/garm-provider-common v0.1.5-0.20250417155201-8ef03502d06e/go.mod h1:sSrTBtTc0q72MZdmS9EuLLdDhkmXZAqAwRIgEK0TqUo= github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= diff --git a/params/params.go b/params/params.go index 5f7cf60a..8f63fecb 100644 --- a/params/params.go +++ b/params/params.go @@ -453,15 +453,16 @@ type ScaleSet struct { State ScaleSetState `json:"state"` ExtendedState string `json:"extended_state,omitempty"` - ProviderName string `json:"provider_name,omitempty"` - MaxRunners uint `json:"max_runners,omitempty"` - MinIdleRunners uint `json:"min_idle_runners,omitempty"` - Image string `json:"image,omitempty"` - Flavor string `json:"flavor,omitempty"` - OSType commonParams.OSType `json:"os_type,omitempty"` - OSArch commonParams.OSArch `json:"os_arch,omitempty"` - Enabled bool `json:"enabled,omitempty"` - Instances []Instance `json:"instances,omitempty"` + ProviderName string `json:"provider_name,omitempty"` + MaxRunners uint `json:"max_runners,omitempty"` + MinIdleRunners uint `json:"min_idle_runners,omitempty"` + Image string `json:"image,omitempty"` + Flavor string `json:"flavor,omitempty"` + OSType commonParams.OSType `json:"os_type,omitempty"` + OSArch commonParams.OSArch `json:"os_arch,omitempty"` + Enabled bool `json:"enabled,omitempty"` + Instances []Instance `json:"instances,omitempty"` + DesiredRunnerCount int64 `json:"desired_runner_count,omitempty"` RunnerBootstrapTimeout uint `json:"runner_bootstrap_timeout,omitempty"` // ExtraSpecs is an opaque raw json that gets sent to the provider diff --git a/vendor/github.com/cloudbase/garm-provider-common/params/params.go b/vendor/github.com/cloudbase/garm-provider-common/params/params.go index 95a6e6bb..0a63f709 100644 --- a/vendor/github.com/cloudbase/garm-provider-common/params/params.go +++ b/vendor/github.com/cloudbase/garm-provider-common/params/params.go @@ -45,6 +45,7 @@ const ( InstancePendingDelete InstanceStatus = "pending_delete" InstancePendingForceDelete InstanceStatus = "pending_force_delete" InstanceDeleting InstanceStatus = "deleting" + InstanceDeleted InstanceStatus = "deleted" InstancePendingCreate InstanceStatus = "pending_create" InstanceCreating InstanceStatus = "creating" InstanceStatusUnknown InstanceStatus = "unknown" diff --git a/vendor/modules.txt b/vendor/modules.txt index a9d04a3c..c19620d9 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -21,8 +21,8 @@ github.com/cespare/xxhash/v2 # github.com/chzyer/readline v1.5.1 ## explicit; go 1.15 github.com/chzyer/readline -# github.com/cloudbase/garm-provider-common v0.1.4 -## explicit; go 1.22 +# github.com/cloudbase/garm-provider-common v0.1.5-0.20250417155201-8ef03502d06e +## explicit; go 1.23.0 github.com/cloudbase/garm-provider-common/defaults github.com/cloudbase/garm-provider-common/errors github.com/cloudbase/garm-provider-common/execution/common diff --git a/workers/scaleset/scaleset.go b/workers/scaleset/scaleset.go index f2fc36af..e6db9d57 100644 --- a/workers/scaleset/scaleset.go +++ b/workers/scaleset/scaleset.go @@ -154,6 +154,7 @@ func (w *Worker) handleEvent(event dbCommon.ChangePayload) { slog.ErrorContext(w.ctx, "error stopping listener", "error", err) } } + // TODO: should we kick off auto-scaling if desired runner count changes? w.scaleSet = scaleSet w.mux.Unlock() default: