Skip to content

Commit

Permalink
feat: add database accessory (#3)
Browse files Browse the repository at this point in the history
<!-- Thank you for contributing to Catalog!

Note: 

1. With pull requests:

    - Open your pull request against "mainb
- Your pull request should have no more than three commits, if not you
should squash them.
- It should pass all tests in the available continuous integration
systems such as GitHub Actions.
    - You should add/modify tests to cover your proposed code changes.
- If your pull request contains a new feature, please document it on the
README.

2. Please create an issue first to describe the problem.

We recommend that link the issue with the PR in the following question.
For more info, check https://kusionstack.io/docs/governance/contribute/
-->

## What type of PR is this?

<!--
Add one of the following kinds:
/kind bug
/kind cleanup
/kind documentation
/kind feature
/kind chore
-->
/kind feature
## What this PR does / why we need it:
This PR adds support for database accessory which defines the relational
database service (rds) provided by a specified cloud vendor.
## Which issue(s) this PR fixes:

<!--
*Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
_If PR is about `failing-tests or flakes`, please post the related
issues/tests in a comment and do not use `Fixes`_*
-->

## Special notes for your reviewer:
The implementation of Database Generator can be found at [feat: add
database generator](KusionStack/kusion#435)

### Does this PR introduce a user-facing change?

<!--
If no, just write "NONE" in the release-note block below.
If yes, a release note is required:
Enter your extended release note in the block below. If the PR requires
additional action from users switching to the new release, include the
string "action required".

-->

```release-note

```

### Additional documentation e.g., design docs, usage docs, etc.:

<!--
Please use the following format for linking documentation:
- [Design]: <link>
- [Usage]: <link>
- [Other doc]: <link>
-->

```docs

```
  • Loading branch information
liu-hm19 authored Aug 29, 2023
1 parent 9d5e1bc commit 8808f96
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
93 changes: 93 additions & 0 deletions models/schema/v1/accessories/database.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
schema Database:
""" As an important supporting accessory, Database describes the attributes
to locally deploy or create a cloud provider managed database instance for
the workload.

Attributes
----------
type: str, default is Undefined, required.
Type defines the local deployment mode or the specific cloud vendor that
provides the relational database service (rds).
engine: str, default is Undefined, required.
Engine defines the database engine to use.
version: str, default is Undefined, required.
Version defines the database engine version to use.
instanceType: str, default is Undefined, optional.
InstanceType defines the type of the database which is required when
creating an rds instance provided by the cloud vendor.
size: int, default is 10, optional.
Size defines the allocated storage size of the rds instance provided by
the cloud vendor in GB.
category: str, default is "Basic", optional.
Category defines the edition of the rds instance provided by the cloud
vendor.
username: str, default is "root", optional.
Username defines the operation account for the database.
securityIPs: [str], default is ["0.0.0.0/0"], optional.
SecurityIPs defines the list of IP addresses allowed to access the rds
instance provided by the cloud vendor.
subnetID: str, default is Undefined, optional.
SubnetID defines the virtual subnet ID associated with the VPC that the rds
instance will be created in.
privateLink: bool, default is True, optional.
PrivateLink defines whether the host address of the rds instance for the workload
to connect with is via public network or private network of the cloud vendor.
extraMap: {str:str}, default is Undefined, optional.
ExtraMap defines the diversified rds configuration items from different
cloud vendors.

Examples
--------
Instantiate an aws rds with mysql 5.7.

import models.schema.v1.accessories.database as db

database: db.Database {
type: "aws"
engine: "mysql"
version: "5.7"
instanceType: "db.t3.micro"
}
"""

# The local deployment mode or the specific cloud vendor that provides the
# relational database service (rds).
type: str

# The database engine to use.
engine: str

# The database engine version to use.
version: str

# The type of the database which is required when creating an rds instance
# provided by the cloud vendor.
instanceType?: str

# The allocated storage size of the rds instance provided by the cloud vendor
# in GB.
size?: int = 10

# The edition of the rds instance provided by the cloud vendor.
category?: str = "Basic"

# The operation account for the database.
username?: str = "root"

# The list of IP addresses allowed to access the rds instance provided by the
# cloud vendor.
securityIPs?: [str] = ["0.0.0.0/0"]

# The virtual subnet ID associated with the VPC that the rds instance will be
# created in.
subnetID?: str

# Whether the host address of the rds instance for the workload to connect with
# is via public network or private network of the cloud vendor.
privateLink?: bool = True

# The diversified rds configuration items from different cloud vendors.
extraMap?: {str:str}

check:
instanceType if type != "local", "instanceType is required for cloud provider managed database"
4 changes: 4 additions & 0 deletions models/schema/v1/app_configuration.k
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import models.schema.v1.workload as wl
import models.schema.v1.trait as t
import models.schema.v1.accessories.database as db

schema AppConfiguration:
""" AppConfiguration is a developer-centric definition that describes how to run an Application.
Expand Down Expand Up @@ -39,6 +40,9 @@ schema AppConfiguration:
# OpsRule specifies collection of rules that will be checked for Day-2 operation.
opsRule?: t.OpsRule

# Database describes a locally deployed or a cloud provider managed database instance for the workload.
database?: db.Database

###### Other metadata info
# Labels and annotations can be used to attach arbitrary metadata as key-value pairs to resources.
labels?: {str:str}
Expand Down

0 comments on commit 8808f96

Please sign in to comment.