Skip to content

Commit

Permalink
🐛 Fix Nomad provider
Browse files Browse the repository at this point in the history
  • Loading branch information
kasefuchs committed Nov 7, 2024
1 parent 873fbb3 commit d19e6b0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 28 deletions.
4 changes: 2 additions & 2 deletions pkg/plugin/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ type providerSelector func() (provider.Provider, error)
// queuesSelector represents function used to select queues to use.
type queuesSelector func() ([]queue.Queue, error)

// configLoader represents function used to load pconfig configuration.
// configLoader represents function used to load plugin configuration.
type configLoader func() (*pconfig.Config, error)

// Options contains customizable pconfig options.
// Options contains customizable plugin options.
type Options struct {
ProviderSelector providerSelector // Selector of provider.
QueuesSelector queuesSelector // Selector of available queues.
Expand Down
47 changes: 21 additions & 26 deletions pkg/provider/nomad/allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,24 @@ func NewAllocation(client *api.Client, item *item) *Allocation {
}
}

func (a *Allocation) scale(count *int64) error {
func (a *Allocation) taskGroup() (*api.TaskGroup, error) {
job, _, err := a.client.Jobs().Info(*a.item.job.ID, nil)
if err != nil {
return err
return nil, err
}

group := job.LookupTaskGroup(*a.item.group.Name)
if group == nil {
return fmt.Errorf("task group %s not found", *a.item.group.Name)
return nil, fmt.Errorf("task group %s not found", *a.item.group.Name)
}

return group, nil
}

func (a *Allocation) scale(count *int64) error {
group, err := a.taskGroup()
if err != nil {
return err
}

if int64(*group.Count) != *count {
Expand Down Expand Up @@ -66,45 +75,31 @@ func (a *Allocation) Start() error {
}

func (a *Allocation) State() provider.AllocationState {
info, _, err := a.client.Jobs().Info(*a.item.job.ID, nil)
group, err := a.taskGroup()
if err != nil {
return provider.AllocationStateUnknown
}

for _, group := range info.TaskGroups {
if group.Name != a.item.group.Name {
continue
}

if *group.Count == 0 {
return provider.AllocationStateStopped
}

return provider.AllocationStateStarted
if *group.Count == 0 {
return provider.AllocationStateStopped
}

return provider.AllocationStateUnknown
return provider.AllocationStateStarted
}

func (a *Allocation) Config() (*allocation.Config, error) {
info, _, err := a.client.Jobs().Info(*a.item.job.ID, nil)
group, err := a.taskGroup()
if err != nil {
return nil, err
}

for _, group := range info.TaskGroups {
if group.Name != a.item.group.Name {
for _, service := range group.Services {
cfg, err := allocation.ParseTags(service.Tags)
if err != nil {
continue
}

for _, service := range group.Services {
cfg, err := allocation.ParseTags(service.Tags)
if err != nil {
continue
}

return cfg, nil
}
return cfg, nil
}

return nil, fmt.Errorf("no allocation configuration found")
Expand Down

0 comments on commit d19e6b0

Please sign in to comment.