Skip to content

Commit

Permalink
refactor: update database accessory and related samples (#43)
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 refactors the database accessory model and updates related
samples.
## 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`_*
-->

Fixes #

## Special notes for your reviewer:

### 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 Jan 8, 2024
1 parent 4e59d58 commit e227e1f
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 117 deletions.
46 changes: 46 additions & 0 deletions models/samples/pgadmin/base/base.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import models.schema.v1 as ac
import models.schema.v1.workload as wl
import models.schema.v1.workload.container as c
import models.schema.v1.workload.network as n
import models.schema.v1.accessories.postgres
import models.schema.v1.workload.secret as sec

# base.k declares reusable configurations for all stacks.
pgadmin: ac.AppConfiguration {
workload: wl.Service {
containers: {
pgadmin: c.Container {
image: "dpage/pgadmin4:latest"
env: {
"PGADMIN_DEFAULT_EMAIL": "[email protected]"
"PGADMIN_DEFAULT_PASSWORD": "secret://pgadmin-secret/pgadmin-default-password"
"PGADMIN_PORT": "80"
}
resources = {
"cpu": "500m"
"memory": "512Mi"
}
}
}
secrets: {
"pgadmin-secret": sec.Secret {
type: "opaque"
data: {
"pgadmin-default-password": "*******"
}
}
}
replicas: 1
ports: [
n.Port {
port: 80
}
]
}
database: {
pgadmin: postgres.PostgreSQL {
type: "cloud"
version: "14.0"
}
}
}
6 changes: 6 additions & 0 deletions models/samples/pgadmin/prod/kcl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kcl_cli_configs:
file:
- ../base/base.k
- ./main.k
disable_none: false

10 changes: 10 additions & 0 deletions models/samples/pgadmin/prod/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import models.schema.v1 as ac

# main.k declares customized configurations for prod stack.

pgadmin: ac.AppConfiguration {
workload.containers.pgadmin: {
# prod stack has different image
image = "dpage/pgadmin4:8.0"
}
}
1 change: 1 addition & 0 deletions models/samples/pgadmin/prod/stack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name: prod
4 changes: 4 additions & 0 deletions models/samples/pgadmin/project.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: pgadmin
generator:
type: AppConfiguration

23 changes: 6 additions & 17 deletions models/samples/wordpress/base/base.k
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import models.schema.v1 as ac
import models.schema.v1.trait as t
import models.schema.v1.workload as wl
import models.schema.v1.workload.container as c
import models.schema.v1.workload.secret as sec
import models.schema.v1.workload.network as n
import models.schema.v1.monitoring as m
import models.schema.v1.accessories.database as db
import models.schema.v1.accessories.mysql

# base.k declares reusable configurations for all stacks.
wordpress: ac.AppConfiguration {
Expand All @@ -31,18 +28,10 @@ wordpress: ac.AppConfiguration {
}
]
}
# Declare dependent database resource
database: db.Database {
type: "alicloud"
engine: "MySQL"
version: "5.7"
size: 20
instanceType: "mysql.n2.serverless.1c"
category: "serverless_basic"

# SubnetID defines the virtual subnet ID associated with the VPC that the rds
# instance will be created in. The rds instance won't be created in user's own VPC
# if this field is not provided.
subnetID: "your_subnet_id"
database: {
wordpress: mysql.MySQL {
type: "cloud"
version: "8.0"
}
}
}
35 changes: 32 additions & 3 deletions models/samples/wordpress/prod/main.k
Original file line number Diff line number Diff line change
@@ -1,10 +1,39 @@
import models.schema.v1 as ac
import models.schema.v1.workload as wl
import models.schema.v1.workload.container as c
import models.schema.v1.workload.network as n
import models.schema.v1.accessories.mysql

# main.k declares customized configurations for prod stack.

