Skip to content

Commit

Permalink
Merge pull request #20 from ringtail/feature/update-v1.3.0-makefile
Browse files Browse the repository at this point in the history
change makefile and add v1.3.0 demo
  • Loading branch information
ringtail authored Nov 5, 2019
2 parents cdf7db8 + 2896e58 commit 8e82633
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 27 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# build params
PREFIX?=registry.aliyuncs.com/acs
VERSION?=v1.3.0
GIT_COMMIT:=$(shell git rev-parse --short HEAD)

# Image URL to use all building/pushing image targets
IMG ?= kubernetes-cronhpa-controller:latest

IMG ?= $(PREFIX)/kubernetes-cronhpa-controller:$(VERSION)-$(GIT_COMMIT)-aliyun
all: test kubernetes-cronhpa-controller

# Run tests
Expand Down
69 changes: 50 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,14 @@ Metadata:
Self Link: /apis/autoscaling.alibabacloud.com/v1beta1/namespaces/default/cronhorizontalpodautoscalers/cronhpa-sample
UID: 05e41c95-5ea2-11e9-8ce6-00163e12e274
Spec:
Exclude Dates: <nil>
Jobs:
Name: scale-down
Run Once: false
Schedule: 30 */1 * * * *
Target Size: 1
Name: scale-up
Run Once: false
Schedule: 0 */1 * * * *
Target Size: 3
Scale Target Ref:
Expand All @@ -82,14 +85,21 @@ Status:
Last Probe Time: 2019-04-14T10:43:02Z
Message:
Name: scale-down
Run Once: false
Schedule: 30 */1 * * * *
State: Submitted
Job Id: a7db95b6-396a-4753-91d5-23c2e73819ac
Last Probe Time: 2019-04-14T10:43:02Z
Message:
Name: scale-up
Run Once: false
Schedule: 0 */1 * * * *
State: Submitted
Exclude Dates: <nil>
Scale Target Ref:
API Version: apps/v1beta2
Kind: Deployment
Name: nginx-deployment-basic
Events: <none>
```

Expand All @@ -100,46 +110,58 @@ if the `State` of cronhpa job is `Succeed` that means the last execution is succ
Name: cronhpa-sample
Namespace: default
Labels: controller-tools.k8s.io=1.0
Annotations: kubectl.kubernetes.io/last-applied-configuration:
{"apiVersion":"autoscaling.alibabacloud.com/v1beta1","kind":"CronHorizontalPodAutoscaler","metadata":{"annotations":{},"labels":{"controll...
Annotations: <none>
API Version: autoscaling.alibabacloud.com/v1beta1
Kind: CronHorizontalPodAutoscaler
Metadata:
Creation Timestamp: 2019-04-15T06:41:44Z
Creation Timestamp: 2019-11-01T12:49:57Z
Generation: 1
Resource Version: 15673230
Resource Version: 47812775
Self Link: /apis/autoscaling.alibabacloud.com/v1beta1/namespaces/default/cronhorizontalpodautoscalers/cronhpa-sample
UID: 88ea51e0-5f49-11e9-bd0b-00163e30eb10
UID: 1bbbab8a-fca6-11e9-bb47-00163e12ab74
Spec:
Exclude Dates: <nil>
Jobs:
Name: scale-down
Run Once: false
Schedule: 30 */1 * * * *
Target Size: 1
Target Size: 2
Name: scale-up
Run Once: false
Schedule: 0 */1 * * * *
Target Size: 3
Scale Target Ref:
API Version: apps/v1beta2
Kind: Deployment
Name: nginx-deployment-basic
Name: nginx-deployment-basic2
Status:
Conditions:
Job Id: 84818af0-3293-43e8-8ba6-6fd3ad2c35a4
Last Probe Time: 2019-04-15T06:42:30Z
Message: cron hpa job scale-down executed successfully
Job Id: 157260b9-489c-4a12-ad5c-f544386f0243
Last Probe Time: 2019-11-05T03:47:30Z
Message: cron hpa job scale-down executed successfully. current replicas:3, desired replicas:2
Name: scale-down
Run Once: false
Schedule: 30 */1 * * * *
State: Succeed
Job Id: f8579f11-b129-4e72-b35f-c0bdd32583b3
Last Probe Time: 2019-04-15T06:42:20Z
Message:
Job Id: 5bab7b8c-158a-469c-a68c-a4657486e2a5
Last Probe Time: 2019-11-05T03:48:00Z
Message: cron hpa job scale-up executed successfully. current replicas:2, desired replicas:3
Name: scale-up
Run Once: false
Schedule: 0 */1 * * * *
State: Submitted
State: Succeed
Exclude Dates: <nil>
Scale Target Ref:
API Version: apps/v1beta2
Kind: Deployment
Name: nginx-deployment-basic
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Succeed 5s cron-horizontal-pod-autoscaler cron hpa job scale-down executed successfully
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Succeed 42m (x5165 over 3d14h) cron-horizontal-pod-autoscaler cron hpa job scale-down executed successfully. current replicas:3, desired replicas:1
Normal Succeed 30m cron-horizontal-pod-autoscaler cron hpa job scale-up executed successfully. current replicas:1, desired replicas:3
Normal Succeed 17m (x13 over 29m) cron-horizontal-pod-autoscaler cron hpa job scale-up executed successfully. current replicas:2, desired replicas:3
Normal Succeed 4m59s (x26 over 29m) cron-horizontal-pod-autoscaler cron hpa job scale-down executed successfully. current replicas:3, desired replicas:2
```
🍻Cheers! It works.

