Handle scale up and down; add provider worker
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
parent
7376a5fe74
commit
020210d6ad
14 changed files with 372 additions and 39 deletions
|
|
@ -30,7 +30,7 @@ type scaleSetJitRunnerConfig struct {
|
|||
WorkFolder string `json:"workFolder"`
|
||||
}
|
||||
|
||||
func (s *ScaleSetClient) GenerateJitRunnerConfig(ctx context.Context, runnerName string, scaleSet params.RunnerScaleSet) (params.RunnerScaleSetJitRunnerConfig, error) {
|
||||
func (s *ScaleSetClient) GenerateJitRunnerConfig(ctx context.Context, runnerName string, scaleSetID int) (params.RunnerScaleSetJitRunnerConfig, error) {
|
||||
runnerSettings := scaleSetJitRunnerConfig{
|
||||
Name: runnerName,
|
||||
WorkFolder: "_work",
|
||||
|
|
@ -41,7 +41,14 @@ func (s *ScaleSetClient) GenerateJitRunnerConfig(ctx context.Context, runnerName
|
|||
return params.RunnerScaleSetJitRunnerConfig{}, err
|
||||
}
|
||||
|
||||
req, err := s.newActionsRequest(ctx, http.MethodPost, scaleSet.RunnerJitConfigURL, bytes.NewBuffer(body))
|
||||
serviceUrl, err := s.actionsServiceInfo.GetURL()
|
||||
if err != nil {
|
||||
return params.RunnerScaleSetJitRunnerConfig{}, fmt.Errorf("failed to get pipeline URL: %w", err)
|
||||
}
|
||||
jitConfigPath := fmt.Sprintf("/%s/%d/generatejitconfig", scaleSetEndpoint, scaleSetID)
|
||||
jitConfigURL := serviceUrl.JoinPath(jitConfigPath)
|
||||
|
||||
req, err := s.newActionsRequest(ctx, http.MethodPost, jitConfigURL.String(), bytes.NewBuffer(body))
|
||||
if err != nil {
|
||||
return params.RunnerScaleSetJitRunnerConfig{}, fmt.Errorf("failed to create request: %w", err)
|
||||
}
|
||||
|
|
@ -81,6 +88,26 @@ func (s *ScaleSetClient) GetRunner(ctx context.Context, runnerID int64) (params.
|
|||
return runnerReference, nil
|
||||
}
|
||||
|
||||
func (s *ScaleSetClient) ListAllRunners(ctx context.Context) (params.RunnerReferenceList, error) {
|
||||
req, err := s.newActionsRequest(ctx, http.MethodGet, runnerEndpoint, nil)
|
||||
if err != nil {
|
||||
return params.RunnerReferenceList{}, fmt.Errorf("failed to construct request: %w", err)
|
||||
}
|
||||
|
||||
resp, err := s.Do(req)
|
||||
if err != nil {
|
||||
return params.RunnerReferenceList{}, fmt.Errorf("request failed for %s: %w", req.URL.String(), err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
var runnerList params.RunnerReferenceList
|
||||
if err := json.NewDecoder(resp.Body).Decode(&runnerList); err != nil {
|
||||
return params.RunnerReferenceList{}, fmt.Errorf("failed to decode response: %w", err)
|
||||
}
|
||||
|
||||
return runnerList, nil
|
||||
}
|
||||
|
||||
func (s *ScaleSetClient) GetRunnerByName(ctx context.Context, runnerName string) (params.RunnerReference, error) {
|
||||
path := fmt.Sprintf("%s?agentName=%s", runnerEndpoint, runnerName)
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
|
|
@ -50,5 +51,7 @@ func (s *ScaleSetClient) newActionsRequest(ctx context.Context, method, path str
|
|||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", s.actionsServiceInfo.Token))
|
||||
|
||||
slog.DebugContext(ctx, "newActionsRequest", "method", method, "url", uri.String(), "body", body, "headers", req.Header)
|
||||
|
||||
return req, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue