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 an example about the global-variables policy #95

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
57 changes: 57 additions & 0 deletions Variables/wordpress+mysql.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
apiVersion: v1
kind: Secret
metadata:
name: wordpress-config
type: Opaque
stringData:
DB_DATABASE: wordpress
DB_USER: wordpress
DB_PASSWORD: wordpress-password
DB_HOST: wordpress-db
DB_PORT: 3306
WORDPRESS_USER: admin
WORDPRESS_PASSWORD: admin-password
---
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: wordpress
spec:
policies:
- type: global-variables
properties:
discover:
secret:
name: wordpress-config
components:
- name: wordpress-db
type: helm
properties:
repoType: "helm"
url: https://charts.bitnami.com/bitnami
chart: mysql
version: 9.2.0
values:
auth:
username: context.variables.DB_USER
database: context.variables.DB_DATABASE
password: context.variables.DB_PASSWORD
- name: wordpress-server
type: helm
dependsOn: ["wordpress-db"]
properties:
repoType: "helm"
url: "https://charts.bitnami.com/bitnami"
chart: "wordpress"
version: "1.0.0"
values:
wordpressUsername: context.variables.WORDPRESS_USER
wordpressPassword: context.variables.WORDPRESS_PASSWORD
externalDatabase:
host: context.variables.DB_HOST
port: context.variables.DB_PORT
user: context.variables.DB_USER
password: context.variables.DB_PASSWORD
database: context.variables.DB_DATABASE
Copy link
Contributor

Choose a reason for hiding this comment

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

这个方案的核心问题是会把我们从 IaD 变成 IaC。 每个 value 都加入了 magic,需要计算一下,再render。

现在我们的 Application 是 IaD 的,每个数据都是固定的 data,不需要计算。 唯一需要计算的可能就是 output 里加入了一个 valueFrom

Copy link
Contributor Author

Choose a reason for hiding this comment

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

如果要保留之前的机制,那就是通过 valueFrom 来设置参数获取和赋值。但是感觉写起来有点多余。因为不得不为 每个字段先写一个默认值。


59 changes: 59 additions & 0 deletions Variables/wordpress+rds.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
apiVersion: v1
kind: Secret
metadata:
name: wordpress-config
type: Opaque
stringData:
DB_INSTANCE: wordpress
DB_DATABASE: wordpress
DB_USER: wordpress
DB_PASSWORD: wordpress-password
DB_PORT: 3306
WORDPRESS_USER: admin
WORDPRESS_PASSWORD: admin-password
---
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: wordpress
spec:
policies:
- type: global-variables
properties:
discover:
secret:
name: wordpress-config
components:
- name: wordpress-db
type: alibaba-rds
properties:
instanceName: context.variables.DB_INSTANCE
databaseName: context.variables.DB_DATABASE
accountName: context.variables.DB_USER
password: context.variables.DB_PASSWORD
outputs:
- name: wordpress-rds-address
# We should copy the outputs info from the Configure to the Application status
valueFrom: context.status.outputs.DB_HOST
- name: wordpress-server
type: helm
dependsOn: ["wordpress-db"]
inputs:
- from: wordpress-rds-address
parameterKey: properties.values.externalDatabase.host
properties:
repoType: "helm"
url: "https://charts.bitnami.com/bitnami"
chart: "wordpress"
version: "1.0.0"
values:
wordpressUsername: context.variables.WORDPRESS_USER
wordpressPassword: context.variables.WORDPRESS_PASSWORD
externalDatabase:
host: context.variables.DB_HOST
port: context.variables.DB_PORT
user: context.variables.DB_USER
password: context.variables.DB_PASSWORD
database: context.variables.DB_DATABASE