Skip to content

Commit 8e82633

Browse files
authored
Merge pull request #20 from ringtail/feature/update-v1.3.0-makefile
change makefile and add v1.3.0 demo
2 parents cdf7db8 + 2896e58 commit 8e82633

File tree

7 files changed

+150
-27
lines changed

7 files changed

+150
-27
lines changed

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
# build params
2+
PREFIX?=registry.aliyuncs.com/acs
3+
VERSION?=v1.3.0
4+
GIT_COMMIT:=$(shell git rev-parse --short HEAD)
15

26
# Image URL to use all building/pushing image targets
3-
IMG ?= kubernetes-cronhpa-controller:latest
4-
7+
IMG ?= $(PREFIX)/kubernetes-cronhpa-controller:$(VERSION)-$(GIT_COMMIT)-aliyun
58
all: test kubernetes-cronhpa-controller
69

710
# Run tests

README.md

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,14 @@ Metadata:
6565
Self Link: /apis/autoscaling.alibabacloud.com/v1beta1/namespaces/default/cronhorizontalpodautoscalers/cronhpa-sample
6666
UID: 05e41c95-5ea2-11e9-8ce6-00163e12e274
6767
Spec:
68+
Exclude Dates: <nil>
6869
Jobs:
6970
Name: scale-down
71+
Run Once: false
7072
Schedule: 30 */1 * * * *
7173
Target Size: 1
7274
Name: scale-up
75+
Run Once: false
7376
Schedule: 0 */1 * * * *
7477
Target Size: 3
7578
Scale Target Ref:
@@ -82,14 +85,21 @@ Status:
8285
Last Probe Time: 2019-04-14T10:43:02Z
8386
Message:
8487
Name: scale-down
88+
Run Once: false
8589
Schedule: 30 */1 * * * *
8690
State: Submitted
8791
Job Id: a7db95b6-396a-4753-91d5-23c2e73819ac
8892
Last Probe Time: 2019-04-14T10:43:02Z
8993
Message:
9094
Name: scale-up
95+
Run Once: false
9196
Schedule: 0 */1 * * * *
9297
State: Submitted
98+
Exclude Dates: <nil>
99+
Scale Target Ref:
100+
API Version: apps/v1beta2
101+
Kind: Deployment
102+
Name: nginx-deployment-basic
93103
Events: <none>
94104
```
95105

@@ -100,46 +110,58 @@ if the `State` of cronhpa job is `Succeed` that means the last execution is succ
100110
Name: cronhpa-sample
101111
Namespace: default
102112
Labels: controller-tools.k8s.io=1.0
103-
Annotations: kubectl.kubernetes.io/last-applied-configuration:
104-
{"apiVersion":"autoscaling.alibabacloud.com/v1beta1","kind":"CronHorizontalPodAutoscaler","metadata":{"annotations":{},"labels":{"controll...
113+
Annotations: <none>
105114
API Version: autoscaling.alibabacloud.com/v1beta1
106115
Kind: CronHorizontalPodAutoscaler
107116
Metadata:
108-
Creation Timestamp: 2019-04-15T06:41:44Z
117+
Creation Timestamp: 2019-11-01T12:49:57Z
109118
Generation: 1
110-
Resource Version: 15673230
119+
Resource Version: 47812775
111120
Self Link: /apis/autoscaling.alibabacloud.com/v1beta1/namespaces/default/cronhorizontalpodautoscalers/cronhpa-sample
112-
UID: 88ea51e0-5f49-11e9-bd0b-00163e30eb10
121+
UID: 1bbbab8a-fca6-11e9-bb47-00163e12ab74
113122
Spec:
123+
Exclude Dates: <nil>
114124
Jobs:
115125
Name: scale-down
126+
Run Once: false
116127
Schedule: 30 */1 * * * *
117-
Target Size: 1
128+
Target Size: 2
118129
Name: scale-up
130+
Run Once: false
119131
Schedule: 0 */1 * * * *
120132
Target Size: 3
121133
Scale Target Ref:
122134
API Version: apps/v1beta2
123135
Kind: Deployment
124-
Name: nginx-deployment-basic
136+
Name: nginx-deployment-basic2
125137
Status:
126138
Conditions:
127-
Job Id: 84818af0-3293-43e8-8ba6-6fd3ad2c35a4
128-
Last Probe Time: 2019-04-15T06:42:30Z
129-
Message: cron hpa job scale-down executed successfully
139+
Job Id: 157260b9-489c-4a12-ad5c-f544386f0243
140+
Last Probe Time: 2019-11-05T03:47:30Z
141+
Message: cron hpa job scale-down executed successfully. current replicas:3, desired replicas:2
130142
Name: scale-down
143+
Run Once: false
131144
Schedule: 30 */1 * * * *
132145
State: Succeed
133-
Job Id: f8579f11-b129-4e72-b35f-c0bdd32583b3
134-
Last Probe Time: 2019-04-15T06:42:20Z
135-
Message:
146+
Job Id: 5bab7b8c-158a-469c-a68c-a4657486e2a5
147+
Last Probe Time: 2019-11-05T03:48:00Z
148+
Message: cron hpa job scale-up executed successfully. current replicas:2, desired replicas:3
136149
Name: scale-up
150+
Run Once: false
137151
Schedule: 0 */1 * * * *
138-
State: Submitted
152+
State: Succeed
153+
Exclude Dates: <nil>
154+
Scale Target Ref:
155+
API Version: apps/v1beta2
156+
Kind: Deployment
157+
Name: nginx-deployment-basic
139158
Events:
140-
Type Reason Age From Message
141-
---- ------ ---- ---- -------
142-
Normal Succeed 5s cron-horizontal-pod-autoscaler cron hpa job scale-down executed successfully
159+
Type Reason Age From Message
160+
---- ------ ---- ---- -------
161+
Normal Succeed 42m (x5165 over 3d14h) cron-horizontal-pod-autoscaler cron hpa job scale-down executed successfully. current replicas:3, desired replicas:1
162+
Normal Succeed 30m cron-horizontal-pod-autoscaler cron hpa job scale-up executed successfully. current replicas:1, desired replicas:3
163+
Normal Succeed 17m (x13 over 29m) cron-horizontal-pod-autoscaler cron hpa job scale-up executed successfully. current replicas:2, desired replicas:3
164+
Normal Succeed 4m59s (x26 over 29m) cron-horizontal-pod-autoscaler cron hpa job scale-down executed successfully. current replicas:3, desired replicas:2
143165
```
144166
🍻Cheers! It works.
145167

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

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

