Skip to content

PoC: Auto stop environments after a certain period

Shinya Maeda requested to merge poc-expiration-for-environments into master

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's 1 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 with on_stop presence)
  • Add a database colomn environments.auto_stop_at (datetime_with_timezone)
  • Renew environments.auto_stop_at in Deployments::SuccessWorker
  • Introduce Deployments::AutoStopCronWorker to stop environments where auto_stop_at < Time.now
  • Expose environments.auto_stop_at and cancel_auto_stop_url in environments.json
  • EnvironmentController#cancel_auto_stop for stopping auto_stop (i.e. Nullfyiing auto_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 in cancel_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

Peek_2019-11-04_18-55

Does this MR meet the acceptance criteria?

Conformity

Performance and Testing

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

Merge request reports