Commit graph

46 commits

Author SHA1 Message Date
Mihaela Balutoiu
36a51f83ab Fixed error wrap
The error is not wrapped correctly, because instead of using `q.Error`,
it uses `err`, which is defined elsewhere.

Also, the `UpdateRepository` and `CreateRepositoryPool` functions will
never fail on update/create repo, because it returns a nil error, instead
of wrap error.

Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
2022-10-17 17:48:00 +03:00
Mihaela Balutoiu
04e89ce1ab Add more test cases for the database/sql/repositories.go
Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
2022-10-17 13:35:38 +03:00
Mihaela Balutoiu
98306dd25a Add repositories.go unit testing
Add initial unit tests for the `database/sql/repositories.go` from `sql`package.

Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
2022-10-14 18:10:34 +03:00
Mihaela Balutoiu
c65cf9ab0c Add pools.go database unit tests
Add full tests coverage for `database/sql/pools.go` file.

Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
2022-10-13 17:57:00 +03:00
Mihaela Balutoiu
1197e82752 Add pools.go unit tests
Add initial unit tests for the `database/sql/pools.go` from `sql` package.

Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
2022-10-13 15:18:26 +03:00
Mihaela Balutoiu
8d138afde2 Add organizations.go database unit testing
Add more test cases regarding the SQL database interactions.

Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
2022-10-12 17:27:08 +03:00
Mihaela Balutoiu
1116de7608 Fixed error wrap
The error is not wrapped correctly, because instead of using `q.Error`,
it uses `err`, which is defined elsewhere.

Also, the `UpdateOrganization` and `CreateOrganizationPool` functions will
never fail on update/create org, because it returns a nil error, instead
of wrap error.

Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
2022-10-10 14:45:55 +03:00
Mihaela Balutoiu
23f521b682 Add more organizations.go unit testing 2022-10-06 11:59:05 +03:00
Gabriel Adrian Samfira
0ff2fd2e06
Make owners and repos case insensitive
Github treats owners (users and orgs) and repos as case insensitive. To
github, https://github.com/cloudbase/garm is equivalent to
https://github.com/CloudBase/GaRm. This commit makes the sql store
backend, case insensitive when querying repos and orgs.

Fixes: #25

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
2022-10-05 18:14:07 +03:00
Mihaela Balutoiu
5692439dda Add organizations.go unit tests 2022-10-03 17:55:35 +03:00
Mihaela Balutoiu
723c9c3d60 Add instances.go database unit tests
Add more test cases regarding the SQL database interactions.
Moreover, add `go-sqlmock` dependency used to mock SQL DB instructions.

Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
2022-09-28 17:29:40 +03:00
Mihaela Balutoiu
898e098ff8 Add more instances.go unit tests
Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
2022-09-21 20:34:14 +03:00
mihaelabalutoiu
6039a97d5a Fix typo 2022-09-15 19:18:28 +03:00
mihaelabalutoiu
e2ada6d1e3 Cleanup unused struct field
Remove `Pool` field from `CreateInstanceParams` struct, because
this is given as a separate parameter to the `CreateInstance` function.
2022-09-15 19:11:37 +03:00
mihaelabalutoiu
797ec21dd9 Add instances.go unit tests 2022-09-15 18:59:16 +03:00
Gabriel Adrian Samfira
b4ac128673
Create a testing package for common utilities
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
2022-09-15 17:48:09 +03:00
mihaelabalutoiu
8c910d904f Cleanup duplicate code 2022-09-14 12:55:26 +03:00
mihaelabalutoiu
bdb087578a Add controller.go unit tests 2022-09-13 14:21:21 +03:00
Gabriel Adrian Samfira
99856af4de
Silence gorm default logger
Disable the default logger for gorm when debug is not set on the sql
store backend. By default gorm will print error level log messages,
which includes queries which find no results, which is not really an
error.