204-
* targetSize
226+
* targetSize
205227
`TargetSize` is the size you desired to scale when the scheduled time arrive.
206-
228+
229+
* runOnce
230+
if `runOnce` is true then the job will only run and exit after the first execution.
231+
232+
* excludeDates
233+
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.
234+
```$xslt
235+
excludeDates:
236+
- "* * * 15 11 *"
237+
```
207238

208239
## Common Question
209240
* Cloud `kubernetes-cronhpa-controller` and HPA work together?

config/default/manager_image_patch.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ spec:
88
spec:
99
containers:
1010
# Change the value of image field below to your controller image URL
11-
- image: kubernetes-cronhpa-controller:latest
11+
- image: registry.aliyuncs.com/acs/kubernetes-cronhpa-controller:v1.3.0-f9010e90-aliyun
1212
name: manager

config/default/manager_image_patch.yaml-e

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ spec:
88
spec:
99
containers:
1010
# Change the value of image field below to your controller image URL
11-
- image: kubernetes-cronhpa-controller:latest
11+
- image: registry.aliyuncs.com/acs/kubernetes-cronhpa-controller:v1.3.0-7f57743a-aliyun
1212
name: manager

config/deploy/deploy.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@ metadata:
2222
namespace: kube-system
2323
labels:
2424
app: kubernetes-cronhpa-controller
25-
controller-tools.k8s.io: "1.0"
25+
controller-tools.k8s.io: "2.0"
2626
spec:
2727
selector:
2828
matchLabels:
2929
app: kubernetes-cronhpa-controller
30-
controller-tools.k8s.io: "1.0"
30+
controller-tools.k8s.io: "2.0"
3131
template:
3232
metadata:
3333
labels:
3434
app: kubernetes-cronhpa-controller
35-
controller-tools.k8s.io: "1.0"
35+
controller-tools.k8s.io: "2.0"
3636
spec:
3737
containers:
3838
- command:
3939
- /root/kubernetes-cronhpa-controller
40-
image: registry.cn-beijing.aliyuncs.com/acs/kubernetes-cronhpa-controller:v1.2.0
40+
image: registry.cn-beijing.aliyuncs.com/acs/kubernetes-cronhpa-controller:v1.3.0-f9010e90-aliyun
4141
imagePullPolicy: Always
4242
name: kubernetes-cronhpa-controller
4343
resources:
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
apiVersion: apps/v1beta2 # for versions before 1.8.0 use apps/v1beta1
3+
kind: Deployment
4+
metadata:
5+
name: nginx-deployment-basic
6+
labels:
7+
app: nginx
8+
spec:
9+
replicas: 2
10+
selector:
11+
matchLabels:
12+
app: nginx
13+
template:
14+
metadata:
15+
labels:
16+
app: nginx
17+
spec:
18+
containers:
19+
- name: nginx
20+
image: nginx:1.7.9 # replace it with your exactly <image_name:tags>
21+
ports:
22+
- containerPort: 80
23+
---
24+
apiVersion: autoscaling.alibabacloud.com/v1beta1
25+
kind: CronHorizontalPodAutoscaler
26+
metadata:
27+
labels:
28+
controller-tools.k8s.io: "1.0"
29+
name: cronhpa-sample
30+
spec:
31+
scaleTargetRef:
32+
apiVersion: apps/v1beta2
33+
kind: Deployment
34+
name: nginx-deployment-basic
35+
excludeDates:
36+
# exclude November 15th
37+
- "* * * 15 11 *"
38+
# exclude every Friday
39+
- "* * * * * 5"
40+
jobs:
41+
- name: "scale-down"
42+
schedule: "30 */1 * * * *"
43+
targetSize: 1
44+
- name: "scale-up"
45+
schedule: "0 */1 * * * *"
46+
targetSize: 3
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
apiVersion: apps/v1beta2 # for versions before 1.8.0 use apps/v1beta1
3+
kind: Deployment
4+
metadata:
5+
name: nginx-deployment-basic
6+
labels:
7+
app: nginx
8+
spec:
9+
replicas: 2
10+
selector:
11+
matchLabels:
12+
app: nginx
13+
template:
14+
metadata:
15+
labels:
16+
app: nginx
17+
spec:
18+
containers:
19+
- name: nginx
20+
image: nginx:1.7.9 # replace it with your exactly <image_name:tags>
21+
ports:
22+
- containerPort: 80
23+
---
24+
apiVersion: autoscaling.alibabacloud.com/v1beta1
25+
kind: CronHorizontalPodAutoscaler
26+
metadata:
27+
labels:
28+
controller-tools.k8s.io: "1.0"
29+
name: cronhpa-sample
30+
spec:
31+
scaleTargetRef:
32+
apiVersion: apps/v1beta2
33+
kind: Deployment
34+
name: nginx-deployment-basic
35+
jobs:
36+
- name: "scale-down"
37+
schedule: "30 */1 * * * *"
38+
targetSize: 1
39+
runOnce: true
40+
- name: "scale-up"
41+
schedule: "0 */1 * * * *"
42+
targetSize: 3
43+
runOnce: true

0 commit comments

Comments
 (0)