-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: StevenLeiZhang <zhangleiic@163.com>
- Loading branch information
1 parent
8338a1f
commit 28b99e1
Showing
11 changed files
with
640 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
apiVersion: core.oam.dev/v1beta1 | ||
kind: Application | ||
metadata: | ||
name: helloworld | ||
spec: | ||
components: | ||
- name: helloworld | ||
type: webservice | ||
properties: | ||
cpu: "0.5" | ||
exposeType: ClusterIP | ||
image: oamdev/hello-world | ||
memory: 1024Mi | ||
ports: | ||
- expose: true | ||
port: 80 | ||
protocol: TCP | ||
traits: | ||
- type: cronhpa | ||
properties: | ||
targetAPIVersion: apps/v1 | ||
targetKind: Deployment | ||
excludeDates: | ||
- '* * * 15 11 *' | ||
- '* * * * * 5' | ||
hpaJobs: | ||
- name: scale-down | ||
runOnce: false | ||
schedule: "30 */1 * * * *" | ||
targetSize: 1 | ||
- name: scale-up | ||
runOnce: false | ||
schedule: "0 */1 * * * *" | ||
targetSize: 3 | ||
policies: | ||
- name: apply-once | ||
type: apply-once | ||
properties: | ||
enable: true | ||
rules: | ||
- strategy: | ||
path: ["spec.replicas"] | ||
selector: | ||
resourceTypes: ["Deployment","StatefulSet"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# cronhpa | ||
|
||
This addon is built based [kubernetes-cronhpa-controller](https://github.com/AliyunContainerService/kubernetes-cronhpa-controller/) | ||
|
||
## install | ||
```shell | ||
vela addon enable cronhpa | ||
``` | ||
|
||
## usage | ||
|
||
This addon exposes one Trait "cronhpa", it provides cron horizontal pod autoscaler controller using crontab like scheme. | ||
|
||
### properties | ||
|
||
```shell | ||
|
||
# properties | ||
+------------------+---------------------------------------------------------------------------------------------+-----------------------+----------+------------+ | ||
| NAME | DESCRIPTION | TYPE | REQUIRED | DEFAULT | | ||
+------------------+---------------------------------------------------------------------------------------------+-----------------------+----------+------------+ | ||
| targetAPIVersion | Specify the apiVersion of scale target. | string | false | apps/v1 | | ||
| targetKind | Specify the kind of scale target. | string | false | Deployment | | ||
| excludeDates | Specify the job will skip the execution when the dates is matched. The minimum unit is day. | []string | false | | | ||
| hpaJobs | Specify multiple cron hpa jobs. | [[]hpaJobs](#hpajobs) | true | | | ||
+------------------+---------------------------------------------------------------------------------------------+-----------------------+----------+------------+ | ||
|
||
|
||
## hpaJobs | ||
+------------+------------------------------------------------------------------------------------------------------+--------+----------+---------+ | ||
| NAME | DESCRIPTION | TYPE | REQUIRED | DEFAULT | | ||
+------------+------------------------------------------------------------------------------------------------------+--------+----------+---------+ | ||
| name | Specify the name of hpa job, should be unique in one cronhpa spec. | string | true | | | ||
| schedule | Specify the cron schedule strategy. | string | true | | | ||
| targetSize | Specify the size you desired to scale when the scheduled time arrive. | int | true | | | ||
| runOnce | Specify if this job need executed repeatly, if runOnce is true then the job will only run and exit | bool | false | false | | ||
| | after the first execution. | | | | | ||
+------------+------------------------------------------------------------------------------------------------------+--------+----------+---------+ | ||
``` | ||
sample as below: | ||
```yaml | ||
|
||
apiVersion: core.oam.dev/v1beta1 | ||
kind: Application | ||
metadata: | ||
name: helloworld | ||
spec: | ||
components: | ||
- name: helloworld | ||
type: webservice | ||
properties: | ||
cpu: "0.5" | ||
exposeType: ClusterIP | ||
image: oamdev/hello-world | ||
memory: 1024Mi | ||
ports: | ||
- expose: true | ||
port: 80 | ||
protocol: TCP | ||
traits: | ||
- type: scaler | ||
properties: | ||
replicas: 1 | ||
- type: cronhpa | ||
properties: | ||
targetAPIVersion: apps/v1 | ||
targetKind: Deployment | ||
excludeDates: | ||
- '* * * 15 11 *' | ||
- '* * * * * 5' | ||
hpaJobs: | ||
- name: scale-down | ||
runOnce: false | ||
schedule: "30 */1 * * * *" | ||
targetSize: 1 | ||
- name: scale-up | ||
runOnce: false | ||
schedule: "0 */1 * * * *" | ||
targetSize: 3 | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
cronhpa: { | ||
type: "trait" | ||
alias: "cronhpa" | ||
annotations: {} | ||
attributes: { | ||
appliesToWorkloads: [ | ||
"deployments.apps", | ||
"statefulsets.apps", | ||
] | ||
conflictsWith: [] | ||
podDisruptive: false | ||
workloadRefPath: "" | ||
} | ||
description: "kubernetes cron horizontal pod autoscaler trait" | ||
labels: {} | ||
} | ||
|
||
template: { | ||
outputs: { | ||
cronhpa: { | ||
apiVersion: "autoscaling.alibabacloud.com/v1beta1" | ||
kind: "CronHorizontalPodAutoscaler" | ||
metadata: { | ||
labels: "controller-tools.k8s.io": "1.0" | ||
name: context.name | ||
} | ||
spec: { | ||
scaleTargetRef: { | ||
apiVersion: parameter.targetAPIVersion | ||
kind: parameter.targetKind | ||
name: context.name | ||
} | ||
if parameter.excludeDates != _|_ { | ||
excludeDates: [ | ||
for d in parameter.excludeDates { | ||
d | ||
}, | ||
] | ||
} | ||
jobs: [ | ||
for s in parameter.hpaJobs { | ||
name: s.name | ||
schedule: s.schedule | ||
targetSize: s.targetSize | ||
runOnce: s.runOnce | ||
}, | ||
] | ||
} | ||
} | ||
} | ||
parameter: { | ||
// +usage=Specify the apiVersion of scale target | ||
targetAPIVersion: *"apps/v1" | string | ||
// +usage=Specify the kind of scale target | ||
targetKind: *"Deployment" | string | ||
// +usage=Specify the job will skip the execution when the dates is matched. The minimum unit is day. | ||
excludeDates?: [...string] | ||
// +usage=Specify multiple cron hpa jobs | ||
hpaJobs: [...{ | ||
// +usage=Specify the name of hpa job, should be unique in one cronhpa spec | ||
name: string | ||
// +usage=Specify the cron schedule strategy | ||
schedule: string | ||
// +usage=Specify the size you desired to scale when the scheduled time arrive | ||
targetSize: int | ||
// +usage=Specify if this job need executed repeatly, if runOnce is true then the job will only run and exit after the first execution. | ||
runOnce: *false | bool | ||
}] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
description: An cron hpa addon for KubeVela. | ||
icon: "" | ||
invisible: false | ||
name: cronhpa | ||
tags: | ||
- Scaler | ||
- AutoScaler | ||
- Cron | ||
version: 1.4.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
parameter: { | ||
// +usage=Specify the image registry of cronhpa controller, eg. "registry.aliyuncs.com/acs" | ||
registry: *"registry.aliyuncs.com" | string | ||
// +usage=Specify the image repository of cronhpa controller, eg. "kubernetes-cronhpa-controller" | ||
repository: *"acs/kubernetes-cronhpa-controller" | string | ||
// +usage=Specify the image tag of cronhpa controller, eg. "v1.4.1" | ||
imageTag: *"v1.4.1-b8cd52c-aliyun" | string | ||
// +usage=Specify the names of imagePullSecret for private image registry, eg. "{a,b,c}" | ||
imagePullSecrets?: [...string] | ||
// +usage=Specify the imagePullPolicy of the image | ||
imagePullPolicy: *"Always" | string | ||
// +usage=Specify the replicas. | ||
replicas: *1 | int | ||
// +usage=Specify the namespace to install | ||
namespace: *"vela-system" | string | ||
// +usage=Specify the clusters to install | ||
clusters?: [...string] | ||
// +usage=Specifies the attributes of the resource required | ||
resources: { | ||
requests: { | ||
cpu: *1 | number | ||
memory: *"100Mi" | string | ||
} | ||
limits: { | ||
cpu: *1 | number | ||
memory: *"100Mi" | string | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
experimental/addons/cronhpa/resources/component/cronController.cue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package main | ||
|
||
cronController: { | ||
name: "cron-controller" | ||
type: "webservice" | ||
properties: { | ||
image: parameter.registry + "/" + parameter.repository + ":" + parameter.imageTag | ||
imagePullPolicy: parameter.imagePullPolicy | ||
if parameter.imagePullSecrets != _|_ { | ||
imagePullSecrets: [ for v in parameter.imagePullSecrets { | ||
v | ||
}, | ||
] | ||
} | ||
env: [ | ||
{ | ||
name: "TZ" | ||
value: '"Asia/Shanghai"' | ||
}, | ||
] | ||
} | ||
traits: [ | ||
{ | ||
type: "scaler" | ||
properties: { | ||
replicas: parameter.replicas | ||
} | ||
}, { | ||
type: "resource" | ||
properties: { | ||
requests: { | ||
cpu: parameter.resources.requests.cpu | ||
memory: parameter.resources.requests.memory | ||
} | ||
limits: { | ||
cpu: parameter.resources.limits.cpu | ||
memory: parameter.resources.limits.memory | ||
} | ||
} | ||
}, { | ||
type: "labels" | ||
properties: { | ||
"app": "kubernetes-cronhpa-controller" | ||
"controller-tools.k8s.io": '2.0' | ||
} | ||
}, { | ||
type: "service-account" | ||
properties: { | ||
create: true | ||
name: "kubernetes-cronhpa-controller" | ||
} | ||
}, | ||
] | ||
} |
Oops, something went wrong.