Skip to content

Commit 9b76197

Browse files
authored
Allow setting deployment strategy (#43)
* Allow 'restarting' (recreating) in addition to rollout * Fix tests, allowing a configurable strategy
1 parent 9d5a4cd commit 9b76197

File tree

7 files changed

+30
-20
lines changed

7 files changed

+30
-20
lines changed

action.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ inputs:
99
description: "The tag used for re-deploy"
1010
required: false
1111
default: "develop"
12+
strategy:
13+
description: "The strategy to use for this deployment"
14+
required: false
15+
default: "rollout"
16+
type: choice
17+
options:
18+
- rollout
19+
- restart
1220
url:
1321
description: "The re-deployment service URL"
1422
required: true

autodeploy.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ class AutoDeployApi {
2323
});
2424
}
2525

26-
redeployUrl(type, targets) {
26+
redeployUrl(type, strategy, targets) {
2727
const encodedTargets = targets
2828
.split(",")
2929
.map((target) => encodeURIComponent(target.trim()))
3030
.join(",");
31-
return `${this.url}/${type}/${encodedTargets}/rollout`;
31+
return `${this.url}/${type}/${encodedTargets}/${strategy}`;
3232
}
3333

34-
async redeploy(type, targets, tag) {
34+
async redeploy(type, strategy, targets, tag) {
3535
const response = await this.client.postJson(
36-
this.redeployUrl(type, targets),
36+
this.redeployUrl(type, strategy, targets),
3737
{ push_data: { tag } }
3838
);
3939

dist/index.js

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@ async function run() {
66
try {
77
const pods = core.getInput("pods");
88
const images = core.getInput("images");
9+
const strategy = core.getInput("strategy")
910
const tag = core.getInput("tag") || "develop";
1011
const url = core.getInput("url", { required: true });
1112
const token = core.getInput("token", { required: true });
1213
const timeout = parseInt(core.getInput("timeout") || 60000);
1314

14-
core.info(`Re-deploying pods ${pods} for tag ${tag}`);
15+
core.info(`Re-deploying pods ${pods} for tag ${tag} with a ${strategy} strategy`);
1516
const api = new AutoDeployApi(url, token, timeout);
1617

1718
if (pods) {
18-
status = await api.redeploy("services", pods, tag);
19+
status = await api.redeploy("services", strategy, pods, tag);
1920
}
2021
if (images) {
21-
status = await api.redeploy("images", images, tag);
22+
status = await api.redeploy("images", strategy, images, tag);
2223
}
2324
if(!pods && !images) {
2425
throw new Error("Specify either the pods or container image for which you want to trigger a redeploy.");

index.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ test("parses authorization token", () => {
1313

1414
test("computes correct redeploy URL", () => {
1515
const api = new AutoDeployApi("https://foo.bar/", "u:p");
16-
expect(api.redeployUrl("services", "foo, bar baz")).toBe(
16+
expect(api.redeployUrl("services", "rollout", "foo, bar baz")).toBe(
1717
"https://foo.bar/services/foo,bar%20baz/rollout",
1818
);
1919
});
2020

2121
test("properly escapes image names", () => {
2222
const api = new AutoDeployApi("https://foo.bar/", "u:p");
23-
expect(api.redeployUrl("image", "foo/bar/baz:baw")).toBe(
23+
expect(api.redeployUrl("image", "rollout", "foo/bar/baz:baw")).toBe(
2424
"https://foo.bar/image/foo%2Fbar%2Fbaz%3Abaw/rollout",
2525
);
2626
});
@@ -33,13 +33,13 @@ function dummyApi(url) {
3333

3434
test("returns successfully on 2xx status codes", async () => {
3535
const api = dummyApi("https://httpbin.org/post");
36-
const status = await api.redeploy("foo", "bar");
36+
const status = await api.redeploy("foo", "rollout", "bar");
3737
expect(status).toBe(200);
3838
});
3939

4040
test("throws on error codes", async () => {
4141
const api = dummyApi("https://httpbin.org/status/404");
42-
await expect(api.redeploy("foo", "bar")).rejects.toThrow(
42+
await expect(api.redeploy("foo", "rollout", "bar")).rejects.toThrow(
4343
"HTTP error 404",
4444
);
4545
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "autodeploy-action",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "An action to automatically trigger a re-deployment of Kubernetes pods",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)