2023-01-01 04:28:08 +00:00
|
|
|
# Deploy Lock
|
|
|
|
|
|
|
|
This is a tool to lock a cluster or service, in order to prevent people from deploying changes during test automation or
|
2023-01-01 17:17:58 +00:00
|
|
|
restarting pods during an infrastructure incident.
|
2023-01-01 04:28:08 +00:00
|
|
|
|
2023-01-04 16:03:12 +00:00
|
|
|
## Features
|
|
|
|
|
|
|
|
- in-memory data store, mostly for testing
|
|
|
|
- DynamoDB data store
|
|
|
|
- lock paths and recursive checking
|
|
|
|
- infer lock data from CI variables
|
2023-01-04 15:48:26 +00:00
|
|
|
|
2023-01-01 04:28:08 +00:00
|
|
|
## Contents
|
|
|
|
|
|
|
|
- [Deploy Lock](#deploy-lock)
|
2023-01-04 16:03:12 +00:00
|
|
|
- [Features](#features)
|
2023-01-01 04:28:08 +00:00
|
|
|
- [Contents](#contents)
|
2023-01-04 16:03:12 +00:00
|
|
|
- [Concepts](#concepts)
|
|
|
|
- [Lock Path](#lock-path)
|
2023-01-01 17:26:45 +00:00
|
|
|
- [Lock Data](#lock-data)
|
2023-01-02 19:56:21 +00:00
|
|
|
- [Usage](#usage)
|
2023-01-01 04:28:08 +00:00
|
|
|
- [Command-line Interface](#command-line-interface)
|
2023-01-01 15:31:14 +00:00
|
|
|
- [Basic Options](#basic-options)
|
|
|
|
- [Lock Data Options](#lock-data-options)
|
|
|
|
- [Storage Backend Options](#storage-backend-options)
|
2023-01-03 02:40:15 +00:00
|
|
|
- [Admission Controller Options](#admission-controller-options)
|
2023-01-01 04:28:08 +00:00
|
|
|
- [REST API](#rest-api)
|
|
|
|
- [Endpoints](#endpoints)
|
2023-01-04 16:03:12 +00:00
|
|
|
|
|
|
|
## Concepts
|
|
|
|
|
|
|
|
![readme banner top](docs/banner-top.png)
|
|
|
|
|
|
|
|
### Lock Path
|
|
|
|
|
|
|
|
Briefly describe paths.
|
|
|
|
|
|
|
|
[More details here.](./docs/concepts.md#deploy-path)
|
2023-01-01 04:28:08 +00:00
|
|
|
|
|
|
|
### Lock Data
|
|
|
|
|
|
|
|
Each lock must contain the following fields:
|
|
|
|
|
|
|
|
```typescript
|
|
|
|
interface Lock {
|
2023-01-01 17:26:45 +00:00
|
|
|
type: 'automation' | 'deploy' | 'freeze' | 'incident' | 'maintenance';
|
2023-01-01 17:57:21 +00:00
|
|
|
path: string;
|
2023-01-01 04:28:08 +00:00
|
|
|
author: string;
|
|
|
|
links: Map<string, string>;
|
2023-01-02 20:08:46 +00:00
|
|
|
// often duplicates of path, but useful for cross-project locks
|
|
|
|
source: string;
|
2023-01-01 04:28:08 +00:00
|
|
|
|
|
|
|
// Timestamps, calculated from --duration and --until
|
|
|
|
created_at: number;
|
|
|
|
updated_at: number;
|
|
|
|
expires_at: number;
|
|
|
|
|
|
|
|
// CI fields, optional
|
|
|
|
ci?: {
|
|
|
|
project: string;
|
|
|
|
ref: string;
|
|
|
|
commit: string;
|
|
|
|
pipeline: string;
|
|
|
|
job: string;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
If `$CI` is not set, the `ci` sub-struct will not be present.
|
|
|
|
|
2023-01-02 19:56:21 +00:00
|
|
|
## Usage
|
|
|
|
|
2023-01-01 04:28:08 +00:00
|
|
|
### Command-line Interface
|
|
|
|
|
|
|
|
```shell
|
2023-01-02 19:41:33 +00:00
|
|
|
> deploy-lock check apps/staging/a/auth-app # is equivalent to
|
|
|
|
> deploy-lock check apps && deploy-lock check apps/staging && deploy-lock check apps/staging/a && deploy-lock check apps/staging/a/auth-app
|
|
|
|
> deploy-lock check apps/staging/a/auth-app --recursive=false # only checks the leaf node
|
2023-01-01 04:28:08 +00:00
|
|
|
|
2023-01-04 15:48:26 +00:00
|
|
|
> deploy-lock list
|
2023-01-02 19:41:33 +00:00
|
|
|
> deploy-lock list apps/staging # list all locks within the apps/staging path
|
2023-01-01 15:31:14 +00:00
|
|
|
|
2023-01-02 19:41:33 +00:00
|
|
|
> deploy-lock lock apps/staging --type automation --duration 60m
|
|
|
|
> deploy-lock lock apps/staging/a/auth-app --type deploy --duration 5m
|
|
|
|
> deploy-lock lock apps/staging --until 2022-12-31T12:00 # local TZ, unless Z specified
|
2023-01-01 17:38:42 +00:00
|
|
|
|
2023-01-02 19:41:33 +00:00
|
|
|
> deploy-lock prune # prune all expired locks
|
|
|
|
> deploy-lock prune apps/staging # prune expired locks within the path
|
|
|
|
> deploy-lock prune apps/staging --now future-date # prune locks that will expire by --now
|
2023-01-01 17:38:42 +00:00
|
|
|
|
2023-01-02 19:41:33 +00:00
|
|
|
> deploy-lock unlock apps/staging --type automation # unlock type must match lock type
|
2023-01-01 04:28:08 +00:00
|
|
|
```
|
|
|
|
|
2023-01-01 15:31:14 +00:00
|
|
|
#### Basic Options
|
2023-01-01 04:28:08 +00:00
|
|
|
|
2023-01-01 17:26:45 +00:00
|
|
|
- command
|
|
|
|
- one of `check`, `list`, `lock`, `prune`, `unlock`
|
2023-01-02 19:41:33 +00:00
|
|
|
- `<path>`
|
|
|
|
- positional, required
|
|
|
|
- string
|
|
|
|
- lock path
|
|
|
|
- always lowercase (forced in code)
|
|
|
|
- `/^[-a-z\/]+$/`
|
2023-01-01 17:11:41 +00:00
|
|
|
- `--now`
|
|
|
|
- number, optional
|
|
|
|
- defaults to current epoch time
|
2023-01-01 04:28:08 +00:00
|
|
|
- `--recursive`
|
|
|
|
- boolean
|
|
|
|
- recursively check locks
|
|
|
|
- defaults to true for `check`
|
|
|
|
- defaults to false for `lock`, `unlock`
|
2023-01-01 15:31:14 +00:00
|
|
|
- `--type`
|
|
|
|
- string, enum
|
|
|
|
- type of lock
|
2023-01-01 17:26:45 +00:00
|
|
|
- one of `automation`, `deploy`, `freeze`, `incident`, or `maintenance`
|
2023-01-01 17:11:41 +00:00
|
|
|
|
|
|
|
#### Lock Data Options
|
|
|
|
|
2023-01-04 15:48:26 +00:00
|
|
|
- `--allow`
|
|
|
|
- array, strings
|
|
|
|
- check types to allow while this lock is active
|
|
|
|
- this does not allow creating other locks at the same path, it only changes whether the check returns allowed
|
2023-01-01 17:11:41 +00:00
|
|
|
- `--author`
|
|
|
|
- string
|
|
|
|
- defaults to `$GITLAB_USER_EMAIL` if `$GITLAB_CI` is set
|
|
|
|
- defaults to `$USER` otherwise
|
|
|
|
- `--duration`
|
|
|
|
- string
|
|
|
|
- duration of lock, relative to now
|
2023-01-01 18:28:17 +00:00
|
|
|
- may be given in epoch seconds (`\d+`), as an ISO-8601 date, or a human interval (`30m`)
|
2023-01-01 17:11:41 +00:00
|
|
|
- mutually exclusive with `--until`
|
|
|
|
- `--link`
|
|
|
|
- array, strings
|
2023-01-02 20:08:46 +00:00
|
|
|
- `--source`
|
|
|
|
- string
|
|
|
|
- each component:
|
|
|
|
- first
|
|
|
|
- defaults to `$CLUSTER_NAME` if set
|
|
|
|
- defaults to `path.split.0` otherwise
|
|
|
|
- second
|
|
|
|
- defaults to `$DEPLOY_ENV` if set
|
|
|
|
- defaults to `path.split.1` otherwise
|
|
|
|
- third
|
|
|
|
- defaults to `$DEPLOY_TARGET` if set
|
|
|
|
- defaults to `path.split.2` otherwise
|
|
|
|
- fourth
|
|
|
|
- defaults to `--ci-project` if set
|
|
|
|
- defaults to `$CI_PROJECT_PATH` if set
|
|
|
|
- defaults to `path.split.3` otherwise
|
|
|
|
- fifth
|
|
|
|
- defaults to `--ci-ref` if set
|
|
|
|
- defaults to `$CI_COMMIT_REF_SLUG` if set
|
|
|
|
- defaults to `path.split.4` otherwise
|
2023-01-01 15:31:14 +00:00
|
|
|
- `--until`
|
|
|
|
- string, timestamp
|
|
|
|
- duration of lock, absolute
|
2023-01-01 18:28:17 +00:00
|
|
|
- may be given in epoch seconds (`\d+`) or as an ISO-8601 date (intervals are not allowed)
|
2023-01-01 15:31:14 +00:00
|
|
|
- mutually exclusive with `--duration`
|
2023-01-01 04:28:08 +00:00
|
|
|
- `--ci-project`
|
|
|
|
- optional string
|
|
|
|
- project path
|
|
|
|
- defaults to `$CI_PROJECT_PATH` if set
|
2023-01-02 19:41:33 +00:00
|
|
|
- defaults to `path.split.3` otherwise
|
2023-01-01 04:28:08 +00:00
|
|
|
- `--ci-ref`
|
|
|
|
- optional string
|
|
|
|
- branch or tag
|
|
|
|
- defaults to `$CI_COMMIT_REF_SLUG` if set
|
2023-01-02 19:41:33 +00:00
|
|
|
- defaults to `path.split.4` otherwise
|
2023-01-01 04:28:08 +00:00
|
|
|
- `--ci-commit`
|
|
|
|
- optional string
|
|
|
|
- SHA of ref
|
|
|
|
- defaults to `$CI_COMMIT_SHA` if set
|
|
|
|
- `--ci-pipeline`
|
|
|
|
- optional string
|
|
|
|
- pipeline ID
|
|
|
|
- defaults to `$CI_PIPELINE_ID` if set
|
|
|
|
- `--ci-job`
|
|
|
|
- optional string
|
|
|
|
- job ID
|
|
|
|
- defaults to `$CI_JOB_ID` if set
|
|
|
|
|
2023-01-01 15:31:14 +00:00
|
|
|
#### Storage Backend Options
|
2023-01-01 04:28:08 +00:00
|
|
|
|
|
|
|
- `--storage`
|
|
|
|
- string
|
|
|
|
- one of `dynamodb`, `memory`
|
2023-01-01 15:31:14 +00:00
|
|
|
- `--region`
|
|
|
|
- string, optional
|
|
|
|
- DynamoDB region name
|
2023-01-01 04:28:08 +00:00
|
|
|
- `--table`
|
|
|
|
- string
|
|
|
|
- DynamoDB table name
|
2023-01-01 15:31:14 +00:00
|
|
|
- `--endpoint`
|
|
|
|
- string, optional
|
|
|
|
- DynamoDB endpoint
|
2023-01-03 04:06:38 +00:00
|
|
|
- set to `http://localhost:8000` for testing with DynamoDB local
|
2023-01-01 15:31:14 +00:00
|
|
|
- `--fake`
|
|
|
|
- string, optional
|
|
|
|
- a fake lock that should be added to the in-memory data store
|
2023-01-01 18:28:17 +00:00
|
|
|
- the in-memory data store always starts empty, this is the only way to have an existing lock
|
2023-01-01 04:28:08 +00:00
|
|
|
|
2023-01-03 02:40:15 +00:00
|
|
|
#### Admission Controller Options
|
|
|
|
|
|
|
|
- `--admission-base`
|
|
|
|
- string
|
|
|
|
- base path for admission controller requests
|
|
|
|
- usually the path to the cluster within the deploy path, like `aws/staging/us-east-1/apps/a`
|
|
|
|
- `--admission-path`
|
|
|
|
- array, strings
|
|
|
|
- path keys to use when checking admission controller requests
|
|
|
|
- must be fields within the `AdmissionReview` kind
|
|
|
|
- usually something like `[namespace, name]` or `[namespace, requestResource.group, requestResource.resource, name]`
|
|
|
|
|
2023-01-01 04:28:08 +00:00
|
|
|
### REST API
|
|
|
|
|
|
|
|
#### Endpoints
|
|
|
|
|
2023-01-03 04:06:38 +00:00
|
|
|
- `/admission POST`
|
|
|
|
- Kubernetes admission controller webhook
|
2023-01-01 04:28:08 +00:00
|
|
|
- `/locks GET`
|
2023-01-01 15:31:14 +00:00
|
|
|
- equivalent to `deploy-lock list`
|
2023-01-03 04:06:38 +00:00
|
|
|
- `/locks POST`
|
|
|
|
- equivalent to `deploy-lock lock`
|
|
|
|
- path taken from request body
|
2023-01-01 17:38:42 +00:00
|
|
|
- `/locks DELETE`
|
2023-01-01 15:31:14 +00:00
|
|
|
- equivalent to `deploy-lock prune`
|
|
|
|
- `/locks/:path GET`
|
|
|
|
- equivalent to `deploy-lock check`
|
2023-01-01 17:38:42 +00:00
|
|
|
- `/locks/:path PUT`
|
2023-01-01 15:31:14 +00:00
|
|
|
- equivalent to `deploy-lock lock`
|
2023-01-03 04:06:38 +00:00
|
|
|
- path taken from URL path
|
2023-01-01 18:28:17 +00:00
|
|
|
- `/locks/:path DELETE`
|
|
|
|
- equivalent to `deploy-lock unlock`
|
2023-01-03 04:06:38 +00:00
|
|
|
- `/ok`
|
|
|
|
- health check
|
2023-01-01 15:31:14 +00:00
|
|
|
|
2023-01-04 15:48:26 +00:00
|
|
|
![readme bottom banner](docs/banner-bottom.png)
|