diff --git a/apiserver/controllers/controllers.go b/apiserver/controllers/controllers.go index 7c33695e..fce100a6 100644 --- a/apiserver/controllers/controllers.go +++ b/apiserver/controllers/controllers.go @@ -22,6 +22,10 @@ import ( "net/http" "strings" + "github.com/gorilla/mux" + "github.com/gorilla/websocket" + "github.com/pkg/errors" + gErrors "github.com/cloudbase/garm-provider-common/errors" "github.com/cloudbase/garm-provider-common/util" "github.com/cloudbase/garm/apiserver/params" @@ -30,10 +34,6 @@ import ( runnerParams "github.com/cloudbase/garm/params" "github.com/cloudbase/garm/runner" wsWriter "github.com/cloudbase/garm/websocket" - - "github.com/gorilla/mux" - "github.com/gorilla/websocket" - "github.com/pkg/errors" ) func NewAPIController(r *runner.Runner, authenticator *auth.Authenticator, hub *wsWriter.Hub) (*APIController, error) { diff --git a/apiserver/controllers/enterprises.go b/apiserver/controllers/enterprises.go index 39abb223..d4b20826 100644 --- a/apiserver/controllers/enterprises.go +++ b/apiserver/controllers/enterprises.go @@ -19,11 +19,11 @@ import ( "log/slog" "net/http" + "github.com/gorilla/mux" + gErrors "github.com/cloudbase/garm-provider-common/errors" "github.com/cloudbase/garm/apiserver/params" runnerParams "github.com/cloudbase/garm/params" - - "github.com/gorilla/mux" ) // swagger:route POST /enterprises enterprises CreateEnterprise @@ -165,7 +165,6 @@ func (a *APIController) DeleteEnterpriseHandler(w http.ResponseWriter, r *http.R w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) - } // swagger:route PUT /enterprises/{enterpriseID} enterprises UpdateEnterprise @@ -318,7 +317,6 @@ func (a *APIController) ListEnterprisePoolsHandler(w http.ResponseWriter, r *htt if err := json.NewEncoder(w).Encode(pools); err != nil { slog.With(slog.Any("error", err)).ErrorContext(ctx, "failed to encode response") } - } // swagger:route GET /enterprises/{enterpriseID}/pools/{poolID} enterprises pools GetEnterprisePool @@ -414,7 +412,6 @@ func (a *APIController) DeleteEnterprisePoolHandler(w http.ResponseWriter, r *ht w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) - } // swagger:route PUT /enterprises/{enterpriseID}/pools/{poolID} enterprises pools UpdateEnterprisePool diff --git a/apiserver/controllers/instances.go b/apiserver/controllers/instances.go index 6cf43dd9..b5504f76 100644 --- a/apiserver/controllers/instances.go +++ b/apiserver/controllers/instances.go @@ -20,11 +20,11 @@ import ( "net/http" "strconv" + "github.com/gorilla/mux" + gErrors "github.com/cloudbase/garm-provider-common/errors" "github.com/cloudbase/garm/apiserver/params" runnerParams "github.com/cloudbase/garm/params" - - "github.com/gorilla/mux" ) // swagger:route GET /pools/{poolID}/instances instances ListPoolInstances diff --git a/apiserver/controllers/metadata.go b/apiserver/controllers/metadata.go index 1b7e215d..4b112b17 100644 --- a/apiserver/controllers/metadata.go +++ b/apiserver/controllers/metadata.go @@ -20,8 +20,9 @@ import ( "log/slog" "net/http" - "github.com/cloudbase/garm/apiserver/params" "github.com/gorilla/mux" + + "github.com/cloudbase/garm/apiserver/params" ) func (a *APIController) InstanceGithubRegistrationTokenHandler(w http.ResponseWriter, r *http.Request) { diff --git a/apiserver/controllers/organizations.go b/apiserver/controllers/organizations.go index 8495d351..ca2ef3b5 100644 --- a/apiserver/controllers/organizations.go +++ b/apiserver/controllers/organizations.go @@ -20,11 +20,11 @@ import ( "net/http" "strconv" + "github.com/gorilla/mux" + gErrors "github.com/cloudbase/garm-provider-common/errors" "github.com/cloudbase/garm/apiserver/params" runnerParams "github.com/cloudbase/garm/params" - - "github.com/gorilla/mux" ) // swagger:route POST /organizations organizations CreateOrg @@ -174,7 +174,6 @@ func (a *APIController) DeleteOrgHandler(w http.ResponseWriter, r *http.Request) w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) - } // swagger:route PUT /organizations/{orgID} organizations UpdateOrg @@ -423,7 +422,6 @@ func (a *APIController) DeleteOrgPoolHandler(w http.ResponseWriter, r *http.Requ w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) - } // swagger:route PUT /organizations/{orgID}/pools/{poolID} organizations pools UpdateOrgPool diff --git a/apiserver/controllers/pools.go b/apiserver/controllers/pools.go index 3f7a81b1..901be588 100644 --- a/apiserver/controllers/pools.go +++ b/apiserver/controllers/pools.go @@ -19,11 +19,11 @@ import ( "log/slog" "net/http" + "github.com/gorilla/mux" + gErrors "github.com/cloudbase/garm-provider-common/errors" "github.com/cloudbase/garm/apiserver/params" runnerParams "github.com/cloudbase/garm/params" - - "github.com/gorilla/mux" ) // swagger:route GET /pools pools ListPools @@ -37,7 +37,6 @@ func (a *APIController) ListAllPoolsHandler(w http.ResponseWriter, r *http.Reque ctx := r.Context() pools, err := a.r.ListAllPools(ctx) - if err != nil { slog.With(slog.Any("error", err)).ErrorContext(ctx, "listing pools") handleError(ctx, w, err) diff --git a/apiserver/controllers/repositories.go b/apiserver/controllers/repositories.go index 6831dda4..7cc3c4f5 100644 --- a/apiserver/controllers/repositories.go +++ b/apiserver/controllers/repositories.go @@ -20,11 +20,11 @@ import ( "net/http" "strconv" + "github.com/gorilla/mux" + gErrors "github.com/cloudbase/garm-provider-common/errors" "github.com/cloudbase/garm/apiserver/params" runnerParams "github.com/cloudbase/garm/params" - - "github.com/gorilla/mux" ) // swagger:route POST /repositories repositories CreateRepo @@ -173,7 +173,6 @@ func (a *APIController) DeleteRepoHandler(w http.ResponseWriter, r *http.Request w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) - } // swagger:route PUT /repositories/{repoID} repositories UpdateRepo @@ -422,7 +421,6 @@ func (a *APIController) DeleteRepoPoolHandler(w http.ResponseWriter, r *http.Req w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) - } // swagger:route PUT /repositories/{repoID}/pools/{poolID} repositories pools UpdateRepoPool diff --git a/apiserver/routers/routers.go b/apiserver/routers/routers.go index 5e6de6cd..88ba445d 100644 --- a/apiserver/routers/routers.go +++ b/apiserver/routers/routers.go @@ -87,7 +87,7 @@ func requestLogger(h http.Handler) http.Handler { // gathers metrics from the upstream handlers metrics := httpsnoop.CaptureMetrics(h, w, r) - //prints log and metrics + slog.Info( "access_log", slog.String("method", r.Method), diff --git a/auth/auth.go b/auth/auth.go index 5bf882c9..6b782bee 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -18,16 +18,16 @@ import ( "context" "time" + jwt "github.com/golang-jwt/jwt/v5" + "github.com/nbutton23/zxcvbn-go" + "github.com/pkg/errors" + "golang.org/x/crypto/bcrypt" + runnerErrors "github.com/cloudbase/garm-provider-common/errors" "github.com/cloudbase/garm-provider-common/util" "github.com/cloudbase/garm/config" "github.com/cloudbase/garm/database/common" "github.com/cloudbase/garm/params" - - jwt "github.com/golang-jwt/jwt/v5" - "github.com/nbutton23/zxcvbn-go" - "github.com/pkg/errors" - "golang.org/x/crypto/bcrypt" ) func NewAuthenticator(cfg config.JWTAuth, store common.Store) *Authenticator { diff --git a/auth/instance_middleware.go b/auth/instance_middleware.go index 1562b8b9..7d5528fe 100644 --- a/auth/instance_middleware.go +++ b/auth/instance_middleware.go @@ -22,15 +22,15 @@ import ( "strings" "time" + jwt "github.com/golang-jwt/jwt/v5" + "github.com/pkg/errors" + + runnerErrors "github.com/cloudbase/garm-provider-common/errors" + commonParams "github.com/cloudbase/garm-provider-common/params" "github.com/cloudbase/garm/config" dbCommon "github.com/cloudbase/garm/database/common" "github.com/cloudbase/garm/params" "github.com/cloudbase/garm/runner/common" - - runnerErrors "github.com/cloudbase/garm-provider-common/errors" - commonParams "github.com/cloudbase/garm-provider-common/params" - jwt "github.com/golang-jwt/jwt/v5" - "github.com/pkg/errors" ) // InstanceJWTClaims holds JWT claims @@ -132,7 +132,6 @@ func (amw *instanceMiddleware) Middleware(next http.Handler) http.Handler { } return []byte(amw.cfg.Secret), nil }) - if err != nil { invalidAuthResponse(ctx, w) return diff --git a/auth/jwt.go b/auth/jwt.go index 8516a02f..15909d75 100644 --- a/auth/jwt.go +++ b/auth/jwt.go @@ -22,12 +22,12 @@ import ( "net/http" "strings" + jwt "github.com/golang-jwt/jwt/v5" + runnerErrors "github.com/cloudbase/garm-provider-common/errors" apiParams "github.com/cloudbase/garm/apiserver/params" "github.com/cloudbase/garm/config" dbCommon "github.com/cloudbase/garm/database/common" - - jwt "github.com/golang-jwt/jwt/v5" ) // JWTClaims holds JWT claims @@ -108,7 +108,6 @@ func (amw *jwtMiddleware) Middleware(next http.Handler) http.Handler { } return []byte(amw.cfg.Secret), nil }) - if err != nil { invalidAuthResponse(ctx, w) return diff --git a/auth/metrics.go b/auth/metrics.go index 1543d56c..55cede44 100644 --- a/auth/metrics.go +++ b/auth/metrics.go @@ -6,9 +6,9 @@ import ( "net/http" "strings" - "github.com/cloudbase/garm/config" - jwt "github.com/golang-jwt/jwt/v5" + + "github.com/cloudbase/garm/config" ) type MetricsMiddleware struct { @@ -43,7 +43,6 @@ func (m *MetricsMiddleware) Middleware(next http.Handler) http.Handler { } return []byte(m.cfg.Secret), nil }) - if err != nil { invalidAuthResponse(ctx, w) return diff --git a/cmd/garm-cli/cmd/controller_info.go b/cmd/garm-cli/cmd/controller_info.go index 0a42ae1e..2cf818b3 100644 --- a/cmd/garm-cli/cmd/controller_info.go +++ b/cmd/garm-cli/cmd/controller_info.go @@ -17,10 +17,11 @@ package cmd import ( "fmt" - apiClientControllerInfo "github.com/cloudbase/garm/client/controller_info" - "github.com/cloudbase/garm/params" "github.com/jedib0t/go-pretty/v6/table" "github.com/spf13/cobra" + + apiClientControllerInfo "github.com/cloudbase/garm/client/controller_info" + "github.com/cloudbase/garm/params" ) var infoCmd = &cobra.Command{ diff --git a/cmd/garm-cli/cmd/credentials.go b/cmd/garm-cli/cmd/credentials.go index d8011ea9..603c6120 100644 --- a/cmd/garm-cli/cmd/credentials.go +++ b/cmd/garm-cli/cmd/credentials.go @@ -17,11 +17,11 @@ package cmd import ( "fmt" - apiClientCreds "github.com/cloudbase/garm/client/credentials" - "github.com/cloudbase/garm/params" - "github.com/jedib0t/go-pretty/v6/table" "github.com/spf13/cobra" + + apiClientCreds "github.com/cloudbase/garm/client/credentials" + "github.com/cloudbase/garm/params" ) // credentialsCmd represents the credentials command diff --git a/cmd/garm-cli/cmd/enterprise.go b/cmd/garm-cli/cmd/enterprise.go index f1eeda00..d65aab9e 100644 --- a/cmd/garm-cli/cmd/enterprise.go +++ b/cmd/garm-cli/cmd/enterprise.go @@ -17,11 +17,11 @@ package cmd import ( "fmt" - apiClientEnterprises "github.com/cloudbase/garm/client/enterprises" - "github.com/cloudbase/garm/params" - "github.com/jedib0t/go-pretty/v6/table" "github.com/spf13/cobra" + + apiClientEnterprises "github.com/cloudbase/garm/client/enterprises" + "github.com/cloudbase/garm/params" ) var ( diff --git a/cmd/garm-cli/cmd/init.go b/cmd/garm-cli/cmd/init.go index b85c5a8f..608d0e1f 100644 --- a/cmd/garm-cli/cmd/init.go +++ b/cmd/garm-cli/cmd/init.go @@ -18,15 +18,15 @@ import ( "fmt" "strings" - "github.com/cloudbase/garm/cmd/garm-cli/common" - "github.com/cloudbase/garm/cmd/garm-cli/config" - "github.com/cloudbase/garm/params" - - apiClientFirstRun "github.com/cloudbase/garm/client/first_run" - apiClientLogin "github.com/cloudbase/garm/client/login" "github.com/jedib0t/go-pretty/v6/table" "github.com/pkg/errors" "github.com/spf13/cobra" + + apiClientFirstRun "github.com/cloudbase/garm/client/first_run" + apiClientLogin "github.com/cloudbase/garm/client/login" + "github.com/cloudbase/garm/cmd/garm-cli/common" + "github.com/cloudbase/garm/cmd/garm-cli/config" + "github.com/cloudbase/garm/params" ) // initCmd represents the init command diff --git a/cmd/garm-cli/cmd/jobs.go b/cmd/garm-cli/cmd/jobs.go index 36f61e8e..0dae4b2a 100644 --- a/cmd/garm-cli/cmd/jobs.go +++ b/cmd/garm-cli/cmd/jobs.go @@ -18,11 +18,12 @@ import ( "fmt" "strings" - apiClientJobs "github.com/cloudbase/garm/client/jobs" - "github.com/cloudbase/garm/params" "github.com/google/uuid" "github.com/jedib0t/go-pretty/v6/table" "github.com/spf13/cobra" + + apiClientJobs "github.com/cloudbase/garm/client/jobs" + "github.com/cloudbase/garm/params" ) // runnerCmd represents the runner command diff --git a/cmd/garm-cli/cmd/log.go b/cmd/garm-cli/cmd/log.go index 19708afc..155127e7 100644 --- a/cmd/garm-cli/cmd/log.go +++ b/cmd/garm-cli/cmd/log.go @@ -11,11 +11,11 @@ import ( "os/signal" "time" - "github.com/cloudbase/garm-provider-common/util" - apiParams "github.com/cloudbase/garm/apiserver/params" - "github.com/gorilla/websocket" "github.com/spf13/cobra" + + "github.com/cloudbase/garm-provider-common/util" + apiParams "github.com/cloudbase/garm/apiserver/params" ) var logCmd = &cobra.Command{ diff --git a/cmd/garm-cli/cmd/metrics.go b/cmd/garm-cli/cmd/metrics.go index e79d9456..cfd48001 100644 --- a/cmd/garm-cli/cmd/metrics.go +++ b/cmd/garm-cli/cmd/metrics.go @@ -17,8 +17,9 @@ package cmd import ( "fmt" - apiClientMetricToken "github.com/cloudbase/garm/client/metrics_token" "github.com/spf13/cobra" + + apiClientMetricToken "github.com/cloudbase/garm/client/metrics_token" ) // orgPoolCmd represents the pool command diff --git a/cmd/garm-cli/cmd/organization.go b/cmd/garm-cli/cmd/organization.go index 946d8646..2873b0e5 100644 --- a/cmd/garm-cli/cmd/organization.go +++ b/cmd/garm-cli/cmd/organization.go @@ -17,12 +17,12 @@ package cmd import ( "fmt" + "github.com/jedib0t/go-pretty/v6/table" + "github.com/spf13/cobra" + "github.com/cloudbase/garm-provider-common/util" apiClientOrgs "github.com/cloudbase/garm/client/organizations" "github.com/cloudbase/garm/params" - - "github.com/jedib0t/go-pretty/v6/table" - "github.com/spf13/cobra" ) var ( diff --git a/cmd/garm-cli/cmd/pool.go b/cmd/garm-cli/cmd/pool.go index 655da267..b304b587 100644 --- a/cmd/garm-cli/cmd/pool.go +++ b/cmd/garm-cli/cmd/pool.go @@ -20,18 +20,16 @@ import ( "os" "strings" - apiClientEnterprises "github.com/cloudbase/garm/client/enterprises" - apiClientOrgs "github.com/cloudbase/garm/client/organizations" - apiClientPools "github.com/cloudbase/garm/client/pools" - apiClientRepos "github.com/cloudbase/garm/client/repositories" - - "github.com/cloudbase/garm/params" - "github.com/jedib0t/go-pretty/v6/table" "github.com/pkg/errors" "github.com/spf13/cobra" commonParams "github.com/cloudbase/garm-provider-common/params" + apiClientEnterprises "github.com/cloudbase/garm/client/enterprises" + apiClientOrgs "github.com/cloudbase/garm/client/organizations" + apiClientPools "github.com/cloudbase/garm/client/pools" + apiClientRepos "github.com/cloudbase/garm/client/repositories" + "github.com/cloudbase/garm/params" ) var ( diff --git a/cmd/garm-cli/cmd/profile.go b/cmd/garm-cli/cmd/profile.go index 71843df8..551cb4ad 100644 --- a/cmd/garm-cli/cmd/profile.go +++ b/cmd/garm-cli/cmd/profile.go @@ -18,13 +18,13 @@ import ( "fmt" "strings" + "github.com/jedib0t/go-pretty/v6/table" + "github.com/spf13/cobra" + apiClientLogin "github.com/cloudbase/garm/client/login" "github.com/cloudbase/garm/cmd/garm-cli/common" "github.com/cloudbase/garm/cmd/garm-cli/config" "github.com/cloudbase/garm/params" - - "github.com/jedib0t/go-pretty/v6/table" - "github.com/spf13/cobra" ) var ( diff --git a/cmd/garm-cli/cmd/provider.go b/cmd/garm-cli/cmd/provider.go index e9635dd0..bd466254 100644 --- a/cmd/garm-cli/cmd/provider.go +++ b/cmd/garm-cli/cmd/provider.go @@ -17,11 +17,11 @@ package cmd import ( "fmt" - apiClientProviders "github.com/cloudbase/garm/client/providers" - "github.com/cloudbase/garm/params" - "github.com/jedib0t/go-pretty/v6/table" "github.com/spf13/cobra" + + apiClientProviders "github.com/cloudbase/garm/client/providers" + "github.com/cloudbase/garm/params" ) // providerCmd represents the provider command diff --git a/cmd/garm-cli/cmd/repository.go b/cmd/garm-cli/cmd/repository.go index ecf99d02..9cc4d2c6 100644 --- a/cmd/garm-cli/cmd/repository.go +++ b/cmd/garm-cli/cmd/repository.go @@ -17,12 +17,12 @@ package cmd import ( "fmt" + "github.com/jedib0t/go-pretty/v6/table" + "github.com/spf13/cobra" + "github.com/cloudbase/garm-provider-common/util" apiClientRepos "github.com/cloudbase/garm/client/repositories" "github.com/cloudbase/garm/params" - - "github.com/jedib0t/go-pretty/v6/table" - "github.com/spf13/cobra" ) var ( diff --git a/cmd/garm-cli/cmd/root.go b/cmd/garm-cli/cmd/root.go index 72ecddc4..ef63ecff 100644 --- a/cmd/garm-cli/cmd/root.go +++ b/cmd/garm-cli/cmd/root.go @@ -19,14 +19,17 @@ import ( "net/url" "os" - apiClient "github.com/cloudbase/garm/client" - "github.com/cloudbase/garm/cmd/garm-cli/config" - "github.com/cloudbase/garm/params" "github.com/go-openapi/runtime" "github.com/jedib0t/go-pretty/v6/table" + openapiRuntimeClient "github.com/go-openapi/runtime/client" + "github.com/jedib0t/go-pretty/v6/table" "github.com/spf13/cobra" + + apiClient "github.com/cloudbase/garm/client" + "github.com/cloudbase/garm/cmd/garm-cli/config" + "github.com/cloudbase/garm/params" ) var Version string diff --git a/cmd/garm-cli/cmd/runner.go b/cmd/garm-cli/cmd/runner.go index f9cf010d..4613c669 100644 --- a/cmd/garm-cli/cmd/runner.go +++ b/cmd/garm-cli/cmd/runner.go @@ -18,14 +18,17 @@ import ( "fmt" "os" - "github.com/cloudbase/garm/params" + "github.com/jedib0t/go-pretty/v6/table" + "github.com/spf13/cobra" + + "github.com/jedib0t/go-pretty/v6/table" + "github.com/spf13/cobra" apiClientEnterprises "github.com/cloudbase/garm/client/enterprises" apiClientInstances "github.com/cloudbase/garm/client/instances" apiClientOrgs "github.com/cloudbase/garm/client/organizations" apiClientRepos "github.com/cloudbase/garm/client/repositories" - "github.com/jedib0t/go-pretty/v6/table" - "github.com/spf13/cobra" + "github.com/cloudbase/garm/params" ) var ( diff --git a/cmd/garm-cli/common/common.go b/cmd/garm-cli/common/common.go index 8164b9a7..b3850e31 100644 --- a/cmd/garm-cli/common/common.go +++ b/cmd/garm-cli/common/common.go @@ -39,7 +39,6 @@ func PromptPassword(label string) (string, error) { Mask: '*', } result, err := prompt.Run() - if err != nil { return "", err } @@ -59,7 +58,6 @@ func PromptString(label string) (string, error) { Validate: validate, } result, err := prompt.Run() - if err != nil { return "", err } diff --git a/cmd/garm-cli/config/home_nix.go b/cmd/garm-cli/config/home_nix.go index 92c99bad..27aed4f8 100644 --- a/cmd/garm-cli/config/home_nix.go +++ b/cmd/garm-cli/config/home_nix.go @@ -12,7 +12,6 @@ import ( func getHomeDir() (string, error) { home, err := os.UserHomeDir() - if err != nil { return "", errors.Wrap(err, "fetching home dir") } diff --git a/cmd/garm/main.go b/cmd/garm/main.go index df7a82e8..e50c9123 100644 --- a/cmd/garm/main.go +++ b/cmd/garm/main.go @@ -28,6 +28,11 @@ import ( "syscall" "time" + "github.com/gorilla/handlers" + "github.com/gorilla/mux" + "github.com/pkg/errors" + lumberjack "gopkg.in/natefinch/lumberjack.v2" + "github.com/cloudbase/garm-provider-common/util" "github.com/cloudbase/garm/apiserver/controllers" "github.com/cloudbase/garm/apiserver/routers" @@ -41,11 +46,6 @@ import ( garmUtil "github.com/cloudbase/garm/util" "github.com/cloudbase/garm/util/appdefaults" "github.com/cloudbase/garm/websocket" - lumberjack "gopkg.in/natefinch/lumberjack.v2" - - "github.com/gorilla/handlers" - "github.com/gorilla/mux" - "github.com/pkg/errors" ) var ( @@ -140,7 +140,6 @@ func setupLogging(ctx context.Context, logCfg config.Logging, hub *websocket.Hub Handler: han, } slog.SetDefault(slog.New(wrapped)) - } func main() { diff --git a/config/config.go b/config/config.go index a12b91a9..1103f99a 100644 --- a/config/config.go +++ b/config/config.go @@ -26,15 +26,18 @@ import ( "time" "github.com/BurntSushi/toml" - "github.com/cloudbase/garm/params" - "github.com/cloudbase/garm/util/appdefaults" zxcvbn "github.com/nbutton23/zxcvbn-go" "github.com/pkg/errors" + + "github.com/cloudbase/garm/params" + "github.com/cloudbase/garm/util/appdefaults" ) -type DBBackendType string -type LogLevel string -type LogFormat string +type ( + DBBackendType string + LogLevel string + LogFormat string +) const ( // MySQLBackend represents the MySQL DB backend diff --git a/config/config_test.go b/config/config_test.go index 2281d196..2295cdf3 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -20,8 +20,9 @@ import ( "testing" "time" - "github.com/cloudbase/garm/util/appdefaults" "github.com/stretchr/testify/require" + + "github.com/cloudbase/garm/util/appdefaults" ) var ( @@ -392,7 +393,6 @@ func TestGormParams(t *testing.T) { require.Nil(t, err) require.Equal(t, MySQLBackend, dbType) require.Equal(t, "test:test@tcp(127.0.0.1)/garm?charset=utf8&parseTime=True&loc=Local&timeout=5s", uri) - } func TestSQLiteConfig(t *testing.T) { diff --git a/config/external.go b/config/external.go index 8368b13c..66458868 100644 --- a/config/external.go +++ b/config/external.go @@ -20,9 +20,9 @@ import ( "path/filepath" "strings" - "github.com/cloudbase/garm-provider-common/util/exec" - "github.com/pkg/errors" + + "github.com/cloudbase/garm-provider-common/util/exec" ) // External represents the config for an external provider. diff --git a/config/external_test.go b/config/external_test.go index 30085726..f8a89800 100644 --- a/config/external_test.go +++ b/config/external_test.go @@ -31,7 +31,7 @@ func getDefaultExternalConfig(t *testing.T) External { } t.Cleanup(func() { os.RemoveAll(dir) }) - err = os.WriteFile(filepath.Join(dir, "garm-external-provider"), []byte{}, 0755) + err = os.WriteFile(filepath.Join(dir, "garm-external-provider"), []byte{}, 0o755) if err != nil { t.Fatalf("failed to write file: %s", err) } diff --git a/metrics/health.go b/metrics/health.go index d1f5e969..4acfbb36 100644 --- a/metrics/health.go +++ b/metrics/health.go @@ -4,10 +4,8 @@ import ( "github.com/prometheus/client_golang/prometheus" ) -var ( - GarmHealth = prometheus.NewGaugeVec(prometheus.GaugeOpts{ - Namespace: metricsNamespace, - Name: "health", - Help: "Health of the garm", - }, []string{"metadata_url", "callback_url", "webhook_url", "controller_webhook_url", "controller_id"}) -) +var GarmHealth = prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Namespace: metricsNamespace, + Name: "health", + Help: "Health of the garm", +}, []string{"metadata_url", "callback_url", "webhook_url", "controller_webhook_url", "controller_id"}) diff --git a/metrics/metrics.go b/metrics/metrics.go index 44b75031..edceb30a 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -4,15 +4,17 @@ import ( "github.com/prometheus/client_golang/prometheus" ) -const metricsNamespace = "garm" -const metricsRunnerSubsystem = "runner" -const metricsPoolSubsystem = "pool" -const metricsProviderSubsystem = "provider" -const metricsOrganizationSubsystem = "organization" -const metricsRepositorySubsystem = "repository" -const metricsEnterpriseSubsystem = "enterprise" -const metricsWebhookSubsystem = "webhook" -const metricsGithubSubsystem = "github" +const ( + metricsNamespace = "garm" + metricsRunnerSubsystem = "runner" + metricsPoolSubsystem = "pool" + metricsProviderSubsystem = "provider" + metricsOrganizationSubsystem = "organization" + metricsRepositorySubsystem = "repository" + metricsEnterpriseSubsystem = "enterprise" + metricsWebhookSubsystem = "webhook" + metricsGithubSubsystem = "github" +) // RegisterMetrics registers all the metrics func RegisterMetrics() error { diff --git a/metrics/provider.go b/metrics/provider.go index 5034a7e9..8285ca1e 100644 --- a/metrics/provider.go +++ b/metrics/provider.go @@ -4,11 +4,9 @@ import ( "github.com/prometheus/client_golang/prometheus" ) -var ( - ProviderInfo = prometheus.NewGaugeVec(prometheus.GaugeOpts{ - Namespace: metricsNamespace, - Subsystem: metricsProviderSubsystem, - Name: "info", - Help: "Info of the organization", - }, []string{"name", "type", "description"}) -) +var ProviderInfo = prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Namespace: metricsNamespace, + Subsystem: metricsProviderSubsystem, + Name: "info", + Help: "Info of the organization", +}, []string{"name", "type", "description"}) diff --git a/metrics/webhooks.go b/metrics/webhooks.go index 14b6492c..839219a4 100644 --- a/metrics/webhooks.go +++ b/metrics/webhooks.go @@ -2,11 +2,9 @@ package metrics import "github.com/prometheus/client_golang/prometheus" -var ( - WebhooksReceived = prometheus.NewCounterVec(prometheus.CounterOpts{ - Namespace: metricsNamespace, - Subsystem: metricsWebhookSubsystem, - Name: "received", - Help: "The total number of webhooks received", - }, []string{"valid", "reason"}) -) +var WebhooksReceived = prometheus.NewCounterVec(prometheus.CounterOpts{ + Namespace: metricsNamespace, + Subsystem: metricsWebhookSubsystem, + Name: "received", + Help: "The total number of webhooks received", +}, []string{"valid", "reason"}) diff --git a/params/params.go b/params/params.go index df37ddb2..af48bd1c 100644 --- a/params/params.go +++ b/params/params.go @@ -22,12 +22,11 @@ import ( "fmt" "time" - commonParams "github.com/cloudbase/garm-provider-common/params" - - "github.com/cloudbase/garm/util/appdefaults" - "github.com/google/go-github/v57/github" "github.com/google/uuid" + + commonParams "github.com/cloudbase/garm-provider-common/params" + "github.com/cloudbase/garm/util/appdefaults" ) type ( diff --git a/params/requests.go b/params/requests.go index 946c8536..2ad4fc1e 100644 --- a/params/requests.go +++ b/params/requests.go @@ -18,9 +18,8 @@ import ( "encoding/json" "fmt" - commonParams "github.com/cloudbase/garm-provider-common/params" - "github.com/cloudbase/garm-provider-common/errors" + commonParams "github.com/cloudbase/garm-provider-common/params" ) const DefaultRunnerPrefix = "garm" diff --git a/runner/pool/common.go b/runner/pool/common.go index 607e1cce..7479ef2e 100644 --- a/runner/pool/common.go +++ b/runner/pool/common.go @@ -4,10 +4,11 @@ import ( "net/url" "strings" - runnerErrors "github.com/cloudbase/garm-provider-common/errors" - "github.com/cloudbase/garm/params" "github.com/google/go-github/v57/github" "github.com/pkg/errors" + + runnerErrors "github.com/cloudbase/garm-provider-common/errors" + "github.com/cloudbase/garm/params" ) func validateHookRequest(controllerID, baseURL string, allHooks []*github.Hook, req *github.Hook) error { diff --git a/runner/pool/enterprise.go b/runner/pool/enterprise.go index e71f04d4..9019bcde 100644 --- a/runner/pool/enterprise.go +++ b/runner/pool/enterprise.go @@ -10,6 +10,9 @@ import ( "strings" "sync" + "github.com/google/go-github/v57/github" + "github.com/pkg/errors" + runnerErrors "github.com/cloudbase/garm-provider-common/errors" commonParams "github.com/cloudbase/garm-provider-common/params" dbCommon "github.com/cloudbase/garm/database/common" @@ -17,9 +20,6 @@ import ( "github.com/cloudbase/garm/params" "github.com/cloudbase/garm/runner/common" "github.com/cloudbase/garm/util" - - "github.com/google/go-github/v57/github" - "github.com/pkg/errors" ) // test that we implement PoolManager @@ -344,7 +344,6 @@ func (r *enterprise) GetGithubRegistrationToken() (string, error) { ).Inc() tk, ghResp, err := r.ghcEnterpriseCli.CreateRegistrationToken(r.ctx, r.cfg.Name) - if err != nil { metrics.GithubOperationFailedCount.WithLabelValues( "CreateRegistrationToken", // label: operation diff --git a/runner/pool/interfaces.go b/runner/pool/interfaces.go index 71a24cbe..0ea446e9 100644 --- a/runner/pool/interfaces.go +++ b/runner/pool/interfaces.go @@ -17,11 +17,11 @@ package pool import ( "context" + "github.com/google/go-github/v57/github" + commonParams "github.com/cloudbase/garm-provider-common/params" "github.com/cloudbase/garm/params" "github.com/cloudbase/garm/runner/common" - - "github.com/google/go-github/v57/github" ) type poolHelper interface { diff --git a/runner/pool/organization.go b/runner/pool/organization.go index 0eee23f4..2e287c94 100644 --- a/runner/pool/organization.go +++ b/runner/pool/organization.go @@ -24,6 +24,9 @@ import ( "strings" "sync" + "github.com/google/go-github/v57/github" + "github.com/pkg/errors" + runnerErrors "github.com/cloudbase/garm-provider-common/errors" commonParams "github.com/cloudbase/garm-provider-common/params" dbCommon "github.com/cloudbase/garm/database/common" @@ -31,9 +34,6 @@ import ( "github.com/cloudbase/garm/params" "github.com/cloudbase/garm/runner/common" "github.com/cloudbase/garm/util" - - "github.com/google/go-github/v57/github" - "github.com/pkg/errors" ) // test that we implement PoolManager @@ -357,7 +357,6 @@ func (r *organization) GetGithubRegistrationToken() (string, error) { metricsLabelOrganizationScope, // label: scope ).Inc() tk, ghResp, err := r.ghcli.CreateOrganizationRegistrationToken(r.ctx, r.cfg.Name) - if err != nil { metrics.GithubOperationFailedCount.WithLabelValues( "CreateOrganizationRegistrationToken", // label: operation diff --git a/runner/pool/pool.go b/runner/pool/pool.go index 8643447f..f073961f 100644 --- a/runner/pool/pool.go +++ b/runner/pool/pool.go @@ -25,19 +25,18 @@ import ( "sync" "time" - commonParams "github.com/cloudbase/garm-provider-common/params" + "github.com/google/go-github/v57/github" + "github.com/google/uuid" + "github.com/pkg/errors" + "golang.org/x/sync/errgroup" runnerErrors "github.com/cloudbase/garm-provider-common/errors" + commonParams "github.com/cloudbase/garm-provider-common/params" "github.com/cloudbase/garm-provider-common/util" "github.com/cloudbase/garm/auth" dbCommon "github.com/cloudbase/garm/database/common" "github.com/cloudbase/garm/params" "github.com/cloudbase/garm/runner/common" - - "github.com/google/go-github/v57/github" - "github.com/google/uuid" - "github.com/pkg/errors" - "golang.org/x/sync/errgroup" ) var ( @@ -674,7 +673,7 @@ func (r *basePoolManager) cleanupOrphanedGithubRunners(runners []*github.Runner) slog.InfoContext( r.ctx, "instance was found in stopped state; starting", "runner_name", dbInstance.Name) - //start the instance + if err := provider.Start(r.ctx, dbInstance.ProviderID); err != nil { return errors.Wrapf(err, "starting instance %s", dbInstance.ProviderID) } @@ -1196,7 +1195,6 @@ func (r *basePoolManager) ensureIdleRunnersForOnePool(pool params.Pool) error { existingInstances, err := r.store.ListPoolInstances(r.ctx, pool.ID) if err != nil { return fmt.Errorf("failed to ensure minimum idle workers for pool %s: %w", pool.ID, err) - } if uint(len(existingInstances)) >= pool.MaxRunners { diff --git a/runner/pool/repository.go b/runner/pool/repository.go index 9ba77c13..43273c16 100644 --- a/runner/pool/repository.go +++ b/runner/pool/repository.go @@ -24,6 +24,9 @@ import ( "strings" "sync" + "github.com/google/go-github/v57/github" + "github.com/pkg/errors" + runnerErrors "github.com/cloudbase/garm-provider-common/errors" commonParams "github.com/cloudbase/garm-provider-common/params" dbCommon "github.com/cloudbase/garm/database/common" @@ -31,9 +34,6 @@ import ( "github.com/cloudbase/garm/params" "github.com/cloudbase/garm/runner/common" "github.com/cloudbase/garm/util" - - "github.com/google/go-github/v57/github" - "github.com/pkg/errors" ) // test that we implement PoolManager @@ -314,7 +314,6 @@ func (r *repository) GetGithubRegistrationToken() (string, error) { metricsLabelRepositoryScope, // label: scope ).Inc() tk, ghResp, err := r.ghcli.CreateRegistrationToken(r.ctx, r.cfg.Owner, r.cfg.Name) - if err != nil { metrics.GithubOperationFailedCount.WithLabelValues( "CreateRegistrationToken", // label: operation diff --git a/runner/providers/external/external.go b/runner/providers/external/external.go index 6b35b3e5..9174b2e8 100644 --- a/runner/providers/external/external.go +++ b/runner/providers/external/external.go @@ -7,18 +7,16 @@ import ( "log/slog" "os/exec" - "github.com/cloudbase/garm-provider-common/execution" - - commonParams "github.com/cloudbase/garm-provider-common/params" + "github.com/pkg/errors" garmErrors "github.com/cloudbase/garm-provider-common/errors" + "github.com/cloudbase/garm-provider-common/execution" + commonParams "github.com/cloudbase/garm-provider-common/params" garmExec "github.com/cloudbase/garm-provider-common/util/exec" "github.com/cloudbase/garm/config" "github.com/cloudbase/garm/metrics" "github.com/cloudbase/garm/params" "github.com/cloudbase/garm/runner/common" - - "github.com/pkg/errors" ) var _ common.Provider = (*external)(nil) diff --git a/runner/providers/providers.go b/runner/providers/providers.go index e9bb48ed..165fb585 100644 --- a/runner/providers/providers.go +++ b/runner/providers/providers.go @@ -18,12 +18,12 @@ import ( "context" "log/slog" + "github.com/pkg/errors" + "github.com/cloudbase/garm/config" "github.com/cloudbase/garm/params" "github.com/cloudbase/garm/runner/common" "github.com/cloudbase/garm/runner/providers/external" - - "github.com/pkg/errors" ) // LoadProvidersFromConfig loads all providers from the config and populates diff --git a/test/integration/e2e/client.go b/test/integration/e2e/client.go index 2ab81695..ee500383 100644 --- a/test/integration/e2e/client.go +++ b/test/integration/e2e/client.go @@ -4,10 +4,11 @@ import ( "log/slog" "net/url" - "github.com/cloudbase/garm/client" - "github.com/cloudbase/garm/params" "github.com/go-openapi/runtime" openapiRuntimeClient "github.com/go-openapi/runtime/client" + + "github.com/cloudbase/garm/client" + "github.com/cloudbase/garm/params" ) var ( diff --git a/test/integration/e2e/client_utils.go b/test/integration/e2e/client_utils.go index 955f7b52..367ff76a 100644 --- a/test/integration/e2e/client_utils.go +++ b/test/integration/e2e/client_utils.go @@ -1,6 +1,8 @@ package e2e import ( + "github.com/go-openapi/runtime" + "github.com/cloudbase/garm/client" clientControllerInfo "github.com/cloudbase/garm/client/controller_info" clientCredentials "github.com/cloudbase/garm/client/credentials" @@ -14,7 +16,6 @@ import ( clientProviders "github.com/cloudbase/garm/client/providers" clientRepositories "github.com/cloudbase/garm/client/repositories" "github.com/cloudbase/garm/params" - "github.com/go-openapi/runtime" ) // /////////// diff --git a/util/util.go b/util/util.go index bf70d081..1db1e5bd 100644 --- a/util/util.go +++ b/util/util.go @@ -21,12 +21,12 @@ import ( "fmt" "net/http" - "github.com/cloudbase/garm/params" - "github.com/cloudbase/garm/runner/common" - "github.com/google/go-github/v57/github" "github.com/pkg/errors" "golang.org/x/oauth2" + + "github.com/cloudbase/garm/params" + "github.com/cloudbase/garm/runner/common" ) type githubClient struct { diff --git a/websocket/client.go b/websocket/client.go index ef420460..69812a0d 100644 --- a/websocket/client.go +++ b/websocket/client.go @@ -5,7 +5,6 @@ import ( "time" "github.com/google/uuid" - "github.com/gorilla/websocket" )