Skip to content

Commit 0bb0ade

Browse files
authored
Merge pull request #7 from RyanSiu1995/Handle-3.0.0-kubebuilder
Handle 3.0.0 kubebuilder
2 parents 273984c + b56e399 commit 0bb0ade

File tree

4 files changed

+133
-9
lines changed

4 files changed

+133
-9
lines changed

.github/workflows/main.yml

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,55 @@ on:
88

99
jobs:
1010
test-workflow:
11+
strategy:
12+
matrix:
13+
kubebuilder-version:
14+
- 2.3.1
15+
- 3.0.0
16+
kubebuilder-only:
17+
- true
18+
- false
19+
etcd-version:
20+
-
21+
- v3.4.15
22+
kubernetes-version:
23+
-
24+
- v1.19.10
1125
runs-on: ubuntu-latest
1226
steps:
1327
- name: Checkout
1428
uses: actions/checkout@v2
1529
- name: Test the workflow
1630
uses: ./
1731
with:
18-
version: 2.3.1
32+
version: ${{ matrix.kubebuilder-version }}
33+
kubebuilderOnly: ${{ matrix.kubebuilder-only }}
34+
etcdVersion: ${{ matrix.etcd-version }}
35+
kubernetesVersion: ${{ matrix.kubernetes-version }}
1936
- name: Check the existence of kubebuilder
37+
env:
38+
KUBEBUILDER_ONLY: ${{ matrix.kubebuilder-only }}
2039
run: |-
2140
cd /usr/local/kubebuilder/bin
22-
if [[ -f "./kubectl" ]] && [[ -f "./kube-apiserver" ]] && [[ -f "./etcd" ]] && [[ -f "./kubebuilder" ]]; then
41+
if [ -f "./kubebuilder" ] && [ "$KUBEBUILDER_ONLY" == "true" ]; then
42+
if [ ! -f "./kubectl" ] && [ ! -f "./kube-apiserver" ] && [ ! -f "./etcd" ]; then
43+
echo "Only kubebuilder have been installed!"
44+
echo "Checking if the binaries are executable"
45+
./kubebuilder version
46+
exit 0
47+
else
48+
echo "There are extra binaries installed"
49+
ls -la ./
50+
exit 1
51+
fi
52+
fi
53+
if [ -f "./kubectl" ] && [ -f "./kube-apiserver" ] && [ -f "./etcd" ] && [ -f "./kubebuilder" ]; then
2354
echo "All binaries from kubebuilder have been installed!"
55+
echo "Checking if the binaries are executable"
56+
./kubebuilder version
57+
./kubectl version --client true
58+
./kube-apiserver --version
59+
./etcd --version
2460
else
2561
echo "Cannot find the binaries from kubuilder!"
2662
ls -la ./

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,26 @@ This action provides a sugar syntax to install the kubebuilder in the ubuntu mac
88

99
**Required** The version going to be installed. Default `"2.3.1"`.
1010

11+
### `kubebuilderOnly`
12+
13+
**Optional** a flag to install kubebuilder binary only. Default as `false`, which is default behavor in 2.x.x.
14+
15+
### `etcdVersion`
16+
17+
**Optional** The etcd version going to be installed. Respected if kubebuilderOnly is `false`
18+
and major version of kubebuilder is greater than or equal to 3. Default `"v3.2.32"`
19+
20+
### `kubernetesVersion`
21+
22+
**Optional** The kubectl and kube-apiserver version going to be installed. Respected if kubebuilderOnly is `false`
23+
and major version of kubebuilder is greater than or equal to 3. Default to use latest version.
24+
1125
## Example usage
1226

1327
```yaml
14-
uses: RyanSiu1995/kubebuilder-action@v1.1
28+
uses: RyanSiu1995/kubebuilder-action@v1.2
1529
with:
16-
version: 2.3.1
30+
version: 3.0.0
1731
```
1832
1933
## License

action.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
name: 'Kubebuilder Installation'
22
description: 'Install the kubebuilder to the local environment'
33
inputs:
4-
version: # id of input
4+
version:
55
description: 'Version of kubebuilder being installed'
66
required: true
77
default: '2.3.1'
8+
kubebuilderOnly:
9+
description: 'A flag to make the behaviour between 2.x.x and 3.x.x to be the same'
10+
required: false
11+
default: false
12+
etcdVersion:
13+
description: 'Valid if kubebuilderOnly is false for 3.0.0+. The action will install etcd with this version'
14+
required: false
15+
kubernetesVersion:
16+
description: 'Valid if kubebuilderOnly is false for 3.0.0+. The action will install kubectl and kube-apiserver with this version'
17+
required: false
818
runs:
919
using: 'node12'
1020
main: 'index.js'

index.js

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,35 @@ const child_process = require('child_process');
88
const supportedCombination = ["darwin-amd64", "linux-amd64", "linux-arm64", "linux-ppc64le"];
99
const installedBinary = ["kubectl", "kube-apiserver", "kubebuilder", "etcd"];
1010