Expand Down Expand Up @@ -201,9 +223,18 @@ The cronhpa job spec need three fields:

more schedule scheme please check this <a target="_blank" href="https://godoc.org/github.com/robfig/cron">doc</a>.

* targetSize
* targetSize
`TargetSize` is the size you desired to scale when the scheduled time arrive.


* runOnce
if `runOnce` is true then the job will only run and exit after the first execution.

* excludeDates
excludeDates is a dates array. The job will skip the execution when the dates is matched. The minimum unit is day. If you want to skip the date(November 15th), You can specific the excludeDates like below.
```$xslt
excludeDates:
- "* * * 15 11 *"
```

## Common Question
* Cloud `kubernetes-cronhpa-controller` and HPA work together?
Expand Down
2 changes: 1 addition & 1 deletion config/default/manager_image_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ spec:
spec:
containers:
# Change the value of image field below to your controller image URL
- image: kubernetes-cronhpa-controller:latest
- image: registry.aliyuncs.com/acs/kubernetes-cronhpa-controller:v1.3.0-f9010e90-aliyun
name: manager
2 changes: 1 addition & 1 deletion config/default/manager_image_patch.yaml-e
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ spec:
spec:
containers:
# Change the value of image field below to your controller image URL
- image: kubernetes-cronhpa-controller:latest
- image: registry.aliyuncs.com/acs/kubernetes-cronhpa-controller:v1.3.0-7f57743a-aliyun
name: manager
8 changes: 4 additions & 4 deletions config/deploy/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ metadata:
namespace: kube-system
labels:
app: kubernetes-cronhpa-controller
controller-tools.k8s.io: "1.0"
controller-tools.k8s.io: "2.0"
spec:
selector:
matchLabels:
app: kubernetes-cronhpa-controller
controller-tools.k8s.io: "1.0"
controller-tools.k8s.io: "2.0"
template:
metadata:
labels:
app: kubernetes-cronhpa-controller
controller-tools.k8s.io: "1.0"
controller-tools.k8s.io: "2.0"
spec:
containers:
- command:
- /root/kubernetes-cronhpa-controller
image: registry.cn-beijing.aliyuncs.com/acs/kubernetes-cronhpa-controller:v1.2.0
image: registry.cn-beijing.aliyuncs.com/acs/kubernetes-cronhpa-controller:v1.3.0-f9010e90-aliyun
imagePullPolicy: Always
name: kubernetes-cronhpa-controller
resources:
Expand Down
46 changes: 46 additions & 0 deletions examples/deploymenet_cronhpa_excludeDates.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
apiVersion: apps/v1beta2 # for versions before 1.8.0 use apps/v1beta1
kind: Deployment
metadata:
name: nginx-deployment-basic
labels:
app: nginx
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.9 # replace it with your exactly <image_name:tags>
ports:
- containerPort: 80
---
apiVersion: autoscaling.alibabacloud.com/v1beta1
kind: CronHorizontalPodAutoscaler
metadata:
labels:
controller-tools.k8s.io: "1.0"
name: cronhpa-sample
spec:
scaleTargetRef:
apiVersion: apps/v1beta2
kind: Deployment
name: nginx-deployment-basic
excludeDates:
# exclude November 15th
- "* * * 15 11 *"
# exclude every Friday
- "* * * * * 5"
jobs:
- name: "scale-down"
schedule: "30 */1 * * * *"
targetSize: 1
- name: "scale-up"
schedule: "0 */1 * * * *"
targetSize: 3
43 changes: 43 additions & 0 deletions examples/deployment_cronhpa_runonce.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
apiVersion: apps/v1beta2 # for versions before 1.8.0 use apps/v1beta1
kind: Deployment
metadata:
name: nginx-deployment-basic
labels:
app: nginx
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.9 # replace it with your exactly <image_name:tags>
ports:
- containerPort: 80
---
apiVersion: autoscaling.alibabacloud.com/v1beta1
kind: CronHorizontalPodAutoscaler
metadata:
labels:
controller-tools.k8s.io: "1.0"
name: cronhpa-sample
spec:
scaleTargetRef:
apiVersion: apps/v1beta2
kind: Deployment
name: nginx-deployment-basic
jobs:
- name: "scale-down"
schedule: "30 */1 * * * *"
targetSize: 1
runOnce: true
- name: "scale-up"
schedule: "0 */1 * * * *"
targetSize: 3
runOnce: true

0 comments on commit 8e82633

Please sign in to comment.