Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add chaos mesh api description and table schema #633

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
249 changes: 249 additions & 0 deletions docs/openapi3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ tags:
- name: Webhooks
description: |
This resource allows you to configure webhooks.
- name: Chaos Experiments
description: |
This resource allows you to add chaos mesh experiments as part of the running job
x-tagGroups:
- name: Reference
tags:
Expand Down Expand Up @@ -1890,6 +1893,185 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/upload_file_response'
/v1/chaos-experiments:
parameters:
- $ref: '#/components/parameters/context_id'
post:
operationId: create-chaos-experiment
tags:
- Chaos Experiments
summary: Create chaos file
description: >-
Create a chaos experiment.
responses:
'201':
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/chaosExperiment'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/error_response'
'422':
description: Unprocessable entity
content:
application/json:
schema:
$ref: '#/components/schemas/error_response'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/error_response'
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/chaosExperiment'
description: The chaos experiment to create
required: true
get:
operationId: retrieve-all-choos-experiments
tags:
- Chaos Experiments
summary: Retrieve all chaos experiments
description: Retrieve all chaos experiments
parameters:
- in: query
name: from
description: From which result to start retrieve data - pagination
required: false
schema:
type: integer
minimum: 0
default: 0
- in: query
name: limit
description: Max results to return from this query ( Limit to 100 )
required: false
schema:
type: integer
maximum: 200
default: 100
- in: query
name: template
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it irrelevant? all are templates

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed - but I closed this MR please see #635

description: filter to get templates only
required: false
schema:
type: boolean
example: true
- in: query
name: exclude
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just a common option in the crud sometimes not to show everything

description: fields to exclude from response
required: false
schema:
type: array
items:
type: string
enum:
- kubeObject
responses:
'200':
description: Success
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/chaosExperiment'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/error_response'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/error_response'
/v1/chaos-experiments/{experiment_id}:
parameters:
- $ref: '#/components/parameters/context_id'
get:
operationId: retrieve-chaos-experiment
tags:
- Chaos Experiments
summary: Retrieve chaos experiment
description: Retrieve a specific chaos experiment.
parameters:
- in: path
name: experiment_id
description: The id of the experiment to retrieve.
required: true
schema:
type: string
responses:
'200':
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/chaosExperiment'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/error_response'
'404':
description: Not found
content:
application/json:
schema:
$ref: '#/components/schemas/error_response'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/error_response'
delete:
operationId: delete-chaos-experiment
tags:
- Chaos Experiments
summary: Delete chaos experiment
description: Delete a specific chaos experiment
parameters:
- in: path
name: experiment_id
description: The id of the experiment to retrieve.
required: true
schema:
type: string
responses:
'204':
description: Success
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/error_response'
'409':
description: Conflict
content:
application/json:
schema:
$ref: '#/components/schemas/error_response'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/error_response'

components:
parameters:
context_id:
Expand Down Expand Up @@ -2956,3 +3138,70 @@ components:
url:
type: string
description: Webhook url to post events
chaosExperiment:
required:
- name
- kind
- namespace
properties:
id:
description: Unique experiment identifier
type: string
format: uuid
readOnly: true
name:
type: string
minLength: 1
description: The name of the experiment.
example: Custom javascript for logging
kubeObject:
$ref: '#/components/schemas/kubeObject'
updated_at:
type: string
format: date-time
description: The date and time that the procesor file was updated.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"procesor file" not relevant in this case

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

readOnly: true
created_at:
type: string
format: date-time
description: The date and time that the procesor file was created.
readOnly: true
kubeObject:
required:
- apiVersion
- kind
- namespace
- name
- spec
properties:
apiVersion:
type: string
enum:
- "chaos-mesh.org/v1alpha1"
kind:
type: string
enum:
- 'dnschaos'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one is small letters on purpose?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

- 'PodChaos'
- 'AWSChaos'
- 'HTTPChaos'
- 'StressChaos'
description: A description of the experiment.
example: 'PodChaos'
namespace:
type: string
example: "apps"
name:
type: string
example: "my-pod-chaos"
spec:
type: object
example:
selector:
namespaces:
- apps
labelSelectors:
app: live-balances-api
mode: all
action: pod-kill
duration: 1m
39 changes: 39 additions & 0 deletions src/chaos-experiments/models/database/databaseConnector.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const sequelizeConnector = require('./sequelize/sequelizeConnector');
const databaseConnector = sequelizeConnector;
module.exports = {
init,
getAllChaosExperiments,
insertChaosExperiment,
getChaosExperimentById,
getChaosExperimentByName,
deleteChaosExperiment,
closeConnection
};

async function init() {
return databaseConnector.init();
}

function closeConnection() {
return databaseConnector.closeConnection();
}

async function insertChaosExperiment(experimentId, experiment, contextId) {
return databaseConnector.insertChaosExperiment(experimentId, experiment, contextId);
}

async function getAllChaosExperiments(from, limit, exclude, contextId) {
return databaseConnector.getAllChaosExperiments(from, limit, exclude, contextId);
}

async function getChaosExperimentById(experimentId, contextId) {
return databaseConnector.getChaosExperimentById(experimentId, contextId);
}

async function getChaosExperimentByName(name, contextId) {
return databaseConnector.getChaosExperimentByName(name, contextId);
}

async function deleteChaosExperiment(experimentId) {
return databaseConnector.deleteChaosExperiment(experimentId);
}
Loading