wordpress: ac.AppConfiguration {
workload.containers.wordpress: {
# prod stack has different image
image = "wordpress:4.8-apache"
workload: wl.Service {
containers: {
wordpress: c.Container {
image = "wordpress:6.3"
env = {
"WORDPRESS_DB_HOST": "$(KUSION_DB_HOST_WORDPRESS)"
"WORDPRESS_DB_USER": "$(KUSION_DB_USERNAME_WORDPRESS)"
"WORDPRESS_DB_PASSWORD": "$(KUSION_DB_PASSWORD_WORDPRESS)"
"WORDPRESS_DB_NAME": "mysql"
}
resources = {
"cpu": "500m"
"memory": "512Mi"
}
}
}
replicas = 1
ports = [
n.Port {
port: 80
}
]
}
database = {
wordpress: mysql.MySQL {
type: "cloud"
version: "8.0"
}
}
}
94 changes: 0 additions & 94 deletions models/schema/v1/accessories/database.k

This file was deleted.

30 changes: 30 additions & 0 deletions models/schema/v1/accessories/mysql.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
schema MySQL:
""" MySQL describes the attributes to locally deploy or create a cloud provider
managed mysql database instance for the workload.

Attributes
----------
type: "local" | "cloud", defaults to Undefined, required.
Type defines whether the mysql database is deployed locally or provided by
cloud vendor.
version: str, defaults to Undefined, required.
Version defines the mysql version to use.

Examples
--------
Instantiate a local mysql database with version of 5.7.

import models.schema.v1.accessories.mysql

mysql: mysql.MySQL {
type: "local"
version: "5.7"
}
"""

# The deployment mode of the mysql database.
type: "local" | "cloud"

# The mysql database version to use.
version: str

30 changes: 30 additions & 0 deletions models/schema/v1/accessories/postgres.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
schema PostgreSQL:
""" PostgreSQL describes the attributes to locally deploy or create a cloud provider
managed postgresql database instance for the workload.

Attributes
----------
type: "local" | "cloud", defaults to Undefined, required.
Type defines whether the postgresql database is deployed locally or provided by
cloud vendor.
version: str, defaults to Undefined, required.
Version defines the mysql version to use.

Examples
--------
Instantiate a local postgresql database with image version of 14.0.

import models.schema.v1.accessories.postgres

postgres: postgres.PostgreSQL {
type: "local"
version: "14.0"
}
"""

# The deployment mode of the postgresql database.
type: "local" | "cloud"

# The postgresql database version to use.
version: str

10 changes: 7 additions & 3 deletions models/schema/v1/app_configuration.k
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import models.schema.v1.workload as wl
import models.schema.v1.trait as t
import models.schema.v1.accessories.database as db
import models.schema.v1.monitoring as m
import models.schema.v1.accessories.mysql
import models.schema.v1.accessories.postgres

schema AppConfiguration:
""" AppConfiguration is a developer-centric definition that describes how to run an Application.
Expand All @@ -15,6 +16,9 @@ schema AppConfiguration:
includes Service and Job.
monitoring: m.Prometheus, default is Undefined, optional.
Monitoring specifies how to scrape Prometheus metrics for the workload.
database: {str:mysql.MySQL | postgres.PostgreSQL}, defualt is Undefined, optional.
Database describes a locally deployed or a cloud provider managed database instance
for the workload. Currently supported database profile includes MySQL and PostgreSQL.
opsRule: t.OpsRule, default is Undefined, optional.
OpsRule specifies collection of rules that will be checked for Day-2 operation.
database: db.Database, default is Undefined, optional.
Expand Down Expand Up @@ -52,8 +56,8 @@ 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
# Database describes a locally deployed or a cloud provider managed database instance for the workload.
database?: {str: mysql.MySQL | postgres.PostgreSQL}

###### Other metadata info
# Labels and annotations can be used to attach arbitrary metadata as key-value pairs to resources.
Expand Down

0 comments on commit e227e1f

Please sign in to comment.