These messages will show up if debug is enabled on the sql store
backend.

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
2022-09-06 21:35:01 +03:00
Gabriel Adrian Samfira
afb1d31394 Slight cleanup
* added interface for the github client. This will help mocking it
out for testing.
  * removed some unused code
  * moved some code around

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
2022-07-07 16:48:00 +00:00
Gabriel Adrian Samfira
280cad96e4 Make runner-bootstrap-timeout optional
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
2022-07-06 17:37:18 +00:00
Gabriel Adrian Samfira
0a17578798 Properly set timeout on pool create
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
2022-06-30 06:55:13 +00:00
Gabriel Adrian Samfira
15a1308441 Add timeout functionality for pool runner bootstrap
Pools can now define a bootstrap timeout for runners. The timeout can
be defined per pool and indicates the amount of time after which a runner
is considered defunct and removed.

If a runner doesn't join github in the configured amount of time, and it
receives no updates indicating that it is installing the runner via instance
status updates, it is considered defunct.

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
2022-06-29 23:44:03 +00:00
Gabriel Adrian Samfira
5390efbaab Add manual runner removal
Runners can now be manually removed using the CLI. Some restrictions apply:

  * A runner must be idle in github. Github will not allow us to remove a runner
that is running a workflow.
  * The runner status must be "running"

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
2022-06-29 16:23:01 +00:00
Gabriel Adrian Samfira
f52accc47f Add idempotency when stopping a VM and some tests
When deleting a VM, we try to force stop it. If the VM is already stopped,
LXD will return an error. Unfortunately, we can't import the drivers package
from LXD without also pulling in a bunch of linux specific CGO dependencies
which we want to avoid.

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
2022-06-28 15:13:02 +00:00
Gabriel Adrian Samfira
b4e9af13d5 Fix tags update 2022-06-24 11:41:38 +00:00
Gabriel Adrian Samfira
98eb594cd6 Remove some blocking code
* added 2 new statuses: creating and deleting
  * remove wait on create/delete, speeding things up a bit
2022-05-13 23:34:16 +00:00
Gabriel Adrian Samfira
209347e0c6 Fix bug in get instance query 2022-05-11 14:50:19 +00:00
Gabriel Adrian Samfira
dc04bca95c Retry failed runners
* retry adding runners for up to 5 times if they fail.
  * various fixes
2022-05-10 12:28:39 +00:00
Gabriel Adrian Samfira
5e0a64f909 Add license headers 2022-05-05 13:25:50 +00:00
Gabriel Adrian Samfira
d9c65872e8 Added more CLI commands and API endpoints 2022-05-05 13:07:06 +00:00
Gabriel Adrian Samfira
f130798f41 Added org pool command
* added new command
  * fixed a bunch of bugs in orgs
2022-05-04 21:57:08 +00:00
Gabriel Adrian Samfira
3e416d8272 Slight refactor of sql code 2022-05-04 13:15:27 +00:00
Gabriel Adrian Samfira
1dda4a835c Rename project to garm
Project renamed to garm (Github Actions Runner Manager)
2022-05-04 11:44:10 +00:00
Gabriel Adrian Samfira
2bd128af13 Runners now send status messages 2022-05-03 19:49:14 +00:00
Gabriel Adrian Samfira
6bdb8cd78b return proper error on conflict 2022-05-03 13:20:49 +00:00
Gabriel Adrian Samfira
8ceafff09b Add more CLI commands 2022-05-03 12:40:59 +00:00
Gabriel Adrian Samfira
475d424f32 Add a basic CLI 2022-05-02 17:55:29 +00:00
Gabriel Adrian Samfira
7ec937a138 Main webhook cases implemented
Queued, completed and in_progress workflow_job messages are now
acted upon.
2022-04-29 23:43:37 +00:00
Gabriel Adrian Samfira
a78ad539fe Auto create runners for pools 2022-04-29 16:08:31 +00:00
Gabriel Adrian Samfira
0314fd3b67 Add some API resources 2022-04-29 14:18:22 +00:00
Gabriel Adrian Samfira
75e06b36b0 Fix GetUser 2022-04-28 16:24:26 +00:00
Gabriel Adrian Samfira
0883fcd5cd Add some basic auth 2022-04-28 16:13:20 +00:00
Gabriel Adrian Samfira
66b46ae0ab Implement some more db functions 2022-04-27 16:56:28 +00:00
Gabriel Adrian Samfira
62ba5a5a08 WiP 2022-04-26 20:29:58 +00:00
Gabriel Adrian Samfira
2be5653683 Added some DB logic 2022-04-25 00:21:44 +00:00