11+
function execSync(command) {
12+
child_process.execSync(command, {shell: '/bin/bash'});
13+
}
14+
1115
async function run() {
1216
try {
1317
const version = core.getInput('version');
18+
const kubebuilderOnly = core.getInput('kubebuilderOnly') === 'true';
19+
let etcdVersion = core.getInput('etcdVersion');
20+
let kubernetesVersion = core.getInput('kubernetesVersion');
21+
const majorVersion = version.split(".")[0];
22+
23+
if (kubebuilderOnly && etcdVersion) {
24+
core.warning("kubebuilderOnly is activated. etcdVersion will not be respected.");
25+
} else if (!kubebuilderOnly && etcdVersion && ! majorVersion > 2) {
26+
core.warning("Requested kubebuilder major version is less than 3. etcdVersion will not be respected.");
27+
} else if (!kubebuilderOnly && !!!etcdVersion) {
28+
core.info("No etcdVersion specified. Going to use the default one.");
29+
etcdVersion = 'v3.2.32';
30+
}
31+
32+
if (kubebuilderOnly && kubernetesVersion) {
33+
core.warning("kubebuilderOnly is activated. kubernetesVersion will not be respected.");
34+
} else if (!kubebuilderOnly && kubernetesVersion && ! majorVersion > 2) {
35+
core.warning("Requested kubebuilder major version is less than 3. kubernetesVersion will not be respected.");
36+
} else if (!kubebuilderOnly && !!!kubernetesVersion) {
37+
core.info("No kubernetesVersion specified. Going to use the latest one.");
38+
}
39+
1440
const osPlat = os.platform();
1541
var osArch = os.arch();
1642
if (osArch === "x64") {
@@ -23,9 +49,47 @@ async function run() {
2349
core.info(`Going to install kubebuilder ${version} for ${osPlat}-${osArch}`);
2450

2551
const downloadUrl = `https://go.kubebuilder.io/dl/${version}/${osPlat}/${osArch}`;
26-
child_process.execSync(`curl -L ${downloadUrl} | tar -xz -C /tmp/`, { shell: '/bin/bash'})
27-
child_process.execSync(`sudo mv /tmp/kubebuilder_${version}_${osPlat}_${osArch}/ /usr/local/kubebuilder/`, { shell: '/bin/bash'})
28-
child_process.execSync(`ls -la /usr/local/kubebuilder/bin`, { shell: '/bin/bash'})
52+
53+
if (majorVersion > 2) {
54+
core.debug(`MajorVersion is greater than 2`);
55+
execSync(`sudo mkdir -p /usr/local/kubebuilder/bin`);
56+
execSync(`sudo curl -L ${downloadUrl} -o /usr/local/kubebuilder/bin/kubebuilder`);
57+
execSync(`sudo chmod +x /usr/local/kubebuilder/bin/kubebuilder`);
58+
if (!kubebuilderOnly) {
59+
// Install kubectl and kube-apiserver
60+
["kubectl", "kube-apiserver"].map((binary) => {
61+
if (kubernetesVersion) {
62+
core.info(`Going to install ${binary} ${kubernetesVersion}`);
63+
execSync(`curl -LO "https://dl.k8s.io//release/${kubernetesVersion}/bin/${osPlat}/${osArch}/${binary}"`);
64+
} else {
65+
core.info(`Going to install ${binary} in latest version`);
66+
execSync(`curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/${osPlat}/${osArch}/${binary}"`);
67+
}
68+
execSync(`chmod +x ${binary}`);
69+
execSync(`sudo mv ${binary} /usr/local/kubebuilder/bin`);
70+
})
71+
// Install etcd
72+
core.info(`Going to install etcd ${etcdVersion}`);
73+
execSync(`curl -L https://github.com/etcd-io/etcd/releases/download/${etcdVersion}/etcd-${etcdVersion}-${osPlat}-${osArch}.tar.gz | tar -xz --strip-components=1 -C /tmp/`);
74+
execSync(`sudo mv /tmp/etcd /usr/local/kubebuilder/bin`);
75+
} else {
76+
core.debug(`No extra binary will be installed.`);
77+
}
78+
} else {
79+
execSync(`curl -L ${downloadUrl} | tar -xz -C /tmp/`);
80+
execSync(`sudo mv /tmp/kubebuilder_${version}_${osPlat}_${osArch}/ /usr/local/kubebuilder/`);
81+
execSync(`ls -la /usr/local/kubebuilder/bin`);
82+
if (kubebuilderOnly) {
83+
installedBinary
84+
.filter(x => x !== "kubebuilder")
85+
.map(x => {
86+
core.info(`Going to remove ${x}`);
87+
execSync(`sudo rm /usr/local/kubebuilder/bin/${x}`);
88+
});
89+
} else {
90+
core.debug(`No extra binary will be deleted.`);
91+
}
92+
}
2993

3094
const cachedPath = await tc.cacheDir('/usr/local/kubebuilder', 'kubebuilder', version);
3195
core.addPath(cachedPath);
@@ -34,4 +98,4 @@ async function run() {
3498
}
3599
}
36100

37-
run()
101+
run();

0 commit comments

Comments
 (0)