PoC: Auto stop environments after a certain period
What does this MR do?
This is PoC/Prototype for #20956 (closed). Not for merge.
Technical overview
- Users can define
environments:auto_stop_in
in .gitlab-ci.yml. If it's1 day
, the system stops the environment in one day. - When a new environment is created, initial
auto_stop_at
is set. - When a new deployment has finished, the
auto_stop_at
is renewed. -
AutoStopCronWorker
runs once per hour. It finds expired environments and stops them. It's basically same approach with Pipeline Schedule. It's not executed at the exact time due to the nature of the cron approach, however, since it's cleanup, the precision would not matter. - Users can manually cancel the auto-stop in UI.
TODOs
BE:
-
Allow to define environments:auto_stop_in
in .gitlab-ci.yml (Has to validate withon_stop
presence) -
Add a database colomn environments.auto_stop_at
(datetime_with_timezone
) -
Renew environments.auto_stop_at
inDeployments::SuccessWorker
-
Introduce Deployments::AutoStopCronWorker
to stop environments whereauto_stop_at < Time.now
-
Expose environments.auto_stop_at
andcancel_auto_stop_url
in environments.json -
EnvironmentController#cancel_auto_stop
for stopping auto_stop (i.e. Nullfyiingauto_stop_at
) -
Update app/views/projects/environments/show.html.haml
to show auto_stop_at -
Create ResetAutoStopService
and returns status and error message. The message will be returned incancel_auto_stop
endpoint.
FE:
-
Render "Auto stop in" and "Cancel auto stop" in app/assets/javascripts/environments/components/environments_table.vue - Should we refactor
app/views/projects/environments/show.html.haml
in vue.js?
Screenshots
Does this MR meet the acceptance criteria?
Conformity
-
Changelog entry -
Documentation created/updated or follow-up review issue created -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Performance and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
-
Label as security and @ mention @gitlab-com/gl-security/appsec
-
The MR includes necessary changes to maintain consistency between UI, API, email, or other methods -
Security reports checked/validated by a reviewer from the AppSec team
Edited by Shinya Maeda